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: IbanSyntaxException.java 8881 2014-09-26 13:25:44Z 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 parsing text to produce an international bank account number fails. 032 * 033 * <dl> 034 * <dt><b>Identifier:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Syntax Exception</dd> 035 * <dt><b>Name:</b></dt><dd>jDTAUS ⁑ ISO-13616 ⁑ IBAN Syntax 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.7", comments = "See http://www.jomc.org/jomc/1.7/jomc-tools-1.7" ) 049// </editor-fold> 050// SECTION-END 051public class IbanSyntaxException extends Exception 052{ 053 // SECTION-START[IbanSyntaxException] 054 055 /** Serial version UID for backwards compatibility with 2007.45.x classes. */ 056 private static final long serialVersionUID = -475265309170567430L; 057 058 /** 059 * The malformed text. 060 * @serial 061 */ 062 private String malformedText; 063 064 /** 065 * The position at which parsing failed. 066 * @serial 067 */ 068 private int errorIndex; 069 070 /** 071 * Creates a new {@code IbanSyntaxException} instance taking malformed text and a position at which parsing failed. 072 * 073 * @param malformedText The malformed text. 074 * @param errorIndex The position at which parsing failed. 075 */ 076 public IbanSyntaxException( final String malformedText, final int errorIndex ) 077 { 078 super(); 079 this.malformedText = malformedText; 080 this.errorIndex = errorIndex; 081 } 082 083 /** 084 * Gets a message describing the exception. 085 * 086 * @return A message describing the exception. 087 */ 088 @Override 089 public String getMessage() 090 { 091 return getIbanSyntaxExceptionMessage( Locale.getDefault(), this.getMalformedText(), this.getErrorIndex() ); 092 } 093 094 /** 095 * Gets a localized message describing the exception for a given locale. 096 * 097 * @param locale The locale of the localized message to get. 098 * 099 * @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({"unchecked", "unused", "PMD.UnnecessaryFullyQualifiedName"}) 154 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.7", comments = "See http://www.jomc.org/jomc/1.7/jomc-tools-1.7" ) 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}