1 | /* |
2 | * jDTAUS Core Messages |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * |
19 | * $JDTAUS: IllegalStringMessage.java 8525 2012-05-07 08:32:23Z schulte2005 $ |
20 | */ |
21 | package org.jdtaus.core.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 an illegal string was specified. |
29 | * |
30 | * @author Christian Schulte |
31 | * @version $JDTAUS: IllegalStringMessage.java 8525 2012-05-07 08:32:23Z schulte2005 $ |
32 | * @since 1.10 |
33 | */ |
34 | public final class IllegalStringMessage extends Message |
35 | { |
36 | //--IllegalStringMessage---------------------------------------------------- |
37 | |
38 | /** Serial version UID for backwards compatibility with 1.10.x classes. */ |
39 | private static final long serialVersionUID = -8783693360487171440L; |
40 | |
41 | /** |
42 | * The invalid string. |
43 | * @serial |
44 | */ |
45 | private String invalidString; |
46 | |
47 | /** |
48 | * The invalid characters of the string. |
49 | * @serial |
50 | */ |
51 | private char[] invalidCharacters; |
52 | |
53 | /** |
54 | * The minimum required length. |
55 | * @serial |
56 | */ |
57 | private Number minimumLength; |
58 | |
59 | /** |
60 | * The maximum allowed length. |
61 | * @serial |
62 | */ |
63 | private Number maximumLength; |
64 | |
65 | /** |
66 | * Creates a new {@code IllegalStringMessage} instance taking an invalid string, an array of invalid characters, |
67 | * a minimum required length and a maximum allowed length. |
68 | * |
69 | * @param invalidString The invalid string or {@code null} if no such string is known. |
70 | * @param invalidCharacters The invalid characters or {@code null} if no such characters are known. |
71 | * @param minimumLength The minimum required length or {@code null} if no such requirement exists. |
72 | * @param maximumLength The maximum allowed length or {@code null} if no such limit exists. |
73 | */ |
74 | public IllegalStringMessage( final String invalidString, final char[] invalidCharacters, |
75 | final Number minimumLength, final Number maximumLength ) |
76 | { |
77 | super(); |
78 | this.invalidString = invalidString; |
79 | this.invalidCharacters = invalidCharacters; |
80 | this.minimumLength = minimumLength; |
81 | this.maximumLength = maximumLength; |
82 | } |
83 | |
84 | //----------------------------------------------------IllegalStringMessage-- |
85 | //--Message----------------------------------------------------------------- |
86 | |
87 | /** |
88 | * {@inheritDoc} |
89 | * <ul> |
90 | * <li>[0]: The invalid string or {@code null} if no such string is known.</li> |
91 | * <li>[1]: The invalid characters or {@code null} if no such characters are known.</li> |
92 | * <li>[2]: The minimum required length or {@code null} if no such requirement exists.</li> |
93 | * <li>[3]: The maximum allowed length or {@code null} if no such limit exists.</li> |
94 | * </ul> |
95 | */ |
96 | public Object[] getFormatArguments( final Locale locale ) |
97 | { |
98 | return new Object[] |
99 | { |
100 | this.invalidString, this.invalidCharacters, this.minimumLength, this.maximumLength |
101 | }; |
102 | |
103 | } |
104 | |
105 | public String getText( final Locale locale ) |
106 | { |
107 | final StringBuffer b = new StringBuffer( 128 ); |
108 | |
109 | if ( this.invalidString != null ) |
110 | { |
111 | b.append( this.getIllegalStringMessage( locale, this.invalidString ) ).append( " " ); |
112 | } |
113 | |
114 | if ( this.invalidCharacters != null ) |
115 | { |
116 | final StringBuffer c = new StringBuffer( this.invalidCharacters.length * 2 ).append( "[" ); |
117 | |
118 | for ( int i = 0, s0 = this.invalidCharacters.length; i < s0; i++ ) |
119 | { |
120 | c.append( this.invalidCharacters[i] ).append( ", " ); |
121 | } |
122 | |
123 | c.setLength( c.length() - 2 ); |
124 | c.append( "]" ); |
125 | |
126 | b.append( this.getIllegalCharactersMessage( locale, c.toString() ) ).append( " " ); |
127 | } |
128 | |
129 | if ( this.minimumLength != null ) |
130 | { |
131 | b.append( this.getIllegalMinimumStringLengthMessage( locale, this.minimumLength ) ).append( " " ); |
132 | } |
133 | |
134 | if ( this.maximumLength != null ) |
135 | { |
136 | b.append( this.getIllegalMaximumStringLengthMessage( locale, this.maximumLength ) ).append( " " ); |
137 | } |
138 | |
139 | if ( b.length() > 0 ) |
140 | { |
141 | b.setLength( b.length() - 1 ); |
142 | } |
143 | |
144 | return b.toString(); |
145 | } |
146 | |
147 | //-----------------------------------------------------------------Message-- |
148 | //--Messages---------------------------------------------------------------- |
149 | |
150 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages |
151 | // This section is managed by jdtaus-container-mojo. |
152 | |
153 | /** |
154 | * Gets the text of message <code>illegalString</code>. |
155 | * <blockquote><pre>Ungültige Zeichenkette ''{0}''.</pre></blockquote> |
156 | * <blockquote><pre>Illegal string ''{0}''.</pre></blockquote> |
157 | * |
158 | * @param locale The locale of the message instance to return. |
159 | * @param illegalString Illegal string. |
160 | * |
161 | * @return Information about an illegal string. |
162 | */ |
163 | private String getIllegalStringMessage( final Locale locale, |
164 | final java.lang.String illegalString ) |
165 | { |
166 | return ContainerFactory.getContainer(). |
167 | getMessage( this, "illegalString", locale, |
168 | new Object[] |
169 | { |
170 | illegalString |
171 | }); |
172 | |
173 | } |
174 | |
175 | /** |
176 | * Gets the text of message <code>illegalMaximumStringLength</code>. |
177 | * <blockquote><pre>Mehr als {0,number} Zeichen.</pre></blockquote> |
178 | * <blockquote><pre>More than {0,number} characters.</pre></blockquote> |
179 | * |
180 | * @param locale The locale of the message instance to return. |
181 | * @param maximumLength Maximum allowed length. |
182 | * |
183 | * @return Information about an illegal maximum string length. |
184 | */ |
185 | private String getIllegalMaximumStringLengthMessage( final Locale locale, |
186 | final java.lang.Number maximumLength ) |
187 | { |
188 | return ContainerFactory.getContainer(). |
189 | getMessage( this, "illegalMaximumStringLength", locale, |
190 | new Object[] |
191 | { |
192 | maximumLength |
193 | }); |
194 | |
195 | } |
196 | |
197 | /** |
198 | * Gets the text of message <code>illegalMinimumStringLength</code>. |
199 | * <blockquote><pre>Weniger als {0,number} Zeichen.</pre></blockquote> |
200 | * <blockquote><pre>Less than {0,number} characters.</pre></blockquote> |
201 | * |
202 | * @param locale The locale of the message instance to return. |
203 | * @param minimumLength Minimum required length. |
204 | * |
205 | * @return Information about an illegal minimum string length. |
206 | */ |
207 | private String getIllegalMinimumStringLengthMessage( final Locale locale, |
208 | final java.lang.Number minimumLength ) |
209 | { |
210 | return ContainerFactory.getContainer(). |
211 | getMessage( this, "illegalMinimumStringLength", locale, |
212 | new Object[] |
213 | { |
214 | minimumLength |
215 | }); |
216 | |
217 | } |
218 | |
219 | /** |
220 | * Gets the text of message <code>illegalCharacters</code>. |
221 | * <blockquote><pre>Ungültige Zeichen {0}.</pre></blockquote> |
222 | * <blockquote><pre>Illegal characters {0}.</pre></blockquote> |
223 | * |
224 | * @param locale The locale of the message instance to return. |
225 | * @param illegalCharacters Illegal characters. |
226 | * |
227 | * @return Information about illegal characters. |
228 | */ |
229 | private String getIllegalCharactersMessage( final Locale locale, |
230 | final java.lang.String illegalCharacters ) |
231 | { |
232 | return ContainerFactory.getContainer(). |
233 | getMessage( this, "illegalCharacters", locale, |
234 | new Object[] |
235 | { |
236 | illegalCharacters |
237 | }); |
238 | |
239 | } |
240 | |
241 | // </editor-fold>//GEN-END:jdtausMessages |
242 | |
243 | //----------------------------------------------------------------Messages-- |
244 | } |