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: IllegalNumberMessage.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 number was specified. |
29 | * |
30 | * @author Christian Schulte |
31 | * @version $JDTAUS: IllegalNumberMessage.java 8525 2012-05-07 08:32:23Z schulte2005 $ |
32 | * @since 1.10 |
33 | */ |
34 | public final class IllegalNumberMessage extends Message |
35 | { |
36 | //--IllegalNumberMessage---------------------------------------------------- |
37 | |
38 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
39 | private static final long serialVersionUID = 6578496762473822182L; |
40 | |
41 | /** |
42 | * The invalid number. |
43 | * @serial |
44 | */ |
45 | private Number invalidNumber; |
46 | |
47 | /** |
48 | * The minimum required value. |
49 | * @serial |
50 | */ |
51 | private Number minimum; |
52 | |
53 | /** |
54 | * The maximum allowed value. |
55 | * @serial |
56 | */ |
57 | private Number maximum; |
58 | |
59 | /** |
60 | * Creates a new {@code IllegalNumberMessage} instance taking an invalid number, a minimum required value and a |
61 | * maximum allowed value. |
62 | * |
63 | * @param invalidNumber The invalid number or {@code null} if no such number is known. |
64 | * @param minimum The minimum required value or {@code null} if no such requirement exists. |
65 | * @param maximum The maximum allowed value or {@code null} if no such limit exists. |
66 | */ |
67 | public IllegalNumberMessage( final Number invalidNumber, final Number minimum, final Number maximum ) |
68 | { |
69 | super(); |
70 | this.invalidNumber = invalidNumber; |
71 | this.minimum = minimum; |
72 | this.maximum = maximum; |
73 | } |
74 | |
75 | //----------------------------------------------------IllegalNumberMessage-- |
76 | //--Message----------------------------------------------------------------- |
77 | |
78 | /** |
79 | * {@inheritDoc} |
80 | * <ul> |
81 | * <li>[0]: The invalid number or {@code null} if no such number is known.</li> |
82 | * <li>[1]: The minimum required value or {@code null} if no such requirement exists.</li> |
83 | * <li>[2]: The maximum allowed value or {@code null} if no such limit exists.</li> |
84 | * </ul> |
85 | */ |
86 | public Object[] getFormatArguments( final Locale locale ) |
87 | { |
88 | return new Object[] |
89 | { |
90 | this.invalidNumber, this.minimum, this.maximum |
91 | }; |
92 | |
93 | } |
94 | |
95 | public String getText( final Locale locale ) |
96 | { |
97 | final StringBuffer b = new StringBuffer( 128 ); |
98 | |
99 | if ( this.invalidNumber != null ) |
100 | { |
101 | b.append( this.getIllegalValueMessage( locale, this.invalidNumber ) ).append( " " ); |
102 | } |
103 | |
104 | if ( this.minimum != null ) |
105 | { |
106 | b.append( this.getIllegalMinimumValueMessage( locale, this.minimum ) ).append( " " ); |
107 | } |
108 | |
109 | if ( this.maximum != null ) |
110 | { |
111 | b.append( this.getIllegalMaximumValueMessage( locale, this.maximum ) ).append( " " ); |
112 | } |
113 | |
114 | |
115 | if ( b.length() > 0 ) |
116 | { |
117 | b.setLength( b.length() - 1 ); |
118 | } |
119 | |
120 | return b.toString(); |
121 | } |
122 | |
123 | //-----------------------------------------------------------------Message-- |
124 | //--Messages---------------------------------------------------------------- |
125 | |
126 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages |
127 | // This section is managed by jdtaus-container-mojo. |
128 | |
129 | /** |
130 | * Gets the text of message <code>illegalValue</code>. |
131 | * <blockquote><pre>Ungültiger Wert {0,number}.</pre></blockquote> |
132 | * <blockquote><pre>Illegal value {0,number}.</pre></blockquote> |
133 | * |
134 | * @param locale The locale of the message instance to return. |
135 | * @param value Illegal value. |
136 | * |
137 | * @return Information about an illegal value. |
138 | */ |
139 | private String getIllegalValueMessage( final Locale locale, |
140 | final java.lang.Number value ) |
141 | { |
142 | return ContainerFactory.getContainer(). |
143 | getMessage( this, "illegalValue", locale, |
144 | new Object[] |
145 | { |
146 | value |
147 | }); |
148 | |
149 | } |
150 | |
151 | /** |
152 | * Gets the text of message <code>illegalMaximumValue</code>. |
153 | * <blockquote><pre>Größer als {0,number}.</pre></blockquote> |
154 | * <blockquote><pre>Greater than {0,number}.</pre></blockquote> |
155 | * |
156 | * @param locale The locale of the message instance to return. |
157 | * @param maximum Maximum allowed value. |
158 | * |
159 | * @return Information about an illegal maximum value. |
160 | */ |
161 | private String getIllegalMaximumValueMessage( final Locale locale, |
162 | final java.lang.Number maximum ) |
163 | { |
164 | return ContainerFactory.getContainer(). |
165 | getMessage( this, "illegalMaximumValue", locale, |
166 | new Object[] |
167 | { |
168 | maximum |
169 | }); |
170 | |
171 | } |
172 | |
173 | /** |
174 | * Gets the text of message <code>illegalMinimumValue</code>. |
175 | * <blockquote><pre>Kleiner als {0,number}.</pre></blockquote> |
176 | * <blockquote><pre>Less than {0,number}.</pre></blockquote> |
177 | * |
178 | * @param locale The locale of the message instance to return. |
179 | * @param minimum Minimum required value. |
180 | * |
181 | * @return Information about an illegal minimum value. |
182 | */ |
183 | private String getIllegalMinimumValueMessage( final Locale locale, |
184 | final java.lang.Number minimum ) |
185 | { |
186 | return ContainerFactory.getContainer(). |
187 | getMessage( this, "illegalMinimumValue", locale, |
188 | new Object[] |
189 | { |
190 | minimum |
191 | }); |
192 | |
193 | } |
194 | |
195 | // </editor-fold>//GEN-END:jdtausMessages |
196 | |
197 | //----------------------------------------------------------------Messages-- |
198 | } |