org.apache.commons.beanutils
public class ConvertUtilsBean extends Object
Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class. The actual Converter instance to be used can be registered for each possible destination Class. Unless you override them, standard Converter instances are provided for all of the following destination Classes:
For backwards compatibility, the standard Converters for primitive types (and the corresponding wrapper classes) return a defined default value when a conversion error occurs. If you prefer to have a ConversionException thrown instead, replace the standard Converter instances with instances created with the zero-arguments constructor. For example, to cause the Converters for integers to throw an exception on conversion errors, you could do this:
// No-args constructor gets the version that throws exceptions Converter myConverter = new org.apache.commons.beanutils.converter.IntegerConverter(); ConvertUtils.register(myConverter, Integer.TYPE); // Native type ConvertUtils.register(myConverter, Integer.class); // Wrapper class
Since: 1.7
Version: $Revision: 1.12.2.1 $ $Date: 2004/07/27 21:44:26 $
Field Summary | |
---|---|
FastHashMap | converters
The set of Converters that can be used to convert Strings
into objects of a specified Class, keyed by the destination Class. |
Boolean | defaultBoolean
The default value for Boolean conversions. |
Byte | defaultByte
The default value for Byte conversions. |
Character | defaultCharacter
The default value for Character conversions. |
Double | defaultDouble
The default value for Double conversions. |
Float | defaultFloat
The default value for Float conversions. |
Integer | defaultInteger
The default value for Integer conversions. |
Long | defaultLong
The default value for Long conversions. |
static Short | defaultShort
The default value for Short conversions. |
Log | log
The Log instance for this class. |
Constructor Summary | |
---|---|
ConvertUtilsBean() Construct a bean with standard converters registered |
Method Summary | |
---|---|
String | convert(Object value)
Convert the specified value into a String. |
Object | convert(String value, Class clazz)
Convert the specified value to an object of the specified class (if
possible). |
Object | convert(String[] values, Class clazz)
Convert an array of specified values to an array of objects of the
specified class (if possible). |
void | deregister()
Remove all registered Converters, and re-establish the
standard Converters. |
void | deregister(Class clazz)
Remove any registered Converter for the specified destination
Class .
|
boolean | getDefaultBoolean()
Gets the default value for Boolean conversions. |
byte | getDefaultByte()
Gets the default value for Byte conversions. |
char | getDefaultCharacter()
Gets the default value for Character conversions. |
double | getDefaultDouble()
Gets the default value for Double conversions. |
float | getDefaultFloat()
Gets the default value for Float conversions. |
int | getDefaultInteger()
Gets the default value for Integer conversions. |
long | getDefaultLong()
Gets the default value for Long conversions. |
short | getDefaultShort()
Gets the default value for Short conversions. |
protected static ConvertUtilsBean | getInstance() Get singleton instance |
Converter | lookup(Class clazz)
Look up and return any registered Converter for the specified
destination class; if there is no registered Converter, return
null .
|
void | register(Class clazz, Converter converter) strictly for convenience since it has same parameter order as Map.put |
void | register(Converter converter, Class clazz)
Register a custom Converter for the specified destination
Class , replacing any previously registered Converter.
|
void | setDefaultBoolean(boolean newDefaultBoolean)
Sets the default value for Boolean conversions. |
void | setDefaultByte(byte newDefaultByte)
Sets the default value for Byte conversions. |
void | setDefaultCharacter(char newDefaultCharacter)
Sets the default value for Character conversions. |
void | setDefaultDouble(double newDefaultDouble)
Sets the default value for Double conversions. |
void | setDefaultFloat(float newDefaultFloat)
Sets the default value for Float conversions. |
void | setDefaultInteger(int newDefaultInteger)
Sets the default value for Integer conversions. |
void | setDefaultLong(long newDefaultLong)
Sets the default value for Long conversions. |
void | setDefaultShort(short newDefaultShort)
Sets the default value for Short conversions. |
Deprecated: Register replacement converters for Boolean.TYPE and Boolean.class instead
The default value for Boolean conversions.Deprecated: Register replacement converters for Byte.TYPE and Byte.class instead
The default value for Byte conversions.Deprecated: Register replacement converters for Character.TYPE and Character.class instead
The default value for Character conversions.Deprecated: Register replacement converters for Double.TYPE and Double.class instead
The default value for Double conversions.Deprecated: Register replacement converters for Float.TYPE and Float.class instead
The default value for Float conversions.Deprecated: Register replacement converters for Integer.TYPE and Integer.class instead
The default value for Integer conversions.Deprecated: Register replacement converters for Long.TYPE and Long.class instead
The default value for Long conversions.Deprecated: Register replacement converters for Short.TYPE and Short.class instead
The default value for Short conversions.Log
instance for this class.java.lang.String
class will be used, which allows
applications to customize Object->String conversions (the default
implementation simply uses toString()).
Parameters: value Value to be converted (may be null)
Parameters: value Value to be converted (may be null) clazz Java class to be converted to
Throws: ConversionException if thrown by an underlying Converter
Parameters: values Values to be converted (may be null) clazz Java array or element class to be converted to
Throws: ConversionException if thrown by an underlying Converter
Class
.
Parameters: clazz Class for which to remove a registered Converter
Deprecated: Register replacement converters for Boolean.TYPE and Boolean.class instead
Gets the default value for Boolean conversions.Deprecated: Register replacement converters for Byte.TYPE and Byte.class instead
Gets the default value for Byte conversions.Deprecated: Register replacement converters for Character.TYPE and Character.class instead
Gets the default value for Character conversions.Deprecated: Register replacement converters for Double.TYPE and Double.class instead
Gets the default value for Double conversions.Deprecated: Register replacement converters for Float.TYPE and Float.class instead
Gets the default value for Float conversions.Deprecated: Register replacement converters for Integer.TYPE and Integer.class instead
Gets the default value for Integer conversions.Deprecated: Register replacement converters for Long.TYPE and Long.class instead
Gets the default value for Long conversions.Deprecated: Register replacement converters for Short.TYPE and Short.class instead
Gets the default value for Short conversions.null
.
Parameters: clazz Class for which to return a registered Converter
Class
, replacing any previously registered Converter.
Parameters: converter Converter to be registered clazz Destination class for conversions performed by this Converter
Deprecated: Register replacement converters for Boolean.TYPE and Boolean.class instead
Sets the default value for Boolean conversions.Deprecated: Register replacement converters for Byte.TYPE and Byte.class instead
Sets the default value for Byte conversions.Deprecated: Register replacement converters for Character.TYPE and Character.class instead
Sets the default value for Character conversions.Deprecated: Register replacement converters for Double.TYPE and Double.class instead
Sets the default value for Double conversions.Deprecated: Register replacement converters for Float.TYPE and Float.class instead
Sets the default value for Float conversions.Deprecated: Register replacement converters for Integer.TYPE and Integer.class instead
Sets the default value for Integer conversions.Deprecated: Register replacement converters for Long.TYPE and Long.class instead
Sets the default value for Long conversions.Deprecated: Register replacement converters for Short.TYPE and Short.class instead
Sets the default value for Short conversions.