Class Converter
java.lang.Object
com.twelvemonkeys.util.convert.Converter
- All Implemented Interfaces:
PropertyConverter
- Direct Known Subclasses:
ConverterImpl
The converter (singleton). Converts strings to objects and back.
This is the entry point to the converter framework.
By default, converters for Time, Date
and Object
(the DefaultConverter) are registered by this class' static
initializer. You might remove them using the
unregisterConverter method.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/Converter.java#1 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Class, PropertyConverter> The converters Mapprotected static final ConverterOur singleton instance -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConverterGets the Converter instance.static voidregisterConverter(Class<?> pType, PropertyConverter pConverter) Registers a converter for a given type.Converts the string to an object of the given type.abstract ObjectConverts the string to an object of the given type, parsing after the given format.Converts the object to a string, usingobject.toString()abstract StringConverts the object to a string, usingobject.toString()static voidunregisterConverter(Class<?> pType) Un-registers a converter for a given type.
-
Field Details
-
sInstance
Our singleton instance -
converters
The converters Map
-
-
Constructor Details
-
Converter
protected Converter()Creates a Converter.
-
-
Method Details
-
getInstance
-
registerConverter
Registers a converter for a given type. This converter will also be used for all subclasses, unless a more specific version is registered.By default, converters for
Time,DateandObject(theDefaultConverter) are registered by this class' static initializer. You might remove them using theunregisterConvertermethod.- Parameters:
pType- the (super) type to register a converter forpConverter- the converter- See Also:
-
unregisterConverter
Un-registers a converter for a given type. That is, making it unavailable for the converter framework, and making it (potentially) available for garbage collection.- Parameters:
pType- the (super) type to remove converter for- See Also:
-
toObject
Converts the string to an object of the given type.- Parameters:
pString- the string to convertpType- the type to convert to- Returns:
- the object created from the given string.
- Throws:
ConversionException- if the string cannot be converted for any reason.
-
toObject
public abstract Object toObject(String pString, Class pType, String pFormat) throws ConversionException Converts the string to an object of the given type, parsing after the given format.- Specified by:
toObjectin interfacePropertyConverter- Parameters:
pString- the string to convertpType- the type to convert topFormat- the (optional) conversion format- Returns:
- the object created from the given string.
- Throws:
ConversionException- if the string cannot be converted for any reason.
-
toString
Converts the object to a string, usingobject.toString()- Parameters:
pObject- the object to convert.- Returns:
- the string representation of the object, on the correct format.
- Throws:
ConversionException- if the object cannot be converted to a string for any reason.
-
toString
Converts the object to a string, usingobject.toString()- Specified by:
toStringin interfacePropertyConverter- Parameters:
pObject- the object to convert.pFormat- the (optional) conversion format- Returns:
- the string representation of the object, on the correct format.
- Throws:
ConversionException- if the object cannot be converted to a string for any reason.
-