001// SECTION-START[License Header]
002// <editor-fold defaultstate="collapsed" desc=" Generated License ">
003/*
004 *   jDTAUS ⁑ ISO-13616
005 *   Copyright (C) Christian Schulte, 2013-222
006 *
007 *   Permission to use, copy, modify, and/or distribute this software for any
008 *   purpose with or without fee is hereby granted, provided that the above
009 *   copyright notice and this permission notice appear in all copies.
010 *
011 *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
012 *   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
013 *   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
014 *   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
015 *   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
016 *   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
017 *   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
018 *
019 *   $JDTAUS: IbanCheckDigitsException.java 8901 2015-06-20 18:30:19Z schulte $
020 *
021 */
022// </editor-fold>
023// SECTION-END
024package org.jdtaus.iso13616;
025
026import java.util.Locale;
027
028// SECTION-START[Documentation]
029// <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
030/**
031 * Gets thrown whenever validation of the check digits of an international bank account number fails.
032 *
033 * <dl>
034 *   <dt><b>Identifier:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Check Digits Exception</dd>
035 *   <dt><b>Name:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Check Digits Exception</dd>
036 *   <dt><b>Abstract:</b></dt><dd>No</dd>
037 *   <dt><b>Final:</b></dt><dd>Yes</dd>
038 *   <dt><b>Stateless:</b></dt><dd>No</dd>
039 * </dl>
040 *
041 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
042 * @version 1.1
043 */
044// </editor-fold>
045// SECTION-END
046// SECTION-START[Annotations]
047// <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
048@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
049// </editor-fold>
050// SECTION-END
051public class IbanCheckDigitsException extends Exception
052{
053    // SECTION-START[IbanCheckDigitsException]
054
055    /** Serial version UID for backwards compatibility with 2007.45.x classes. */
056    private static final long serialVersionUID = 2758511596781778791L;
057
058    /**
059     * The IBAN failing check digits validation.
060     * @serial
061     */
062    private String iban;
063
064    /**
065     * The invalid check digits.
066     * @serial
067     */
068    private Number checkDigits;
069
070    /**
071     * Creates a new {@code IbanCheckDigitsException} instance taking the IBAN failing check digits validation and the
072     * invalid check digits.
073     *
074     * @param iban The IBAN failing check digits validation.
075     * @param checkDigits The invalid check digits.
076     */
077    public IbanCheckDigitsException( final String iban, final Number checkDigits )
078    {
079        super();
080        this.iban = iban;
081        this.checkDigits = checkDigits;
082    }
083
084    /**
085     * Gets a message describing the exception.
086     *
087     * @return A message describing the exception.
088     */
089    @Override
090    public String getMessage()
091    {
092        return getIbanCheckDigitsExceptionMessage( Locale.getDefault(), this.getIban(), this.getCheckDigits() );
093    }
094
095    /**
096     * Gets a localized message describing the exception for a given locale.
097     *
098     * @param locale The locale of the localized message to get.
099     *
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({"unchecked", "unused", "PMD.UnnecessaryFullyQualifiedName"})
155    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
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}