1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.beanutils;
19
20 /**
21 * <p>Utility methods for converting String scalar values to objects of the
22 * specified Class, String arrays to arrays of the specified Class.</p>
23 *
24 * <p>For more details, see <code>ConvertUtilsBean</code> which provides the
25 * implementations for these methods.</p>
26 *
27 * @author Craig R. McClanahan
28 * @author Ralph Schaer
29 * @author Chris Audley
30 * @version $Revision: 1.17 $ $Date: 2004/02/28 13:18:33 $
31 * @see ConvertUtilsBean
32 */
33
34 public class ConvertUtils {
35
36
37
38
39 /**
40 * Gets the default value for Boolean conversions.
41 * @deprecated Register replacement converters for Boolean.TYPE and
42 * Boolean.class instead
43 */
44 public static boolean getDefaultBoolean() {
45 return (ConvertUtilsBean.getInstance().getDefaultBoolean());
46 }
47
48 /**
49 * Sets the default value for Boolean conversions.
50 * @deprecated Register replacement converters for Boolean.TYPE and
51 * Boolean.class instead
52 */
53 public static void setDefaultBoolean(boolean newDefaultBoolean) {
54 ConvertUtilsBean.getInstance().setDefaultBoolean(newDefaultBoolean);
55 }
56
57
58 /**
59 * Gets the default value for Byte conversions.
60 * @deprecated Register replacement converters for Byte.TYPE and
61 * Byte.class instead
62 */
63 public static byte getDefaultByte() {
64 return ConvertUtilsBean.getInstance().getDefaultByte();
65 }
66
67 /**
68 * Sets the default value for Byte conversions.
69 * @deprecated Register replacement converters for Byte.TYPE and
70 * Byte.class instead
71 */
72 public static void setDefaultByte(byte newDefaultByte) {
73 ConvertUtilsBean.getInstance().setDefaultByte(newDefaultByte);
74 }
75
76
77 /**
78 * Gets the default value for Character conversions.
79 * @deprecated Register replacement converters for Character.TYPE and
80 * Character.class instead
81 */
82 public static char getDefaultCharacter() {
83 return ConvertUtilsBean.getInstance().getDefaultCharacter();
84 }
85
86 /**
87 * Sets the default value for Character conversions.
88 * @deprecated Register replacement converters for Character.TYPE and
89 * Character.class instead
90 */
91 public static void setDefaultCharacter(char newDefaultCharacter) {
92 ConvertUtilsBean.getInstance().setDefaultCharacter(newDefaultCharacter);
93 }
94
95
96 /**
97 * Gets the default value for Double conversions.
98 * @deprecated Register replacement converters for Double.TYPE and
99 * Double.class instead
100 */
101 public static double getDefaultDouble() {
102 return ConvertUtilsBean.getInstance().getDefaultDouble();
103 }
104
105 /**
106 * Sets the default value for Double conversions.
107 * @deprecated Register replacement converters for Double.TYPE and
108 * Double.class instead
109 */
110 public static void setDefaultDouble(double newDefaultDouble) {
111 ConvertUtilsBean.getInstance().setDefaultDouble(newDefaultDouble);
112 }
113
114
115 /**
116 * Get the default value for Float conversions.
117 * @deprecated Register replacement converters for Float.TYPE and
118 * Float.class instead
119 */
120 public static float getDefaultFloat() {
121 return ConvertUtilsBean.getInstance().getDefaultFloat();
122 }
123
124 /**
125 * Sets the default value for Float conversions.
126 * @deprecated Register replacement converters for Float.TYPE and
127 * Float.class instead
128 */
129 public static void setDefaultFloat(float newDefaultFloat) {
130 ConvertUtilsBean.getInstance().setDefaultFloat(newDefaultFloat);
131 }
132
133
134 /**
135 * Gets the default value for Integer conversions.
136 * @deprecated Register replacement converters for Integer.TYPE and
137 * Integer.class instead
138 */
139 public static int getDefaultInteger() {
140 return ConvertUtilsBean.getInstance().getDefaultInteger();
141 }
142
143 /**
144 * Sets the default value for Integer conversions.
145 * @deprecated Register replacement converters for Integer.TYPE and
146 * Integer.class instead
147 */
148 public static void setDefaultInteger(int newDefaultInteger) {
149 ConvertUtilsBean.getInstance().setDefaultInteger(newDefaultInteger);
150 }
151
152
153 /**
154 * Gets the default value for Long conversions.
155 * @deprecated Register replacement converters for Long.TYPE and
156 * Long.class instead
157 */
158 public static long getDefaultLong() {
159 return (ConvertUtilsBean.getInstance().getDefaultLong());
160 }
161
162 /**
163 * Sets the default value for Long conversions.
164 * @deprecated Register replacement converters for Long.TYPE and
165 * Long.class instead
166 */
167 public static void setDefaultLong(long newDefaultLong) {
168 ConvertUtilsBean.getInstance().setDefaultLong(newDefaultLong);
169 }
170
171
172 /**
173 * Gets the default value for Short conversions.
174 * @deprecated Register replacement converters for Short.TYPE and
175 * Short.class instead
176 */
177 public static short getDefaultShort() {
178 return ConvertUtilsBean.getInstance().getDefaultShort();
179 }
180
181 /**
182 * Sets the default value for Short conversions.
183 * @deprecated Register replacement converters for Short.TYPE and
184 * Short.class instead
185 */
186 public static void setDefaultShort(short newDefaultShort) {
187 ConvertUtilsBean.getInstance().setDefaultShort(newDefaultShort);
188 }
189
190
191
192
193 /**
194 * <p>Convert the specified value into a String.</p>
195 *
196 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
197 *
198 * @see ConvertUtilsBean#convert(Object)
199 */
200 public static String convert(Object value) {
201
202 return ConvertUtilsBean.getInstance().convert(value);
203
204 }
205
206
207 /**
208 * <p>Convert the specified value to an object of the specified class (if
209 * possible). Otherwise, return a String representation of the value.</p>
210 *
211 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
212 *
213 * @see ConvertUtilsBean#convert(String, Class)
214 */
215 public static Object convert(String value, Class clazz) {
216
217 return ConvertUtilsBean.getInstance().convert(value, clazz);
218
219 }
220
221
222 /**
223 * <p>Convert an array of specified values to an array of objects of the
224 * specified class (if possible).</p>
225 *
226 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
227 *
228 * @see ConvertUtilsBean#convert(String[], Class)
229 */
230 public static Object convert(String values[], Class clazz) {
231
232 return ConvertUtilsBean.getInstance().convert(values, clazz);
233
234 }
235
236
237 /**
238 * <p>Remove all registered {@link Converter}s, and re-establish the
239 * standard Converters.</p>
240 *
241 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
242 *
243 * @see ConvertUtilsBean#deregister()
244 */
245 public static void deregister() {
246
247 ConvertUtilsBean.getInstance().deregister();
248
249 }
250
251
252 /**
253 * <p>Remove any registered {@link Converter} for the specified destination
254 * <code>Class</code>.</p>
255 *
256 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
257 *
258 * @see ConvertUtilsBean#deregister(Class)
259 */
260 public static void deregister(Class clazz) {
261
262 ConvertUtilsBean.getInstance().deregister(clazz);
263
264 }
265
266
267 /**
268 * <p>Look up and return any registered {@link Converter} for the specified
269 * destination class; if there is no registered Converter, return
270 * <code>null</code>.</p>
271 *
272 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
273 *
274 * @see ConvertUtilsBean#lookup(Class)
275 */
276 public static Converter lookup(Class clazz) {
277
278 return ConvertUtilsBean.getInstance().lookup(clazz);
279
280 }
281
282
283 /**
284 * <p>Register a custom {@link Converter} for the specified destination
285 * <code>Class</code>, replacing any previously registered Converter.</p>
286 *
287 * <p>For more details see <code>ConvertUtilsBean</code>.</p>
288 *
289 * @see ConvertUtilsBean#register(Converter, Class)
290 */
291 public static void register(Converter converter, Class clazz) {
292
293 ConvertUtilsBean.getInstance().register(converter, clazz);
294
295 }
296
297
298 }