public class TypeHandlerFactory extends Object
A TypeHandler is registered and retrieved by class, type alias, or name. If a stream format is specified when registering a type handler by class or type alias, the type handler will only be returned when the same format is queried for. 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.
TypeHandler
,
ConfigurableTypeHandler
Constructor and Description |
---|
TypeHandlerFactory()
Constructs a new TypeHandlerFactory using the default type handler factory
for its parent and the same
ClassLoader that loaded this class. |
TypeHandlerFactory(ClassLoader classLoader)
Constructs a new TypeHandlerFactory using the default type handler factory
for its parent.
|
TypeHandlerFactory(ClassLoader classLoader,
TypeHandlerFactory parent)
Constructs a new TypeHandlerFactory.
|
Modifier and Type | Method and Description |
---|---|
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,
String format,
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,
String format)
Returns the type handler for the given type and format, or null if there is no type
handler configured for the type in this factory or any of its ancestors.
|
TypeHandler |
getTypeHandlerFor(String type,
String format,
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 for any stream format.
|
void |
registerHandlerFor(Class<?> clazz,
TypeHandler handler,
String format)
Registers a type handler in this factory for a specific stream format.
|
void |
registerHandlerFor(String type,
TypeHandler handler)
Registers a type handler in this factory by class type for all stream formats
|
void |
registerHandlerFor(String type,
TypeHandler handler,
String format)
Registers a type handler in this factory by class type for a specific stream format.
|
public TypeHandlerFactory()
ClassLoader
that loaded this class.public TypeHandlerFactory(ClassLoader classLoader)
classLoader
- the ClassLoader
for resolving unrecognized typespublic TypeHandlerFactory(ClassLoader classLoader, TypeHandlerFactory parent)
classLoader
- the ClassLoader
for resolving unrecognized typesparent
- the parent TypeHandlerFactorypublic TypeHandler getTypeHandler(String name)
name
- the name of type handler was registered underpublic TypeHandler getTypeHandler(String name, Properties properties) throws IllegalArgumentException
name
- the name the type handler was registered underproperties
- the custom properties for configuring the type handlerIllegalArgumentException
- if a custom property value was invalidpublic TypeHandler getTypeHandlerFor(String type)
type
- the class name or type aliaspublic TypeHandler getTypeHandlerFor(String type, String format)
type
- the class name or type aliasformat
- the stream format, or if null, format specific handlers will not be returnedpublic TypeHandler getTypeHandlerFor(String type, String format, Properties properties) throws IllegalArgumentException
type
- the property typeformat
- the stream format, or if null, format specific handlers will not be returnedproperties
- the custom properties for configuring the type handlerIllegalArgumentException
- if a custom property value was invalidpublic TypeHandler getTypeHandlerFor(Class<?> clazz)
clazz
- the target class to find a type handler forpublic TypeHandler getTypeHandlerFor(Class<?> clazz, String format, Properties properties) throws IllegalArgumentException
clazz
- the target class to find a type handler forformat
- the stream format, or if null, format specific handlers will not be returnedproperties
- the custom properties for configuring the type handlerIllegalArgumentException
- if a custom property value was invalidpublic void registerHandler(String name, TypeHandler handler)
name
- the name to register the type handler underhandler
- the type handler to registerpublic void registerHandlerFor(String type, TypeHandler handler) throws IllegalArgumentException
type
- the fully qualified class name or type alias to register the type handler forhandler
- the type handler to registerIllegalArgumentException
- if the type name is invalid or if the handler type is not
assignable from the typepublic void registerHandlerFor(String type, TypeHandler handler, String format) throws IllegalArgumentException
type
- the fully qualified class name or type alias to register the type handler forhandler
- the type handler to registerformat
- the stream format to register the type handler for, or if null the type handler
may be returned for any formatIllegalArgumentException
- if the type name is invalid or if the handler type is not
assignable from the typepublic void registerHandlerFor(Class<?> clazz, TypeHandler handler) throws IllegalArgumentException
clazz
- the target class to register the type handler forhandler
- the type handler to registerIllegalArgumentException
- if the handler type is not assignable from
the registered class typepublic void registerHandlerFor(Class<?> clazz, TypeHandler handler, String format) throws IllegalArgumentException
clazz
- the target class to register the type handler forhandler
- the type handler to registerformat
- the stream format to register the type handler for, or if null the type handler
may be returned for any formatIllegalArgumentException
- if the handler type is not assignable from
the registered class typepublic static TypeHandlerFactory getDefault()