|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.value.base.AbstractGenericValueConverter<Object>
net.sf.mmm.util.value.base.AbstractComposedValueConverter
net.sf.mmm.util.value.impl.ComposedValueConverterImpl
@Singleton @Named public class ComposedValueConverterImpl
This is the implementation of the
ComposedValueConverter
interface.
Nested Class Summary | |
---|---|
protected class |
ComposedValueConverterImpl.ComposedTargetTypeConverter<TARGET>
This inner class is a composed converter for all ValueConverter s
with the same target-type . |
protected class |
ComposedValueConverterImpl.TargetClass2ConverterMap
This inner class is an AdvancedClassHierarchieMap for
ComposedValueConverterImpl.ComposedTargetTypeConverter s. |
Field Summary | |
---|---|
private List<ValueConverter<?,?>> |
converters
|
private ComposedValueConverterImpl.TargetClass2ConverterMap |
targetArrayClass2converterMap
|
private ComposedValueConverterImpl.TargetClass2ConverterMap |
targetClass2converterMap
|
Constructor Summary | |
---|---|
ComposedValueConverterImpl()
The constructor. |
Method Summary | |
---|---|
void |
addConverter(ValueConverter<?,?> converter)
This method registers the given converter to this composed
converter. |
private ValueConverter<?,?> |
addConverterInternal(ValueConverter<?,?> converter)
This method registers the given converter to this composed
converter. |
Object |
convert(Object value,
Object valueSource,
GenericType<? extends Object> targetType)
This method converts the given pojo to the
<TARGET>-type. |
protected Object |
convertRecursive(Object value,
Object valueSource,
GenericType<?> targetType,
Class<?> currentTargetClass,
ValueConverter previousConverter,
ComposedValueConverterImpl.TargetClass2ConverterMap converterMap)
This method performs the conversion recursive. |
protected void |
doInitialize()
This method performs the actual initialization . |
protected boolean |
isAccepted(Class<?> type)
This method determines if the given type is accepted as
significant type for registration and lookup of ValueConverter s. |
protected boolean |
isApplicable(Class<?> converterTargetClass,
Class<?> expectedTargetClass)
This method determines if the given converterTargetClass is
applicable for the expectedTargetClass . |
protected boolean |
isApplicable(ValueConverter<?,?> converter,
GenericType<?> targetType)
This method determines if the given converter is applicable
for the given targetType . |
void |
setConverters(List<ValueConverter<?,?>> converterList)
This method allows to add a
List of ValueConverter s. |
Methods inherited from class net.sf.mmm.util.value.base.AbstractComposedValueConverter |
---|
convert, convertValue, convertValue, getReflectionUtil, getSourceType, getTargetType, setReflectionUtil |
Methods inherited from class net.sf.mmm.util.value.base.AbstractGenericValueConverter |
---|
convertValue, convertValue, convertValue, convertValue |
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
---|
getLogger, setLogger |
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
---|
doInitialized, getInitializationState, initialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.mmm.util.value.api.GenericValueConverter |
---|
convertValue, convertValue, convertValue, convertValue |
Field Detail |
---|
private final ComposedValueConverterImpl.TargetClass2ConverterMap targetClass2converterMap
addConverter(ValueConverter)
private final ComposedValueConverterImpl.TargetClass2ConverterMap targetArrayClass2converterMap
addConverter(ValueConverter)
private List<ValueConverter<?,?>> converters
setConverters(List)
Constructor Detail |
---|
public ComposedValueConverterImpl()
Method Detail |
---|
protected void doInitialize()
initialization
. It is
called when AbstractComponent.initialize()
is invoked for the first time.super.AbstractComponent.doInitialize()
.
doInitialize
in class AbstractComposedValueConverter
public void addConverter(ValueConverter<?,?> converter)
converter
to this composed
converter.
converter
- is the converter to add.private ValueConverter<?,?> addConverterInternal(ValueConverter<?,?> converter)
converter
to this composed
converter.
converter
- is the converter to add.
source-type
and target-type
that has been replaced by converter
or
null
if no converter has been replaced.@Inject public void setConverters(List<ValueConverter<?,?>> converterList)
add
a
List
of ValueConverter
s.
converterList
- is the list of converters to register.public Object convert(Object value, Object valueSource, GenericType<? extends Object> targetType)
pojo
to the
<TARGET>-type.
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.targetType
- 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 boolean isApplicable(ValueConverter<?,?> converter, GenericType<?> targetType)
converter
is applicable
for the given targetType
.
converter
- is the ValueConverter
to check.targetType
- is the GenericType
to match with
ValueConverter.getTargetType()
.
true
if the given converter
is
applicable, false
otherwise.ValueConverter.getTargetType()
protected boolean isApplicable(Class<?> converterTargetClass, Class<?> expectedTargetClass)
converterTargetClass
is
applicable for the expectedTargetClass
.
converterTargetClass
- is the target-class
of the ValueConverter
to check.expectedTargetClass
- is the target-class to convert to.
true
if the conversion is applicable.protected boolean isAccepted(Class<?> type)
type
is accepted as
significant type for registration and lookup of ValueConverter
s.
E.g. interfaces such as Cloneable
or Serializable
are not more significant than Object
in order to choose the
appropriate ValueConverter
and should therefore be skipped when the
Class
-hierarchy is recursively traversed.false
the behaviour differs between
interfaces
and regular classes. For an
interface the entire traversal of super-interfaces is skipped, while for a
regular class, just that class is skipped, but
super-classes
are recursively traversed.
type
- is the Class
reflecting the type to check.
true
if the given type
is acceptable,
false
if the given type
should be
ignored.protected Object convertRecursive(Object value, Object valueSource, GenericType<?> targetType, Class<?> currentTargetClass, ValueConverter previousConverter, ComposedValueConverterImpl.TargetClass2ConverterMap converterMap)
conversion
recursive.
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.targetType
- is the GenericType
to convert the
value
to.currentTargetClass
- is the current
target-type
to try.previousConverter
- is the converter that has been tried last time
without success. It is used to avoid trying the same converter
again. Will initially be null
.converterMap
- is the ComposedValueConverterImpl.TargetClass2ConverterMap
.
value
or null
if the
conversion is NOT possible. The returned value has to be an
instance
of the given
targetType
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |