Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.beanutils.ConvertUtilsBean
public class ConvertUtilsBean
extends java.lang.Object
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:
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 FastHashMap |
|
private Boolean |
|
private Byte |
|
private Character |
|
private Double |
|
private Float |
|
private Integer |
|
private Long |
|
private static Short |
|
private Log |
|
Constructor Summary | |
|
Method Summary | |
String |
|
Object |
|
Object |
|
void |
|
void |
|
boolean |
|
byte |
|
char |
|
double |
|
float |
|
int |
|
long |
|
short |
|
protected static ConvertUtilsBean |
|
Converter | |
private void | |
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
private FastHashMap converters
The set ofConverter
s that can be used to convert Strings into objects of a specified Class, keyed by the destination Class.
private Boolean defaultBoolean
Deprecated. Register replacement converters for Boolean.TYPE and Boolean.class instead
The default value for Boolean conversions.
private Byte defaultByte
Deprecated. Register replacement converters for Byte.TYPE and Byte.class instead
The default value for Byte conversions.
private Character defaultCharacter
Deprecated. Register replacement converters for Character.TYPE and Character.class instead
The default value for Character conversions.
private Double defaultDouble
Deprecated. Register replacement converters for Double.TYPE and Double.class instead
The default value for Double conversions.
private Float defaultFloat
Deprecated. Register replacement converters for Float.TYPE and Float.class instead
The default value for Float conversions.
private Integer defaultInteger
Deprecated. Register replacement converters for Integer.TYPE and Integer.class instead
The default value for Integer conversions.
private Long defaultLong
Deprecated. Register replacement converters for Long.TYPE and Long.class instead
The default value for Long conversions.
private static Short defaultShort
Deprecated. Register replacement converters for Short.TYPE and Short.class instead
The default value for Short conversions.
private Log log
TheLog
instance for this class.
public String convert(Object value)
Convert the specified value into a String. If the specified value is an array, the first element (converted to a String) will be returned. The registeredConverter
for thejava.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)
public Object convert(String value, Class clazz)
Convert the specified value to an object of the specified class (if possible). Otherwise, return a String representation of the value.
- Parameters:
value
- Value to be converted (may be null)clazz
- Java class to be converted to
public Object convert(values[] , Class clazz)
Convert an array of specified values to an array of objects of the specified class (if possible). If the specified Java class is itself an array class, this class will be the type of the returned value. Otherwise, an array will be constructed whose component type is the specified class.
- Parameters:
clazz
- Java array or element class to be converted to
public void deregister()
Remove all registeredConverter
s, and re-establish the standard Converters.
public void deregister(Class clazz)
Remove any registeredConverter
for the specified destinationClass
.
- Parameters:
clazz
- Class for which to remove a registered Converter
public boolean getDefaultBoolean()
Deprecated. Register replacement converters for Boolean.TYPE and Boolean.class instead
Gets the default value for Boolean conversions.
public byte getDefaultByte()
Deprecated. Register replacement converters for Byte.TYPE and Byte.class instead
Gets the default value for Byte conversions.
public char getDefaultCharacter()
Deprecated. Register replacement converters for Character.TYPE and Character.class instead
Gets the default value for Character conversions.
public double getDefaultDouble()
Deprecated. Register replacement converters for Double.TYPE and Double.class instead
Gets the default value for Double conversions.
public float getDefaultFloat()
Deprecated. Register replacement converters for Float.TYPE and Float.class instead
Gets the default value for Float conversions.
public int getDefaultInteger()
Deprecated. Register replacement converters for Integer.TYPE and Integer.class instead
Gets the default value for Integer conversions.
public long getDefaultLong()
Deprecated. Register replacement converters for Long.TYPE and Long.class instead
Gets the default value for Long conversions.
public short getDefaultShort()
Deprecated. Register replacement converters for Short.TYPE and Short.class instead
Gets the default value for Short conversions.
public Converter lookup(Class clazz)
Look up and return any registeredConverter
for the specified destination class; if there is no registered Converter, returnnull
.
- Parameters:
clazz
- Class for which to return a registered Converter
private void register(Class clazz, Converter converter)
strictly for convenience since it has same parameter order as Map.put
public void register(Converter converter, Class clazz)
Register a customConverter
for the specified destinationClass
, replacing any previously registered Converter.
- Parameters:
converter
- Converter to be registeredclazz
- Destination class for conversions performed by this Converter
public void setDefaultBoolean(boolean newDefaultBoolean)
Deprecated. Register replacement converters for Boolean.TYPE and Boolean.class instead
Sets the default value for Boolean conversions.
public void setDefaultByte(byte newDefaultByte)
Deprecated. Register replacement converters for Byte.TYPE and Byte.class instead
Sets the default value for Byte conversions.
public void setDefaultCharacter(char newDefaultCharacter)
Deprecated. Register replacement converters for Character.TYPE and Character.class instead
Sets the default value for Character conversions.
public void setDefaultDouble(double newDefaultDouble)
Deprecated. Register replacement converters for Double.TYPE and Double.class instead
Sets the default value for Double conversions.
public void setDefaultFloat(float newDefaultFloat)
Deprecated. Register replacement converters for Float.TYPE and Float.class instead
Sets the default value for Float conversions.
public void setDefaultInteger(int newDefaultInteger)
Deprecated. Register replacement converters for Integer.TYPE and Integer.class instead
Sets the default value for Integer conversions.
public void setDefaultLong(long newDefaultLong)
Deprecated. Register replacement converters for Long.TYPE and Long.class instead
Sets the default value for Long conversions.
public void setDefaultShort(short newDefaultShort)
Deprecated. Register replacement converters for Short.TYPE and Short.class instead
Sets the default value for Short conversions.