1 /*
2 * jDTAUS Banking Messages
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.messages;
22
23 import java.util.Locale;
24 import org.jdtaus.core.container.ContainerFactory;
25 import org.jdtaus.core.text.Message;
26
27 /**
28 * Message stating that a field holds invalid data.
29 *
30 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31 * @version $JDTAUS: IllegalDataMessage.java 8661 2012-09-27 11:29:58Z schulte $
32 */
33 public final class IllegalDataMessage extends Message
34 {
35
36 /** Constant for DTAUS alphabet fields. */
37 public static final int TYPE_ALPHA = 1;
38
39 /** Constant for numeric DTAUS alphabet fields. */
40 public static final int TYPE_NUMERIC = 2;
41
42 /** Constant for alpha-numeric DTAUS alphabet fields. */
43 public static final int TYPE_ALPHA_NUMERIC = 3;
44
45 /** Constant for EBCDIC packed number fields. */
46 public static final int TYPE_PACKET_POSITIVE = 4;
47
48 /** Constant for well-known constant value fields. */
49 public static final int TYPE_CONSTANT = 5;
50
51 /** Constant for reserved fields. */
52 public static final int TYPE_RESERVED = 6;
53
54 /** Constant for two-digit year information date fields. */
55 public static final int TYPE_SHORTDATE = 7;
56
57 /** Constant for four-digit year information date fields. */
58 public static final int TYPE_LONGDATE = 8;
59
60 /** Constant for field 3 of an A record. */
61 public static final int TYPE_FILETYPE = 9;
62
63 /** Constant for {@code Bankleitzahl} fields. */
64 public static final int TYPE_BANKLEITZAHL = 10;
65
66 /** Constant for {@code Kontonummer} fields. */
67 public static final int TYPE_KONTONUMMER = 11;
68
69 /**
70 * Constant for either a {@code Referenznummer10} or
71 * {@code Referenznummer11} fields.
72 */
73 public static final int TYPE_REFERENZNUMMER = 12;
74
75 /** Constant for {@code Textschluessel} fields. */
76 public static final int TYPE_TEXTSCHLUESSEL = 13;
77
78 /** Constant for currency fields. */
79 public static final int TYPE_CURRENCY = 14;
80
81 /** All type constants. */
82 private static final int[] TYPES =
83 {
84 TYPE_ALPHA, TYPE_NUMERIC, TYPE_ALPHA_NUMERIC, TYPE_PACKET_POSITIVE, TYPE_CONSTANT, TYPE_RESERVED,
85 TYPE_SHORTDATE, TYPE_LONGDATE, TYPE_FILETYPE, TYPE_BANKLEITZAHL, TYPE_KONTONUMMER, TYPE_REFERENZNUMMER,
86 TYPE_TEXTSCHLUESSEL, TYPE_CURRENCY
87 };
88
89 /** Serial version UID for backwards compatibility with 1.0.x classes. */
90 private static final long serialVersionUID = 5634623930947949635L;
91
92 /**
93 * Constant of the field holding illegal data.
94 * @serial
95 */
96 private final int field;
97
98 /**
99 * Absolute position of the field holding illegal data.
100 * @serial
101 */
102 private final long position;
103
104 /**
105 * Constant for the type of the field holding illegal data.
106 * @serial
107 */
108 private final int type;
109
110 /**
111 * The illegal data.
112 * @serial
113 */
114 private final String invalidData;
115
116 /**
117 * Creates a new {@code IllegalDataMessage} instance taking information about the illegal data.
118 *
119 * @param field Constant for the field holding illegal data.
120 * @param type Constant for the type of the field.
121 * @param position Absolute position of the field holding illegal data.
122 * @param invalidData The illegal data held in {@code field} at {@code position}.
123 *
124 * @throws IllegalArgumentException if {@code type} does not match one of {@link #TYPE_ALPHA TYPE_<i>XYZ</i>}
125 * constants.
126 *
127 * @see org.jdtaus.banking.dtaus.spi.Fields
128 */
129 public IllegalDataMessage( final int field, final int type, final long position, final String invalidData )
130 {
131 super();
132 this.field = field;
133 this.type = type;
134 this.position = position;
135 this.invalidData = invalidData;
136 this.assertValidType();
137 }
138
139 /**
140 * Checks a given integer to match one of the {@code TYPE_<i>XYZ</i>} constants.
141 *
142 * @throws IllegalArgumentException if {@code type} does not match one of {@link #TYPE_ALPHA TYPE_<i>XYZ</i>}
143 * constants.
144 */
145 private void assertValidType()
146 {
147 boolean valid = false;
148 for ( int i = TYPES.length - 1; i >= 0 && !valid; i-- )
149 {
150 if ( TYPES[i] == this.type )
151 {
152 valid = true;
153 break;
154 }
155 }
156
157 if ( !valid )
158 {
159 throw new IllegalArgumentException( Integer.toString( this.type ) );
160 }
161 }
162
163 /**
164 * {@inheritDoc}
165 *
166 * @return A string describing the field holding illegal data, the absolute position of that field, and the illegal
167 * data held by the field.
168 * <ul>
169 * <li>[0]: a string describing the field holding illegal data.</li>
170 * <li>[1]: the absolute position of that field.</li>
171 * <li>[2]: the invalid data.</li>
172 * </ul>
173 */
174 public Object[] getFormatArguments( final Locale locale )
175 {
176 return new Object[]
177 {
178 Integer.toHexString( this.field ).toUpperCase( locale ),
179 new Long( this.position ),
180 this.invalidData
181 };
182 }
183
184 /**
185 * {@inheritDoc}
186 *
187 * @return The corresponding text from the message's {@code ResourceBundle}
188 * <blockquote><pre>
189 * "{2}" is no valid value for field {0} (at {1, number}).
190 * </pre></blockquote>
191 */
192 public String getText( final Locale locale )
193 {
194 return this.getIllegalDataMessage(
195 locale, Integer.toHexString( this.field ).toUpperCase(), new Long( this.position ), this.invalidData );
196
197 }
198
199 //--Messages----------------------------------------------------------------
200
201 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
202 // This section is managed by jdtaus-container-mojo.
203
204 /**
205 * Gets the text of message <code>illegalData</code>.
206 * <blockquote><pre>"{2}" ist kein gültiger Wert für Feld {0} (Position {1, number}).</pre></blockquote>
207 * <blockquote><pre>"{2}" is no valid value for field {0} (at {1, number}).</pre></blockquote>
208 *
209 * @param locale The locale of the message instance to return.
210 * @param fld format argument.
211 * @param pos format argument.
212 * @param data format argument.
213 *
214 * @return the text of message <code>illegalData</code>.
215 */
216 private String getIllegalDataMessage( final Locale locale,
217 final java.lang.String fld,
218 final java.lang.Number pos,
219 final java.lang.String data )
220 {
221 return ContainerFactory.getContainer().
222 getMessage( this, "illegalData", locale,
223 new Object[]
224 {
225 fld,
226 pos,
227 data
228 });
229
230 }
231
232 // </editor-fold>//GEN-END:jdtausMessages
233
234 //----------------------------------------------------------------Messages--
235 }