net.sourceforge.stripes.validation
Class DefaultTypeConverterFactory

java.lang.Object
  extended by net.sourceforge.stripes.validation.DefaultTypeConverterFactory
All Implemented Interfaces:
ConfigurableComponent, TypeConverterFactory

public class DefaultTypeConverterFactory
extends Object
implements TypeConverterFactory

Default TypeConverterFactory implementation that simply creates an instance level map of all the TypeConverters included in the Stripes distribution, and their applicable classes. Can handle all the primitive and wrapper types as well as the rich types for which type converters exist.

Author:
Tim Fennell

Field Summary
protected  Configuration configuration
          Stores a reference to the Configuration passed in at initialization time.
 
Constructor Summary
DefaultTypeConverterFactory()
           
 
Method Summary
 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.
 void init(Configuration configuration)
          Places all the known convertible types and type converters into an instance level Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected Configuration configuration
Stores a reference to the Configuration passed in at initialization time.

Constructor Detail

DefaultTypeConverterFactory

public DefaultTypeConverterFactory()
Method Detail

init

public void init(Configuration configuration)
Places all the known convertible types and type converters into an instance level Map.

Specified by:
init in interface ConfigurableComponent
Parameters:
configuration - the Configuration object being used by Stripes

getTypeConverter

public TypeConverter getTypeConverter(Class forType,
                                      Locale locale)
                               throws Exception
Gets the applicable type converter for the class passed in. This is based on the default set of type converters which are stored in a Map on this class. Enums are a special case, whereby if there is no converter in the map, the EnumeratedTypeConverter will be returned.

Specified by:
getTypeConverter in interface TypeConverterFactory
Parameters:
forType - 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 converter
Returns:
an instance of a TypeConverter which will convert Strings to the desired type
Throws:
Exception - if the TypeConverter cannot be instantiated

getInstance

public TypeConverter getInstance(Class<? extends TypeConverter> clazz,
                                 Locale locale)
                          throws Exception
Gets an instance of the TypeConverter class specified.

Specified by:
getInstance in interface TypeConverterFactory
Parameters:
clazz - the TypeConverter type that is desired
locale - the locale of the Strings to be converted with the returned converter
Returns:
an instance of the TypeConverter specified
Throws:
Exception - if there is a problem instantiating the TypeConverter


© Copyright 2005, Stripes Development Team.