public class DefaultTypeConverterFactory extends Object implements TypeConverterFactory
| Constructor and Description |
|---|
DefaultTypeConverterFactory() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Class<?> targetType,
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 Class<? extends TypeConverter<?>> |
cacheTypeConverterClass(Class<?> clazz,
Class<? extends TypeConverter<?>> converterClass)
Add converter class
converterClass for converting objects of type clazz. |
protected void |
clearCache()
Clear the instance cache.
|
protected Class<? extends TypeConverter<?>> |
findTypeConverterClass(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(Class<? extends TypeConverter> clazz,
Locale locale)
Gets an instance of the TypeConverter class specified.
|
TypeConverter |
getTypeConverter(Class forType,
Locale locale)
Gets the applicable type converter for the class passed in.
|
protected Map<Class<?>,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 Map<Class<?>,Class<? extends TypeConverter<?>>> getTypeConverters()
public void add(Class<?> targetType, 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(Class forType, Locale locale) throws 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 converterException - if the TypeConverter cannot be instantiatedprotected Class<? extends TypeConverter<?>> findTypeConverterClass(Class<?> targetClass)
targetClass - the class of the object that needs to be convertedprotected Class<? extends TypeConverter<?>> cacheTypeConverterClass(Class<?> clazz, 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(Class<? extends TypeConverter> clazz, Locale locale) throws Exception
getInstance in interface TypeConverterFactoryclazz - the TypeConverter type that is desiredlocale - the locale of the Strings to be converted with the returned converterException - if there is a problem instantiating the TypeConverter© Copyright 2005-2006, Stripes Development Team.