org.jbeans
Class TypeConverterManager
java.lang.Object
|
+--org.jbeans.TypeConverterManager
- public class TypeConverterManager
- extends Object
This class is the manager for all the TypeConverters. It uses a Hashtable
to store the converters and therefore is thread safe. A converter for a given
type will be retrieved when the manager is queried for that type and all sub
class of that type, unless another converter is registered for a sub class of
the type. For example, registering a convert for the type Number would ensure
that Integer, Double, Float, etc. used that converter for conversions. If a
converter was registered for Number and another converter for Double, the the
converter for Number would handle all sub-class of Number (Integer, etc.)
except Double.
- Author:
- bpontarelli
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
getTypeConverter
public static TypeConverter getTypeConverter(Class type)
- Returns the type converter for the given type. This converter is either
the converter associated with the given type of associated with a super
class of the given type (not interfaces). This principal also works with
arrays. If the type is an array, then what happens is that the array type
is asked for its component type using the method getComponentType and this
type is used to query the manager. So, the converter registered for Number
is returned Double[] is queried (because Double is queried and since no
converter was register for it, then Number is checked).
Normal types work the exact same way. First the type is checked and then
its parents are checked until Object is reached, in which case null is
returned.
Primitive values are treated as their wrapper classes. So, if int.class
is passed into this method (queried) then either a converter registered
for Integer, or Number or null is returned depending on what converters
have been registered so far.
- Parameters:
type
- The type to start with when looking for converters- Returns:
- The converter or null if one was not found
registerTypeConverter
public static TypeConverter registerTypeConverter(Class type,
TypeConverter converter)
- Registers the given converter with the given type
- Parameters:
type
- The type to register the converter forconverter
- The convert to register with the given type- Returns:
- The converter that was already registered with the given type
or null if this is the first converter being registered for
that type
unregisterTypeConverter
public static TypeConverter unregisterTypeConverter(Class type)
- Unregisters the given converter with the given type
- Parameters:
type
- The type to unregister the converter- Returns:
- The converter that was registered with the given type or null
if no converter was registered for the given type