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 $
- Author:
- Harald Kuhr, last modified by $Author: haku $
-
-
Constructor Summary
Constructors Constructor Description DefaultConverter()
Creates aDefaultConverter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.java.lang.String
toString(java.lang.Object pObject, java.lang.String pFormat)
Converts the object to a string, usingpObject.toString()
.
-
-
-
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.
-
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.
-
-