BeanIO 1.2.3

org.beanio.types
Class TypeHandlerFactory

java.lang.Object
  extended by org.beanio.types.TypeHandlerFactory

public class TypeHandlerFactory
extends Object

A factory class used to get a TypeHandler for parsing field text into field objects, and for formatting field objects into field text.

A TypeHandler is registered and retrieved by class, type alias, or name. In most cases, registering a type handler by type alias has the same effect as registering the type handler using the target class associated with the alias. There are two exceptions: type handlers can be specifically registered for 'Date' and 'Time' type aliases without overriding the default Date type handler, which is registered for the class java.util.Date and type alias 'DateTime'.

If a registered type handler implements the ConfigurableTypeHandler interface, handler properties can be overridden using a Properties object. When the type handler is retrieved, the factory calls ConfigurableTypeHandler.newInstance(Properties) to allow the type handler to return a customized version of itself.

By default, a TypeHandlerFactory holds a reference to a parent factory. If a factory cannot find a type handler, its parent will be checked recursively until there is no parent left to check.

Since:
1.0
Author:
Kevin Seim
See Also:
TypeHandler, ConfigurableTypeHandler

Constructor Summary
TypeHandlerFactory()
          Constructs a new TypeHandlerFactory using the default type handler factory for its parent.
TypeHandlerFactory(TypeHandlerFactory parent)
          Constructs a new TypeHandlerFactory.
 
Method Summary
static TypeHandlerFactory getDefault()
          Returns the default TypeHandlerFactory.
 TypeHandler getTypeHandler(String name)
          Returns a named type handler, or null if there is no type handler configured for the given name in this factory or any of its ancestors.
 TypeHandler getTypeHandler(String name, Properties properties)
          Returns a named type handler, or null if there is no type handler configured for the given name in this factory or any of its ancestors.
 TypeHandler getTypeHandlerFor(Class<?> clazz)
          Returns a type handler for a class, or null if there is no type handler configured for the class in this factory or any of its ancestors
 TypeHandler getTypeHandlerFor(Class<?> clazz, Properties properties)
          Returns a type handler for a class, or null if there is no type handler configured for the class in this factory or any of its ancestors
 TypeHandler getTypeHandlerFor(String type)
          Returns the type handler for the given type, or null if there is no type handler configured for the type in this factory or any of its ancestors.
 TypeHandler getTypeHandlerFor(String type, Properties properties)
          Returns the type handler for the given type, or null if there is no type handler configured for the type in this factory or any of its ancestors.
 void registerHandler(String name, TypeHandler handler)
          Registers a type handler in this factory.
 void registerHandlerFor(Class<?> clazz, TypeHandler handler)
          Registers a type handler in this factory.
 void registerHandlerFor(String type, TypeHandler handler)
          Registers a type handler in this factory.
 void setParent(TypeHandlerFactory parent)
          Sets the parent TypeHandlerFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeHandlerFactory

public TypeHandlerFactory()
Constructs a new TypeHandlerFactory using the default type handler factory for its parent.


TypeHandlerFactory

public TypeHandlerFactory(TypeHandlerFactory parent)
Constructs a new TypeHandlerFactory.

Parameters:
parent - the parent TypeHandlerFactory
Method Detail

getTypeHandler

public TypeHandler getTypeHandler(String name)
Returns a named type handler, or null if there is no type handler configured for the given name in this factory or any of its ancestors.

Parameters:
name - the name of type handler was registered under
Returns:
the type handler, or null if there is no configured type handler registered for the name

getTypeHandler

public TypeHandler getTypeHandler(String name,
                                  Properties properties)
                           throws IllegalArgumentException
Returns a named type handler, or null if there is no type handler configured for the given name in this factory or any of its ancestors.

Parameters:
name - the name the type handler was registered under
properties - the custom properties for configuring the type handler
Returns:
the type handler, or null if there is no configured type handler registered for the name
Throws:
IllegalArgumentException - if a custom property value was invalid

getTypeHandlerFor

public TypeHandler getTypeHandlerFor(String type)
Returns the type handler for the given type, or null if there is no type handler configured for the type in this factory or any of its ancestors.

Parameters:
type - the class name or type alias
Returns:
the type handler, or null if there is no configured type handler registered for the type

getTypeHandlerFor

public TypeHandler getTypeHandlerFor(String type,
                                     Properties properties)
                              throws IllegalArgumentException
Returns the type handler for the given type, or null if there is no type handler configured for the type in this factory or any of its ancestors.

Parameters:
type - the property type
properties - the custom properties for configuring the type handler
Returns:
the type handler, or null if there is no configured type handler registered for the type
Throws:
IllegalArgumentException - if a custom property value was invalid

getTypeHandlerFor

public TypeHandler getTypeHandlerFor(Class<?> clazz)
Returns a type handler for a class, or null if there is no type handler configured for the class in this factory or any of its ancestors

Parameters:
clazz - the target class to find a type handler for
Returns:
the type handler, or null if the class is not supported

getTypeHandlerFor

public TypeHandler getTypeHandlerFor(Class<?> clazz,
                                     Properties properties)
                              throws IllegalArgumentException
Returns a type handler for a class, or null if there is no type handler configured for the class in this factory or any of its ancestors

Parameters:
clazz - the target class to find a type handler for
properties - the custom properties for configuring the type handler
Returns:
the type handler, or null if the class is not supported
Throws:
IllegalArgumentException - if a custom property value was invalid

registerHandler

public void registerHandler(String name,
                            TypeHandler handler)
Registers a type handler in this factory.

Parameters:
name - the name to register the type handler under
handler - the type handler to register

registerHandlerFor

public void registerHandlerFor(String type,
                               TypeHandler handler)
                        throws IllegalArgumentException
Registers a type handler in this factory.

Parameters:
type - the fully qualified class name or type alias to register the type handler for
handler - the type handler to registere
Throws:
IllegalArgumentException - if the type name is invalid or if the handler type is not assignable from the type

registerHandlerFor

public void registerHandlerFor(Class<?> clazz,
                               TypeHandler handler)
                        throws IllegalArgumentException
Registers a type handler in this factory.

Parameters:
clazz - the target class to register the type handler for
handler - the type handler to register
Throws:
IllegalArgumentException - if the handler type is not assignable from the registered class type

setParent

public void setParent(TypeHandlerFactory parent)
Sets the parent TypeHandlerFactory.

Parameters:
parent - the parent TypeHandlerFactory
Since:
1.1

getDefault

public static TypeHandlerFactory getDefault()
Returns the default TypeHandlerFactory.

Returns:
the default TypeHandlerFactory

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim