Joda System API

org.joda.typeconvertor
Class TypeConvertorManager

java.lang.Object
  |
  +--org.joda.typeconvertor.TypeConvertorManager
Direct Known Subclasses:
DefaultTypeConvertorManager

public abstract class TypeConvertorManager
extends java.lang.Object

TypeConvertorManager controls all the object to object type convertors. To use,

Author:
Stephen Colebourne

Constructor Summary
TypeConvertorManager()
           
 
Method Summary
abstract  void addTypeConvertor(TypeConvertor convertor)
          Add a type convertor used to convert an object from one type to another.
abstract  void addTypeConvertorFactory(TypeConvertor.ConvertorFactory typeConvertorFactory)
          Add a type convertor factory used to create type convertors.
abstract  java.lang.Object convertFromObject(java.lang.Class convertTo, java.lang.Object object, java.lang.Object errSource)
          Convert an object from one type to another.
abstract  java.lang.String convertToString(java.lang.Class convertFrom, java.lang.Object object, java.lang.Object errSource)
          Convert an object to a formal string.
static TypeConvertorManager getInstance()
          Gets the TypeConvertorManager singleton instance.
abstract  TypeConvertor getTypeConvertor(java.lang.Class type)
          Get a type convertor used to convert an object from one type to another
static void setInstance(TypeConvertorManager manager)
          Sets the TypeConvertorManager singleton instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeConvertorManager

public TypeConvertorManager()
Method Detail

getInstance

public static TypeConvertorManager getInstance()
Gets the TypeConvertorManager singleton instance.

Returns:
the PropertyFactory to set as the default

setInstance

public static void setInstance(TypeConvertorManager manager)
Sets the TypeConvertorManager singleton instance. This method is not thread-safe, and should generally be called only once in the program initialisation code.

Parameters:
manager - the TypeConvertorManager to set as the default

getTypeConvertor

public abstract TypeConvertor getTypeConvertor(java.lang.Class type)
Get a type convertor used to convert an object from one type to another

Parameters:
type - the type to convert to
Returns:
suitable type convertor, null if none found

convertFromObject

public abstract java.lang.Object convertFromObject(java.lang.Class convertTo,
                                                   java.lang.Object object,
                                                   java.lang.Object errSource)
Convert an object from one type to another. The returned object may be the same as the original only if the type is correct and the object is fully immutable (final and no setters). Mutable objects will be cloned/copied even if they are the correct type.

All type convertors should accept String and null as inputs. The String should be formatted as per the output of the matching convertToString.

Parameters:
object - the object to convert
errSource - the object to indicate errors belong to
Returns:
converted object

convertToString

public abstract java.lang.String convertToString(java.lang.Class convertFrom,
                                                 java.lang.Object object,
                                                 java.lang.Object errSource)
Convert an object to a formal string. A formal string should represent an object's data completely in string format.

Parameters:
convertFrom - the type to convert from
object - the object to convert
errSource - the object to indicate errors belong to
Returns:
converted object

addTypeConvertor

public abstract void addTypeConvertor(TypeConvertor convertor)
Add a type convertor used to convert an object from one type to another. Replaces any previous one of the same type.

Parameters:
convertor - the convertor

addTypeConvertorFactory

public abstract void addTypeConvertorFactory(TypeConvertor.ConvertorFactory typeConvertorFactory)
Add a type convertor factory used to create type convertors. Replaces any previous one of the same type.

This method allows for type convertors which can handle a number of related classes. One example is the enumeration pattern, where an application may have many enumeration classes each needing similar but slightly different conversion.

The type convertor will be created on demand by calling the create method on the factory.

Parameters:
typeConvertorFactory - the convertor factory

Joda System API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.