View Javadoc
1   /*
2    *  jDTAUS Banking API
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.banking.dtaus;
22  
23  import java.util.Locale;
24  import org.jdtaus.core.container.ContainerFactory;
25  import org.jdtaus.core.text.Message;
26  
27  /**
28   * Gets thrown by methods prepared to handle invalid files.
29   *
30   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31   * @version $JDTAUS: PhysicalFileException.java 8865 2014-01-10 17:13:42Z schulte $
32   */
33  public class PhysicalFileException extends Exception
34  {
35  
36      /** Serial version UID for backwards compatibility with 1.0.x classes. */
37      private static final long serialVersionUID = -8624765386920924529L;
38  
39      /** Empty {@code Message} array. */
40      private static final Message[] NO_MESSAGES =
41      {
42      };
43  
44      /**
45       * Messages describing the exception.
46       * @serial
47       */
48      private final Message[] messages;
49  
50      /**
51       * Creates a new {@code PhysicalFileException} instance taking an array of messages describing the exception.
52       *
53       * @param messages array of messages describing the exception or {@code null} if no information is available.
54       */
55      public PhysicalFileException( final Message[] messages )
56      {
57          super();
58          this.messages = messages == null ? NO_MESSAGES : messages;
59      }
60  
61      /**
62       * Getter for property {@code messages}.
63       *
64       * @return Messages describing the exception or an empty array if no information is available.
65       */
66      public final Message[] getMessages()
67      {
68          final Message[] copy = new Message[ this.messages.length ];
69  
70          for ( int i = 0, l0 = this.messages.length; i < l0; i++ )
71          {
72              copy[i] = this.messages[i];
73          }
74  
75          return copy;
76      }
77  
78      /**
79       * Returns the message of the exception.
80       *
81       * @return The message of the exception.
82       */
83      public String getMessage()
84      {
85          return this.getPhysicalFileExceptionMessage( this.getLocale() );
86      }
87  
88      /**
89       * Returns a string representation of the object.
90       *
91       * @return A string representation of the object.
92       */
93      public String toString()
94      {
95          return super.toString() + this.internalString();
96      }
97  
98      /**
99       * 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 }