|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.beanutils.ConvertUtils
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
Field Summary | |
private static org.apache.commons.collections.FastHashMap |
converters
The set of Converter s that can be used to convert Strings
into objects of a specified Class, keyed by the destination Class. |
private static java.lang.Boolean |
defaultBoolean
Deprecated. Register replacement converters for Boolean.TYPE and Boolean.class instead |
private static java.lang.Byte |
defaultByte
Deprecated. Register replacement converters for Byte.TYPE and Byte.class instead |
private static java.lang.Character |
defaultCharacter
Deprecated. Register replacement converters for Character.TYPE and Character.class instead |
private static java.lang.Double |
defaultDouble
Deprecated. Register replacement converters for Double.TYPE and Double.class instead |
private static java.lang.Float |
defaultFloat
Deprecated. Register replacement converters for Float.TYPE and Float.class instead |
private static java.lang.Integer |
defaultInteger
Deprecated. Register replacement converters for Integer.TYPE and Integer.class instead |
private static java.lang.Long |
defaultLong
Deprecated. Register replacement converters for Long.TYPE and Long.class instead |
private static java.lang.Short |
defaultShort
Deprecated. Register replacement converters for Short.TYPE and Short.class instead |
private static org.apache.commons.logging.Log |
log
The Log instance for this class. |
Constructor Summary | |
ConvertUtils()
|
Method Summary | |
static java.lang.String |
convert(java.lang.Object value)
Convert the specified value into a String. |
static java.lang.Object |
convert(java.lang.String[] values,
java.lang.Class clazz)
Convert an array of specified values to an array of objects of the specified class (if possible). |
static java.lang.Object |
convert(java.lang.String value,
java.lang.Class clazz)
Convert the specified value to an object of the specified class (if possible). |
static void |
deregister()
Remove all registered Converter s, and re-establish the
standard Converters. |
static void |
deregister(java.lang.Class clazz)
Remove any registered Converter for the specified destination
Class . |
static boolean |
getDefaultBoolean()
|
static byte |
getDefaultByte()
|
static char |
getDefaultCharacter()
|
static double |
getDefaultDouble()
|
static float |
getDefaultFloat()
|
static int |
getDefaultInteger()
|
static long |
getDefaultLong()
|
static short |
getDefaultShort()
|
static Converter |
lookup(java.lang.Class clazz)
Look up and return any registered Converter for the specified
destination class; if there is no registered Converter, return
null . |
static void |
register(Converter converter,
java.lang.Class clazz)
Register a custom Converter for the specified destination
Class , replacing any previously registered Converter. |
static void |
setDefaultBoolean(boolean newDefaultBoolean)
|
static void |
setDefaultByte(byte newDefaultByte)
|
static void |
setDefaultCharacter(char newDefaultCharacter)
|
static void |
setDefaultDouble(double newDefaultDouble)
|
static void |
setDefaultFloat(float newDefaultFloat)
|
static void |
setDefaultInteger(int newDefaultInteger)
|
static void |
setDefaultLong(long newDefaultLong)
|
static void |
setDefaultShort(short newDefaultShort)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static java.lang.Boolean defaultBoolean
private static java.lang.Byte defaultByte
private static java.lang.Character defaultCharacter
private static java.lang.Double defaultDouble
private static java.lang.Float defaultFloat
private static java.lang.Integer defaultInteger
private static java.lang.Long defaultLong
private static java.lang.Short defaultShort
private static org.apache.commons.collections.FastHashMap converters
Converter
s that can be used to convert Strings
into objects of a specified Class, keyed by the destination Class.
private static org.apache.commons.logging.Log log
Log
instance for this class.
Constructor Detail |
public ConvertUtils()
Method Detail |
public static boolean getDefaultBoolean()
public static void setDefaultBoolean(boolean newDefaultBoolean)
public static byte getDefaultByte()
public static void setDefaultByte(byte newDefaultByte)
public static char getDefaultCharacter()
public static void setDefaultCharacter(char newDefaultCharacter)
public static double getDefaultDouble()
public static void setDefaultDouble(double newDefaultDouble)
public static float getDefaultFloat()
public static void setDefaultFloat(float newDefaultFloat)
public static int getDefaultInteger()
public static void setDefaultInteger(int newDefaultInteger)
public static long getDefaultLong()
public static void setDefaultLong(long newDefaultLong)
public static short getDefaultShort()
public static void setDefaultShort(short newDefaultShort)
public static java.lang.String convert(java.lang.Object value)
Converter
for the
java.lang.String
class will be used, which allows
applications to customize Object->String conversions (the default
implementation simply uses toString()).
value
- Value to be converted (may be null)public static java.lang.Object convert(java.lang.String value, java.lang.Class clazz)
value
- Value to be converted (may be null)clazz
- Java class to be converted to
ConversionException
- if thrown by an underlying Converterpublic static java.lang.Object convert(java.lang.String[] values, java.lang.Class clazz)
clazz
- Java array or element class to be converted to
ConversionException
- if thrown by an underlying Converterpublic static void deregister()
Converter
s, and re-establish the
standard Converters.
public static void deregister(java.lang.Class clazz)
Converter
for the specified destination
Class
.
clazz
- Class for which to remove a registered Converterpublic static Converter lookup(java.lang.Class clazz)
Converter
for the specified
destination class; if there is no registered Converter, return
null
.
clazz
- Class for which to return a registered Converterpublic static void register(Converter converter, java.lang.Class clazz)
Converter
for the specified destination
Class
, replacing any previously registered Converter.
converter
- Converter to be registeredclazz
- Destination class for conversions performed by this
Converter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |