net.sf.mmm.util.value.impl
Class ComposedValueConverterImpl.ComposedTargetTypeConverter<TARGET>

java.lang.Object
  extended by net.sf.mmm.util.value.impl.ComposedValueConverterImpl.ComposedTargetTypeConverter<TARGET>
Type Parameters:
TARGET - is the generic target-type.
All Implemented Interfaces:
SimpleValueConverter<Object,TARGET>, ValueConverter<Object,TARGET>
Enclosing class:
ComposedValueConverterImpl

protected class ComposedValueConverterImpl.ComposedTargetTypeConverter<TARGET>
extends Object
implements ValueConverter<Object,TARGET>

This inner class is a composed converter for all ValueConverters with the same target-type.


Field Summary
private  Map<Class<?>,ValueConverter<?,TARGET>> sourceClass2converterMap
           
private  Class<TARGET> targetType
           
 
Constructor Summary
ComposedValueConverterImpl.ComposedTargetTypeConverter(Class<TARGET> targetType)
          The constructor.
 
Method Summary
 ValueConverter<?,TARGET> addConverter(ValueConverter<?,TARGET> converter)
          This method registers the given converter to this composed converter.
 TARGET convert(Object value, Object valueSource, Class<? extends TARGET> targetClass)
          This method converts the given pojo to the <TARGET>-type.
 TARGET convert(Object value, Object valueSource, GenericType<? extends TARGET> genericTargetType)
          This method converts the given pojo to the <TARGET>-type.
protected  TARGET convertRecursive(Object value, Object valueSource, GenericType<? extends TARGET> genericTargetType, Class<?> sourceClass)
          This method performs the conversion recursive.
 Class<Object> getSourceType()
          This the type of the value accepted by this converter.
 Class<TARGET> getTargetType()
          Is the guaranteed return-type of the conversion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

targetType

private final Class<TARGET> targetType
See Also:
getTargetType()

sourceClass2converterMap

private final Map<Class<?>,ValueConverter<?,TARGET>> sourceClass2converterMap
See Also:
addConverter(ValueConverter)
Constructor Detail

ComposedValueConverterImpl.ComposedTargetTypeConverter

public ComposedValueConverterImpl.ComposedTargetTypeConverter(Class<TARGET> targetType)
The constructor.

Parameters:
targetType - is the target-type of this converter.
Method Detail

getSourceType

public Class<Object> getSourceType()
This the type of the value accepted by this converter. Use Object if you want to accept any value. A very common source-type is String.

Specified by:
getSourceType in interface ValueConverter<Object,TARGET>
Returns:
the source-type.

getTargetType

public Class<TARGET> getTargetType()
Is the guaranteed return-type of the conversion. This information is used externally to choose the most specific ValueConverter that is appropriate for the conversion.
E.g. a generic converter can have Object as target-type while a specific converter may have Collection as target-type. Now if an object (compliant with the source-type) needs to be converted to a Collection or List, the specific converter is used while for other objects the generic converter is chosen.
Please note that the target-type is often more general than the actual returned result. So a ValueConverter that converts a comma-separated String to an ArrayList will typically declare List as target-type.

Specified by:
getTargetType in interface ValueConverter<Object,TARGET>
Returns:
the target-type.

addConverter

public ValueConverter<?,TARGET> addConverter(ValueConverter<?,TARGET> converter)
This method registers the given converter to this composed converter.

Parameters:
converter - is the converter to add.
Returns:
the converter with the same source-type that has been replaced by converter or null if no converter has been replaced.

convert

public TARGET convert(Object value,
                      Object valueSource,
                      Class<? extends TARGET> targetClass)
               throws ValueException
This method converts the given pojo to the <TARGET>-type.

Specified by:
convert in interface SimpleValueConverter<Object,TARGET>
Specified by:
convert in interface ValueConverter<Object,TARGET>
Parameters:
value - is the value to convert.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
targetClass - is the type to convert the value to.
Returns:
the converted value or null if the conversion is NOT possible. The returned value has to be an instance of the given targetType.
Throws:
ValueException - if the conversion failed (e.g. the given value is illegal for the given targetClass).
See Also:
ValueConverter.convert(Object, Object, GenericType)

convert

public TARGET convert(Object value,
                      Object valueSource,
                      GenericType<? extends TARGET> genericTargetType)
This method converts the given pojo to the <TARGET>-type.

Specified by:
convert in interface ValueConverter<Object,TARGET>
Parameters:
value - is the value to convert.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
genericTargetType - is the GenericType to convert the value to. It is potentially generic and therefore contains more detailed information than a Class. E.g. the targetType could be java.util.List<Long>. This could help e.g. if the value is a string like "2, 47, 4252525".
Returns:
the converted value or null if the conversion is NOT possible. The returned value has to be an instance of the given targetType.

convertRecursive

protected TARGET convertRecursive(Object value,
                                  Object valueSource,
                                  GenericType<? extends TARGET> genericTargetType,
                                  Class<?> sourceClass)
This method performs the conversion recursive.

Parameters:
value - is the value to convert.
valueSource - describes the source of the value. This may be the filename where the value was read from, an XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes wrong. This will help to find the problem easier.
genericTargetType - is the GenericType to convert the value to.
sourceClass - is the current source-type to try.
Returns:
the converted value or null if the conversion is NOT possible. The returned value has to be an instance of the given targetType.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.