net.sourceforge.stripes.validation
Interface TypeConverter<T>

All Known Implementing Classes:
BigDecimalTypeConverter, BigIntegerTypeConverter, BooleanTypeConverter, ByteTypeConverter, CharacterTypeConverter, CreditCardTypeConverter, DateTypeConverter, DoubleTypeConverter, EmailTypeConverter, EnumeratedTypeConverter, FloatTypeConverter, IntegerTypeConverter, LongTypeConverter, ObjectTypeConverter, OneToManyTypeConverter, PercentageTypeConverter, ShortTypeConverter, StringTypeConverter

public interface TypeConverter<T>

Interface for all type converters in the validation system that provide facilities for converting from String to a specific object type.

Author:
Tim Fennell

Method Summary
 T convert(String input, Class<? extends T> targetType, Collection<ValidationError> errors)
          Convert a String to the target type supported by this converter.
 void setLocale(Locale locale)
          Sets the locale that the TypeConverter can expect incoming Strings to be in.
 

Method Detail

setLocale

void setLocale(Locale locale)
Sets the locale that the TypeConverter can expect incoming Strings to be in. This method will only be called once during a TypeConverter's lifetime, and will be called prior to any invocations of convert().

Parameters:
locale - the locale that the TypeConverter will be converting from.

convert

T convert(String input,
          Class<? extends T> targetType,
          Collection<ValidationError> errors)
Convert a String to the target type supported by this converter.

Parameters:
input - the String being converted
targetType - the Class representing the type of the property to which the return value of the conversion will be assigned. In many cases this can be ignored as converters will return a single type more often than not.
errors - an empty collection of validation errors that should be populated by the converter for any errors that occur during validation that are user input related.
Returns:
T an instance of the converted type, or null if the input cannot be converted


© Copyright 2005-2006, Stripes Development Team.