View Javadoc

1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    *   jDTAUS ⁑ ISO-13616
5    *   Copyright (C) Christian Schulte, 2013-222
6    *
7    *   Permission to use, copy, modify, and/or distribute this software for any
8    *   purpose with or without fee is hereby granted, provided that the above
9    *   copyright notice and this permission notice appear in all copies.
10   *
11   *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12   *   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13   *   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14   *   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15   *   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16   *   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17   *   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18   *
19   *   $JDTAUS: IbanCheckDigitsException.java 8843 2013-11-28 10:47:34Z schulte $
20   *
21   */
22  // </editor-fold>
23  // SECTION-END
24  package org.jdtaus.iso13616;
25  
26  import java.util.Locale;
27  
28  // SECTION-START[Documentation]
29  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
30  /**
31   * Gets thrown whenever validation of the check digits of an international bank account number fails.
32   *
33   * <dl>
34   *   <dt><b>Identifier:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Check Digits Exception</dd>
35   *   <dt><b>Name:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Check Digits Exception</dd>
36   *   <dt><b>Abstract:</b></dt><dd>No</dd>
37   *   <dt><b>Final:</b></dt><dd>Yes</dd>
38   *   <dt><b>Stateless:</b></dt><dd>No</dd>
39   * </dl>
40   *
41   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
42   * @version 1.1
43   */
44  // </editor-fold>
45  // SECTION-END
46  // SECTION-START[Annotations]
47  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
48  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
49  // </editor-fold>
50  // SECTION-END
51  public class IbanCheckDigitsException extends Exception
52  {
53      // SECTION-START[IbanCheckDigitsException]
54  
55      /** Serial version UID for backwards compatibility with 2007.45.x classes. */
56      private static final long serialVersionUID = 2758511596781778791L;
57  
58      /**
59       * The IBAN failing check digits validation.
60       * @serial
61       */
62      private String iban;
63  
64      /**
65       * The invalid check digits.
66       * @serial
67       */
68      private Number checkDigits;
69  
70      /**
71       * Creates a new {@code IbanCheckDigitsException} instance taking the IBAN failing check digits validation and the
72       * invalid check digits.
73       *
74       * @param iban The IBAN failing check digits validation.
75       * @param checkDigits The invalid check digits.
76       */
77      public IbanCheckDigitsException( final String iban, final Number checkDigits )
78      {
79          super();
80          this.iban = iban;
81          this.checkDigits = checkDigits;
82      }
83  
84      /**
85       * Gets a message describing the exception.
86       *
87       * @return A message describing the exception.
88       */
89      @Override
90      public String getMessage()
91      {
92          return getIbanCheckDigitsExceptionMessage( Locale.getDefault(), this.getIban(), this.getCheckDigits() );
93      }
94  
95      /**
96       * Gets a localized message describing the exception for a given locale.
97       *
98       * @param locale The locale of the localized message to get.
99       *
100      * @return A localized message describing the exception.
101      *
102      * @throws NullPointerException if {@code locale} is {@code null}.
103      */
104     public String getLocalizedMessage( final Locale locale )
105     {
106         if ( locale == null )
107         {
108             throw new NullPointerException( "locale" );
109         }
110 
111         return getIbanCheckDigitsExceptionMessage( locale, this.getIban(), this.getCheckDigits() );
112     }
113 
114     /**
115      * Gets the IBAN failing check digits validation.
116      *
117      * @return The IBAN failing check digits validation.
118      */
119     public String getIban()
120     {
121         return this.iban;
122     }
123 
124     /**
125      * Gets the invalid check digits.
126      *
127      * @return The invalid check digits.
128      */
129     public Number getCheckDigits()
130     {
131         return this.checkDigits;
132     }
133 
134     // SECTION-END
135     // SECTION-START[Dependencies]
136     // SECTION-END
137     // SECTION-START[Properties]
138     // SECTION-END
139     // SECTION-START[Messages]
140     // <editor-fold defaultstate="collapsed" desc=" Generated Messages ">
141     /**
142      * Gets the text of the {@code <IBAN Check Digits Exception Message>} message.
143      * <p><dl>
144      *   <dt><b>Languages:</b></dt>
145      *     <dd>English (default)</dd>
146      *     <dd>Deutsch</dd>
147      *   <dt><b>Final:</b></dt><dd>No</dd>
148      * </dl></p>
149      * @param locale The locale of the message to return.
150      * @param iban Format argument.
151      * @param illegalCheckDigits Format argument.
152      * @return The text of the {@code <IBAN Check Digits Exception Message>} message for {@code locale}.
153      */
154     @SuppressWarnings("unused")
155     @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
156     private static String getIbanCheckDigitsExceptionMessage( final java.util.Locale locale, final java.lang.String iban, final java.lang.Number illegalCheckDigits )
157     {
158         java.io.BufferedReader reader = null;
159 
160         try
161         {
162             final String message = java.text.MessageFormat.format( java.util.ResourceBundle.getBundle( "org.jdtaus.iso13616.IbanCheckDigitsException", locale ).getString( "IBAN Check Digits Exception Message" ), iban, illegalCheckDigits, (Object) null );
163             final java.lang.StringBuilder builder = new java.lang.StringBuilder( message.length() );
164             reader = new java.io.BufferedReader( new java.io.StringReader( message ) );
165             final String lineSeparator = System.getProperty( "line.separator", "\n" );
166 
167             String line;
168             while ( ( line = reader.readLine() ) != null )
169             {
170                 builder.append( lineSeparator ).append( line );
171             }
172 
173             reader.close();
174             reader = null;
175             return builder.length() > 0 ? builder.substring( lineSeparator.length() ) : "";
176         }
177         catch( final java.io.IOException e )
178         {
179             throw new java.lang.AssertionError( e );
180         }
181         finally
182         {
183             try
184             {
185                 if( reader != null )
186                 {
187                     reader.close();
188                 }
189             }
190             catch( final java.io.IOException e )
191             {
192                 throw new java.lang.AssertionError( e );
193             }
194         }
195     }
196     // </editor-fold>
197     // SECTION-END
198 }