001/* 002 * jDTAUS Banking API 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.banking.dtaus; 022 023import java.util.Locale; 024import org.jdtaus.core.container.ContainerFactory; 025import org.jdtaus.core.text.Message; 026 027/** 028 * Gets thrown by methods prepared to handle invalid files. 029 * 030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 031 * @version $JDTAUS: PhysicalFileException.java 8865 2014-01-10 17:13:42Z schulte $ 032 */ 033public class PhysicalFileException extends Exception 034{ 035 036 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 037 private static final long serialVersionUID = -8624765386920924529L; 038 039 /** Empty {@code Message} array. */ 040 private static final Message[] NO_MESSAGES = 041 { 042 }; 043 044 /** 045 * Messages describing the exception. 046 * @serial 047 */ 048 private final Message[] messages; 049 050 /** 051 * Creates a new {@code PhysicalFileException} instance taking an array of messages describing the exception. 052 * 053 * @param messages array of messages describing the exception or {@code null} if no information is available. 054 */ 055 public PhysicalFileException( final Message[] messages ) 056 { 057 super(); 058 this.messages = messages == null ? NO_MESSAGES : messages; 059 } 060 061 /** 062 * Getter for property {@code messages}. 063 * 064 * @return Messages describing the exception or an empty array if no information is available. 065 */ 066 public final Message[] getMessages() 067 { 068 final Message[] copy = new Message[ this.messages.length ]; 069 070 for ( int i = 0, l0 = this.messages.length; i < l0; i++ ) 071 { 072 copy[i] = this.messages[i]; 073 } 074 075 return copy; 076 } 077 078 /** 079 * Returns the message of the exception. 080 * 081 * @return The message of the exception. 082 */ 083 public String getMessage() 084 { 085 return this.getPhysicalFileExceptionMessage( this.getLocale() ); 086 } 087 088 /** 089 * Returns a string representation of the object. 090 * 091 * @return A string representation of the object. 092 */ 093 public String toString() 094 { 095 return super.toString() + this.internalString(); 096 } 097 098 /** 099 * Creates a string representing the properties of the instance. 100 * 101 * @return A string representing the properties of the instance. 102 */ 103 private String internalString() 104 { 105 final StringBuffer buf = new StringBuffer( 200 ).append( '{' ); 106 final Message[] msgs = this.getMessages(); 107 for ( int i = 0; i < msgs.length; i++ ) 108 { 109 buf.append( "[" ).append( i ).append( "]=" ).append( msgs[i].getText( Locale.getDefault() ) ); 110 if ( i + 1 < msgs.length ) 111 { 112 buf.append( ", " ); 113 } 114 } 115 116 return buf.append( '}' ).toString(); 117 } 118 119 //--Dependencies------------------------------------------------------------ 120 121// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies 122 // This section is managed by jdtaus-container-mojo. 123 124 /** 125 * Gets the configured <code>Locale</code> implementation. 126 * 127 * @return The configured <code>Locale</code> implementation. 128 */ 129 private Locale getLocale() 130 { 131 return (Locale) ContainerFactory.getContainer(). 132 getDependency( this, "Locale" ); 133 134 } 135 136// </editor-fold>//GEN-END:jdtausDependencies 137 138 //------------------------------------------------------------Dependencies-- 139 //--Messages---------------------------------------------------------------- 140 141// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages 142 // This section is managed by jdtaus-container-mojo. 143 144 /** 145 * Gets the text of message <code>physicalFileException</code>. 146 * <blockquote><pre>Datei-Fehler.</pre></blockquote> 147 * <blockquote><pre>File error.</pre></blockquote> 148 * 149 * @param locale The locale of the message instance to return. 150 * 151 * @return the text of message <code>physicalFileException</code>. 152 */ 153 private String getPhysicalFileExceptionMessage( final Locale locale ) 154 { 155 return ContainerFactory.getContainer(). 156 getMessage( this, "physicalFileException", locale, null ); 157 158 } 159 160// </editor-fold>//GEN-END:jdtausMessages 161 162 //----------------------------------------------------------------Messages-- 163}