TARGET - is the generic target-type.protected class ComposedValueConverterImpl.ComposedTargetTypeConverter<TARGET> extends Object implements ValueConverter<Object,TARGET>
ValueConverters with the same
target-type.| Modifier and Type | Field and Description |
|---|---|
private Map<Class<?>,ValueConverter<?,TARGET>> |
sourceClass2converterMap |
private Class<TARGET> |
targetType |
| Constructor and Description |
|---|
ComposedTargetTypeConverter(Class<TARGET> targetType)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
ValueConverter<?,TARGET> |
addConverter(ValueConverter<?,TARGET> converter)
This method registers the given
converter to this composed converter. |
<T extends TARGET> |
convert(Object value,
Object valueSource,
Class<T> targetClass)
This method converts the given
pojo to the <TARGET>-type. |
<T extends TARGET> |
convert(Object value,
Object valueSource,
GenericType<T> genericTargetType)
This method converts the given
pojo to the <TARGET>-type. |
protected <T extends TARGET> |
convertRecursive(Object value,
Object valueSource,
GenericType<T> 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. |
private final Map<Class<?>,ValueConverter<?,TARGET>> sourceClass2converterMap
public ComposedTargetTypeConverter(Class<TARGET> targetType)
targetType - is the target-type of this converter.public Class<Object> getSourceType()
ValueConverterObject if you want to accept any value. A very
common source-type is String.getSourceType in interface ValueConverter<Object,TARGET>public Class<TARGET> getTargetType()
ValueConverterconversion. This information is
used externally to choose the most specific ValueConverter that is appropriate for the conversion. 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.
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.getTargetType in interface ValueConverter<Object,TARGET>public ValueConverter<?,TARGET> addConverter(ValueConverter<?,TARGET> converter)
converter to this composed converter.converter - is the converter to add.source-type that has been replaced by
converter or null if no converter has been replaced.public <T extends TARGET> T convert(Object value, Object valueSource, Class<T> targetClass) throws ValueException
SimpleValueConverterpojo to the <TARGET>-type.convert in interface SimpleValueConverter<Object,TARGET>T - is the generic type of targetClass.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.value or null if the conversion is NOT possible. The returned value
has to be an instance of the given targetType.ValueException - if the conversion failed (e.g. the given value is illegal for the given
targetClass).ValueExceptionpublic <T extends TARGET> T convert(Object value, Object valueSource, GenericType<T> genericTargetType)
ValueConverterpojo to the <TARGET>-type.convert in interface ValueConverter<Object,TARGET>T - is the generic type of targetClass.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".value or null if the conversion is NOT possible. The returned value has to be
an instance of the given targetType.protected <T extends TARGET> T convertRecursive(Object value, Object valueSource, GenericType<T> genericTargetType, Class<?> sourceClass)
conversion recursive.T - is the generic type of genericTargetType.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.value or null if the conversion is NOT possible. The returned value has to
be an instance of the given targetType.Copyright © 2001–2019 mmm-Team. All rights reserved.