net.sourceforge.stripes.validation
Interface TypeConverterFactory

All Superinterfaces:
ConfigurableComponent
All Known Implementing Classes:
DefaultTypeConverterFactory

public interface TypeConverterFactory
extends ConfigurableComponent

Provides access to a set of TypeConverters for converting Strings to various types. Implementations may use any mechanism desired to map a type to a TypeConverter, and may optionally choose to cache TypeConverter instances. The behaviour of the type conversion lookups in Stripes can be altered either by directly implementing this interface, or by subclassing DefaultTypeConverterFactory.

Author:
Tim Fennell

Method Summary
 void add(Class<?> targetType, Class<? extends TypeConverter<?>> converterClass)
          Adds a type converter to the set of registered type converters, overriding an existing converter if one was already registered for the type.
 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.
 
Methods inherited from interface net.sourceforge.stripes.config.ConfigurableComponent
init
 

Method Detail

getTypeConverter

TypeConverter getTypeConverter(Class forType,
                               Locale locale)
                               throws Exception
Gets the applicable type converter for the class passed in. The TypeConverter returned must create objects of the type supplied, or possibly a suitable derived type.

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

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

Parameters:
clazz - the Class object representing the desired TypeConverter
locale - the locale of the Strings to be converted with the returned converter
Returns:
an instance of the TypeConverter specified
Throws:
Exception - if the TypeConverter cannot be instantiated

add

void add(Class<?> targetType,
         Class<? extends TypeConverter<?>> converterClass)
Adds a type converter to the set of registered type converters, overriding an existing converter if one was already registered for the type. This is an optional operation. Implementations that do not support adding type converters at runtime must throw UnsupportedOperationException.

Parameters:
targetType - the type for which the converter will handle conversions
converterClass - the implementation class that will handle the conversions
Throws:
UnsupportedOperationException - if the implementation does not support adding type converters at runtime


? Copyright 2005-2006, Stripes Development Team.