| 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: IbanSyntaxException.java 8825 2013-10-01 00:24:23Z 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 parsing text to produce an international bank account number fails. | 
| 32 | * | 
| 33 | * <dl> | 
| 34 | *   <dt><b>Identifier:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Syntax Exception</dd> | 
| 35 | *   <dt><b>Name:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Syntax 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.0 | 
| 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 IbanSyntaxException extends Exception | 
| 52 | { | 
| 53 | // SECTION-START[IbanSyntaxException] | 
| 54 |  | 
| 55 | /** Serial version UID for backwards compatibility with 2007.45.x classes. */ | 
| 56 | private static final long serialVersionUID = -475265309170567430L; | 
| 57 |  | 
| 58 | /** | 
| 59 | * The malformed text. | 
| 60 | * @serial | 
| 61 | */ | 
| 62 | private String malformedText; | 
| 63 |  | 
| 64 | /** | 
| 65 | * The position at which parsing failed. | 
| 66 | * @serial | 
| 67 | */ | 
| 68 | private int errorIndex; | 
| 69 |  | 
| 70 | /** | 
| 71 | * Creates a new {@code IbanSyntaxException} instance taking malformed text and a position at which parsing failed. | 
| 72 | * | 
| 73 | * @param malformedText The malformed text. | 
| 74 | * @param errorIndex The position at which parsing failed. | 
| 75 | */ | 
| 76 | public IbanSyntaxException( final String malformedText, final int errorIndex ) | 
| 77 | { | 
| 78 | super(); | 
| 79 | this.malformedText = malformedText; | 
| 80 | this.errorIndex = errorIndex; | 
| 81 | } | 
| 82 |  | 
| 83 | /** | 
| 84 | * Gets a message describing the exception. | 
| 85 | * | 
| 86 | * @return A message describing the exception. | 
| 87 | */ | 
| 88 | @Override | 
| 89 | public String getMessage() | 
| 90 | { | 
| 91 | return getIbanSyntaxExceptionMessage( Locale.getDefault(), this.getMalformedText(), this.getErrorIndex() ); | 
| 92 | } | 
| 93 |  | 
| 94 | /** | 
| 95 | * Gets a localized message describing the exception for a given locale. | 
| 96 | * | 
| 97 | * @param locale The locale of the localized message to get. | 
| 98 | * | 
| 99 | * @return A localized message describing the exception. | 
| 100 | * | 
| 101 | * @throws NullPointerException if {@code locale} is {@code null}. | 
| 102 | */ | 
| 103 | public String getLocalizedMessage( final Locale locale ) | 
| 104 | { | 
| 105 | if ( locale == null ) | 
| 106 | { | 
| 107 | throw new NullPointerException( "locale" ); | 
| 108 | } | 
| 109 |  | 
| 110 | return getIbanSyntaxExceptionMessage( locale, this.getMalformedText(), this.getErrorIndex() ); | 
| 111 | } | 
| 112 |  | 
| 113 | /** | 
| 114 | * Gets the malformed text causing the exception. | 
| 115 | * | 
| 116 | * @return The malformed text causing the exception. | 
| 117 | */ | 
| 118 | public String getMalformedText() | 
| 119 | { | 
| 120 | return this.malformedText; | 
| 121 | } | 
| 122 |  | 
| 123 | /** | 
| 124 | * Gets the position at which parsing failed. | 
| 125 | * | 
| 126 | * @return The position at which parsing failed. | 
| 127 | */ | 
| 128 | public int getErrorIndex() | 
| 129 | { | 
| 130 | return this.errorIndex; | 
| 131 | } | 
| 132 |  | 
| 133 | // SECTION-END | 
| 134 | // SECTION-START[Dependencies] | 
| 135 | // SECTION-END | 
| 136 | // SECTION-START[Properties] | 
| 137 | // SECTION-END | 
| 138 | // SECTION-START[Messages] | 
| 139 | // <editor-fold defaultstate="collapsed" desc=" Generated Messages "> | 
| 140 | /** | 
| 141 | * Gets the text of the {@code <IBAN Syntax Exception Message>} message. | 
| 142 | * <p><dl> | 
| 143 | *   <dt><b>Languages:</b></dt> | 
| 144 | *     <dd>English (default)</dd> | 
| 145 | *     <dd>Deutsch</dd> | 
| 146 | *   <dt><b>Final:</b></dt><dd>No</dd> | 
| 147 | * </dl></p> | 
| 148 | * @param locale The locale of the message to return. | 
| 149 | * @param malformedText Format argument. | 
| 150 | * @param errorIndex Format argument. | 
| 151 | * @return The text of the {@code <IBAN Syntax Exception Message>} message for {@code locale}. | 
| 152 | */ | 
| 153 | @SuppressWarnings("unused") | 
| 154 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" ) | 
| 155 | private static String getIbanSyntaxExceptionMessage( final java.util.Locale locale, final java.lang.String malformedText, final java.lang.Number errorIndex ) | 
| 156 | { | 
| 157 | java.io.BufferedReader reader = null; | 
| 158 |  | 
| 159 | try | 
| 160 | { | 
| 161 | final String message = java.text.MessageFormat.format( java.util.ResourceBundle.getBundle( "org.jdtaus.iso13616.IbanSyntaxException", locale ).getString( "IBAN Syntax Exception Message" ), malformedText, errorIndex, (Object) null ); | 
| 162 | final java.lang.StringBuilder builder = new java.lang.StringBuilder( message.length() ); | 
| 163 | reader = new java.io.BufferedReader( new java.io.StringReader( message ) ); | 
| 164 | final String lineSeparator = System.getProperty( "line.separator", "\n" ); | 
| 165 |  | 
| 166 | String line; | 
| 167 | while ( ( line = reader.readLine() ) != null ) | 
| 168 | { | 
| 169 | builder.append( lineSeparator ).append( line ); | 
| 170 | } | 
| 171 |  | 
| 172 | reader.close(); | 
| 173 | reader = null; | 
| 174 | return builder.length() > 0 ? builder.substring( lineSeparator.length() ) : ""; | 
| 175 | } | 
| 176 | catch( final java.io.IOException e ) | 
| 177 | { | 
| 178 | throw new java.lang.AssertionError( e ); | 
| 179 | } | 
| 180 | finally | 
| 181 | { | 
| 182 | try | 
| 183 | { | 
| 184 | if( reader != null ) | 
| 185 | { | 
| 186 | reader.close(); | 
| 187 | } | 
| 188 | } | 
| 189 | catch( final java.io.IOException e ) | 
| 190 | { | 
| 191 | throw new java.lang.AssertionError( e ); | 
| 192 | } | 
| 193 | } | 
| 194 | } | 
| 195 | // </editor-fold> | 
| 196 | // SECTION-END | 
| 197 | } |