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, aConversionException
is 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.String
arrayToString(java.lang.Object[] pArray, java.lang.String pFormat)
private java.lang.Object
toArray(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)
java.lang.Object
toObject(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.String
toString(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 ConversionException
Converts the string to an object of the given type.- Specified by:
toObject
in 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 staticvalueOf
method.
-
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 ConversionException
Converts the object to a string, usingpObject.toString()
.- Specified by:
toString
in interfacePropertyConverter
- Parameters:
pObject
- the object to convert.pFormat
- ignored.- Returns:
- the string representation of the object, or
null
ifpObject == 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)
-
-