org.apache.commons.beanutils

Class ConvertUtils

public class ConvertUtils extends Object

Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class.

For more details, see ConvertUtilsBean which provides the implementations for these methods.

Version: $Revision: 556229 $ $Date: 2007-07-14 07:11:19 +0100 (Sat, 14 Jul 2007) $

Author: Craig R. McClanahan Ralph Schaer Chris Audley

See Also: ConvertUtilsBean

Method Summary
static Stringconvert(Object value)

Convert the specified value into a String.

For more details see ConvertUtilsBean.

static Objectconvert(String value, Class clazz)

Convert the specified value to an object of the specified class (if possible).

static Objectconvert(String[] values, Class clazz)

Convert an array of specified values to an array of objects of the specified class (if possible).

For more details see ConvertUtilsBean.

static Objectconvert(Object value, Class targetType)

Convert the value to an object of the specified class (if possible).

static voidderegister()

Remove all registered Converters, and re-establish the standard Converters.

For more details see ConvertUtilsBean.

static voidderegister(Class clazz)

Remove any registered Converter for the specified destination Class.

For more details see ConvertUtilsBean.

static booleangetDefaultBoolean()
Gets the default value for Boolean conversions.
static bytegetDefaultByte()
Gets the default value for Byte conversions.
static chargetDefaultCharacter()
Gets the default value for Character conversions.
static doublegetDefaultDouble()
Gets the default value for Double conversions.
static floatgetDefaultFloat()
Get the default value for Float conversions.
static intgetDefaultInteger()
Gets the default value for Integer conversions.
static longgetDefaultLong()
Gets the default value for Long conversions.
static shortgetDefaultShort()
Gets the default value for Short conversions.
static Converterlookup(Class clazz)

Look up and return any registered Converter for the specified destination class; if there is no registered Converter, return null.

For more details see ConvertUtilsBean.

static Converterlookup(Class sourceType, Class targetType)
Look up and return any registered Converter for the specified source and destination class; if there is no registered Converter, return null.
static voidregister(Converter converter, Class clazz)

Register a custom Converter for the specified destination Class, replacing any previously registered Converter.

For more details see ConvertUtilsBean.

static voidsetDefaultBoolean(boolean newDefaultBoolean)
Sets the default value for Boolean conversions.
static voidsetDefaultByte(byte newDefaultByte)
Sets the default value for Byte conversions.
static voidsetDefaultCharacter(char newDefaultCharacter)
Sets the default value for Character conversions.
static voidsetDefaultDouble(double newDefaultDouble)
Sets the default value for Double conversions.
static voidsetDefaultFloat(float newDefaultFloat)
Sets the default value for Float conversions.
static voidsetDefaultInteger(int newDefaultInteger)
Sets the default value for Integer conversions.
static voidsetDefaultLong(long newDefaultLong)
Sets the default value for Long conversions.
static voidsetDefaultShort(short newDefaultShort)
Sets the default value for Short conversions.

Method Detail

convert

public static String convert(Object value)

Convert the specified value into a String.

For more details see ConvertUtilsBean.

Parameters: value Value to be converted (may be null)

Returns: The converted String value

See Also: convert

convert

public static 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.

For more details see ConvertUtilsBean.

Parameters: value Value to be converted (may be null) clazz Java class to be converted to

Returns: The converted value

See Also: ConvertUtilsBean

convert

public static Object convert(String[] values, Class clazz)

Convert an array of specified values to an array of objects of the specified class (if possible).

For more details see ConvertUtilsBean.

Parameters: values Array of values to be converted clazz Java array or element class to be converted to

Returns: The converted value

See Also: (String[], Class)

convert

public static Object convert(Object value, Class targetType)

Convert the value to an object of the specified class (if possible).

Parameters: value Value to be converted (may be null) targetType Class of the value to be converted to

Returns: The converted value

Throws: ConversionException if thrown by an underlying Converter

deregister

public static void deregister()

Remove all registered Converters, and re-establish the standard Converters.

For more details see ConvertUtilsBean.

See Also: deregister

deregister

public static void deregister(Class clazz)

Remove any registered Converter for the specified destination Class.

For more details see ConvertUtilsBean.

Parameters: clazz Class for which to remove a registered Converter

See Also: deregister

getDefaultBoolean

public static boolean getDefaultBoolean()

Deprecated: Register replacement converters for Boolean.TYPE and Boolean.class instead

Gets the default value for Boolean conversions.

Returns: The default Boolean value

getDefaultByte

public static byte getDefaultByte()

Deprecated: Register replacement converters for Byte.TYPE and Byte.class instead

Gets the default value for Byte conversions.

Returns: The default Byte value

getDefaultCharacter

public static char getDefaultCharacter()

Deprecated: Register replacement converters for Character.TYPE and Character.class instead

Gets the default value for Character conversions.

Returns: The default Character value

getDefaultDouble

public static double getDefaultDouble()

Deprecated: Register replacement converters for Double.TYPE and Double.class instead

Gets the default value for Double conversions.

Returns: The default Double value

getDefaultFloat

public static float getDefaultFloat()

Deprecated: Register replacement converters for Float.TYPE and Float.class instead

Get the default value for Float conversions.

Returns: The default Float value

getDefaultInteger

public static int getDefaultInteger()

Deprecated: Register replacement converters for Integer.TYPE and Integer.class instead

Gets the default value for Integer conversions.

Returns: The default Integer value

getDefaultLong

public static long getDefaultLong()

Deprecated: Register replacement converters for Long.TYPE and Long.class instead

Gets the default value for Long conversions.

Returns: The default Long value

getDefaultShort

public static short getDefaultShort()

Deprecated: Register replacement converters for Short.TYPE and Short.class instead

Gets the default value for Short conversions.

Returns: The default Short value

lookup

public static Converter lookup(Class clazz)

Look up and return any registered Converter for the specified destination class; if there is no registered Converter, return null.

For more details see ConvertUtilsBean.

Parameters: clazz Class for which to return a registered Converter

Returns: The registered Converter or null if not found

See Also: lookup

lookup

public static Converter lookup(Class sourceType, Class targetType)
Look up and return any registered Converter for the specified source and destination class; if there is no registered Converter, return null.

Parameters: sourceType Class of the value being converted targetType Class of the value to be converted to

Returns: The registered Converter or null if not found

register

public static void register(Converter converter, Class clazz)

Register a custom Converter for the specified destination Class, replacing any previously registered Converter.

For more details see ConvertUtilsBean.

Parameters: converter Converter to be registered clazz Destination class for conversions performed by this Converter

See Also: ConvertUtilsBean

setDefaultBoolean

public static void setDefaultBoolean(boolean newDefaultBoolean)

Deprecated: Register replacement converters for Boolean.TYPE and Boolean.class instead

Sets the default value for Boolean conversions.

Parameters: newDefaultBoolean The default Boolean value

setDefaultByte

public static void setDefaultByte(byte newDefaultByte)

Deprecated: Register replacement converters for Byte.TYPE and Byte.class instead

Sets the default value for Byte conversions.

Parameters: newDefaultByte The default Byte value

setDefaultCharacter

public static void setDefaultCharacter(char newDefaultCharacter)

Deprecated: Register replacement converters for Character.TYPE and Character.class instead

Sets the default value for Character conversions.

Parameters: newDefaultCharacter The default Character value

setDefaultDouble

public static void setDefaultDouble(double newDefaultDouble)

Deprecated: Register replacement converters for Double.TYPE and Double.class instead

Sets the default value for Double conversions.

Parameters: newDefaultDouble The default Double value

setDefaultFloat

public static void setDefaultFloat(float newDefaultFloat)

Deprecated: Register replacement converters for Float.TYPE and Float.class instead

Sets the default value for Float conversions.

Parameters: newDefaultFloat The default Float value

setDefaultInteger

public static void setDefaultInteger(int newDefaultInteger)

Deprecated: Register replacement converters for Integer.TYPE and Integer.class instead

Sets the default value for Integer conversions.

Parameters: newDefaultInteger The default Integer value

setDefaultLong

public static void setDefaultLong(long newDefaultLong)

Deprecated: Register replacement converters for Long.TYPE and Long.class instead

Sets the default value for Long conversions.

Parameters: newDefaultLong The default Long value

setDefaultShort

public static void setDefaultShort(short newDefaultShort)

Deprecated: Register replacement converters for Short.TYPE and Short.class instead

Sets the default value for Short conversions.

Parameters: newDefaultShort The default Short value

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.