public class DefaultTypeConverterFactory extends java.lang.Object implements TypeConverterFactory
| Constructor and Description |
|---|
DefaultTypeConverterFactory() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Class<?> targetType,
java.lang.Class<? extends TypeConverter<?>> converterClass)
Adds a TypeConverter to the set of registered TypeConverters, overriding an existing
converter if one was registered for the type.
|
protected java.lang.Class<? extends TypeConverter<?>> |
cacheTypeConverterClass(java.lang.Class<?> clazz,
java.lang.Class<? extends TypeConverter<?>> converterClass)
Add converter class
converterClass for converting objects of type clazz. |
protected void |
clearCache()
Clear the instance cache.
|
protected java.lang.Class<? extends TypeConverter<?>> |
findTypeConverterClass(java.lang.Class<?> targetClass)
Search for a type converter class that best matches the requested class.
|
protected Configuration |
getConfiguration()
Provides subclasses with access to the configuration provided at initialization.
|
TypeConverter |
getInstance(java.lang.Class<? extends TypeConverter> clazz,
java.util.Locale locale)
Gets an instance of the TypeConverter class specified.
|
TypeConverter |
getTypeConverter(java.lang.Class forType,
java.util.Locale locale)
Gets the applicable type converter for the class passed in.
|
protected java.util.Map<java.lang.Class<?>,java.lang.Class<? extends TypeConverter<?>>> |
getTypeConverters()
Gets the (rather confusing) Map of TypeConverter objects.
|
void |
init(Configuration configuration)
Places all the known convertible types and type converters into an instance level Map.
|
public void init(Configuration configuration)
init in interface ConfigurableComponentconfiguration - the Configuration object being used by Stripesprotected Configuration getConfiguration()
protected java.util.Map<java.lang.Class<?>,java.lang.Class<? extends TypeConverter<?>>> getTypeConverters()
public void add(java.lang.Class<?> targetType,
java.lang.Class<? extends TypeConverter<?>> converterClass)
add in interface TypeConverterFactorytargetType - the type for which the converter will handle conversionsconverterClass - the implementation class that will handle the conversionspublic TypeConverter getTypeConverter(java.lang.Class forType, java.util.Locale locale) throws java.lang.Exception
getTypeConverter in interface TypeConverterFactoryforType - the type/Class that is the target type of the conversion. It is assumed that
the input type is String, so to convert a String to a Date object you would supply
java.util.Date.class.locale - the locale of the Strings to be converted with the returned converterjava.lang.Exception - if the TypeConverter cannot be instantiatedprotected java.lang.Class<? extends TypeConverter<?>> findTypeConverterClass(java.lang.Class<?> targetClass)
targetClass - the class of the object that needs to be convertedprotected java.lang.Class<? extends TypeConverter<?>> cacheTypeConverterClass(java.lang.Class<?> clazz, java.lang.Class<? extends TypeConverter<?>> converterClass)
converterClass for converting objects of type clazz.clazz - the type of object being convertedconverterClass - the class of the convertertargetType parameterprotected void clearCache()
add(Class, Class).public TypeConverter getInstance(java.lang.Class<? extends TypeConverter> clazz, java.util.Locale locale) throws java.lang.Exception
getInstance in interface TypeConverterFactoryclazz - the TypeConverter type that is desiredlocale - the locale of the Strings to be converted with the returned converterjava.lang.Exception - if there is a problem instantiating the TypeConverter? Copyright 2005-2006, Stripes Development Team.