Package com.twelvemonkeys.util.convert
Class DefaultConverter
- java.lang.Object
-
- com.twelvemonkeys.util.convert.DefaultConverter
-
- All Implemented Interfaces:
PropertyConverter
public final class DefaultConverter extends java.lang.Object implements PropertyConverter
Converts strings to objects and back.This converter first tries to create an object, using the class' single string argument constructor (
<type>(String)) if found, otherwise, an attempt to call the class' staticvalueOf(String)method. If both fails, aConversionExceptionis thrown.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/DefaultConverter.java#2 $
-
-
Constructor Summary
Constructors Constructor Description DefaultConverter()Creates aDefaultConverter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringarrayToString(java.lang.Object[] pArray, java.lang.String pFormat)private java.lang.ObjecttoArray(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)java.lang.ObjecttoObject(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)Converts the string to an object of the given type.private java.lang.Object[]toObjectArray(java.lang.Object pObject)java.lang.StringtoString(java.lang.Object pObject, java.lang.String pFormat)Converts the object to a string, usingpObject.toString().private java.lang.Class<?>unBoxType(java.lang.Class<?> pType)
-
-
-
Method Detail
-
toObject
public java.lang.Object toObject(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat) throws ConversionExceptionConverts the string to an object of the given type.- Specified by:
toObjectin interfacePropertyConverter- Parameters:
pString- the string to convertpType- the type to convert topFormat- ignored.- Returns:
- the object created from the given string.
- Throws:
ConversionException- if the type is null, or if the string cannot be converted into the given type, using a string constructor or staticvalueOfmethod.
-
toArray
private java.lang.Object toArray(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)
-
toString
public java.lang.String toString(java.lang.Object pObject, java.lang.String pFormat) throws ConversionExceptionConverts the object to a string, usingpObject.toString().- Specified by:
toStringin interfacePropertyConverter- Parameters:
pObject- the object to convert.pFormat- ignored.- Returns:
- the string representation of the object, or
nullifpObject == null - Throws:
ConversionException- if the string could not be converted to the specified type and format.
-
arrayToString
private java.lang.String arrayToString(java.lang.Object[] pArray, java.lang.String pFormat)
-
toObjectArray
private java.lang.Object[] toObjectArray(java.lang.Object pObject)
-
unBoxType
private java.lang.Class<?> unBoxType(java.lang.Class<?> pType)
-
-