org.spicefactory.lib.reflect
Interface Converter<T>

All Known Implementing Classes:
AbstractSequenceConverter, ArrayConverter, CollectionConverter, EnumConverter, NumberConverter

public interface Converter<T>

Interface to be implemented by objects responsible for any necessary type conversion. Instances implementing this interface will be registered in ReflectionFactory instances and will be used in TypeContext, MethodInvoker and Property instances created by that factory.

Author:
Jens Halm

Method Summary
 T convert(Object value, TypeContext typeContext)
          Converts the given value to the target type of this converter.
 boolean supports(Class<?> type)
          Checks if this converter can convert instances of the given class to the target type of this converter.
 

Method Detail

supports

boolean supports(Class<?> type)
Checks if this converter can convert instances of the given class to the target type of this converter. Of course this does not give any guarantee that conversion will succeed for any instance of the given type.

Parameters:
type - the class to be checked
Returns:
true if this converter can convert instances of the given class

convert

T convert(Object value,
          TypeContext typeContext)
          throws ConversionException
Converts the given value to the target type of this converter. The TypeContext parameter serves as an additional hint for the required type of the converted value. Example: If a Converter implementation handles all kinds of Collections (implements Converter<Collection>) the given TypeContext might provide information for the exact nature of the Collection (like List<String>).

Parameters:
value - the value to be converted
typeContext - additional information for the required type of the converted value
Returns:
the converted value
Throws:
ConversionException - if the conversion fails