CONTAINER
- is the generic type of the container.@Singleton @Named public abstract class AbstractValueConverterToContainer<CONTAINER> extends AbstractRecursiveValueConverter<Object,CONTAINER>
ValueConverter
that converts an
Object
to a container type. A container type is an array, Collection
or
Map
. It supports objects given as CharSequence
(e.g. String
), Collection
,
or array. If a value is given as CharSequence
it will be parsed as comma-separated values. An individual
value can be escaped by enclosing it with "<{[" and "]}>" so it can itself contain the separator character. value | target-type |
result |
---|---|---|
"123" | List<Integer> | {123} |
"1, 2,3" | int[] | {1,2,3} |
"a, <{[b,c,d]}>,e" | List<List<Character>> | {{'a'},{'b','c','d'},{'e'}} |
"42=true,84=false" | Map<Integer, Boolean> | {42->true, 84->false} |
Modifier and Type | Field and Description |
---|---|
private CollectionReflectionUtil |
collectionReflectionUtil |
protected static String |
ELEMENT_ESCAPE_END
The suffix used to escape an element (that may contain
ELEMENT_SEPARATOR ). |
protected static String |
ELEMENT_ESCAPE_START
The prefix used to escape an element (that may contain
ELEMENT_SEPARATOR ). |
protected static char |
ELEMENT_SEPARATOR
The character used to separate the element of the collection.
|
Constructor and Description |
---|
AbstractValueConverterToContainer()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
<T extends CONTAINER> |
convert(Object value,
Object valueSource,
GenericType<T> targetType)
This method converts the given
pojo to the <TARGET>-type. |
protected abstract void |
convertContainerEntry(Object element,
int index,
CONTAINER container,
Object valueSource,
GenericType<? extends CONTAINER> targetType,
Object value)
This method converts a single entry of a container.
|
protected <T extends CONTAINER> |
convertFromArray(Object arrayValue,
Object valueSource,
GenericType<T> targetType)
This method performs the
conversion for array values. |
protected <T extends CONTAINER> |
convertFromCollection(Collection collectionValue,
Object valueSource,
GenericType<T> targetType)
This method performs the
conversion for Collection values. |
protected <T extends CONTAINER> |
convertFromString(String stringValue,
Object valueSource,
GenericType<T> targetType)
This method performs the
conversion for String values. |
protected abstract <T extends CONTAINER> |
createContainer(GenericType<T> targetType,
int length)
This method creates the according container for the given
containerType . |
protected void |
doInitialize()
This method performs the actual
initialization . |
protected CollectionReflectionUtil |
getCollectionReflectionUtil()
This method gets the
CollectionReflectionUtilImpl instance to use. |
Class<Object> |
getSourceType()
This the type of the value accepted by this converter.
|
void |
setCollectionReflectionUtil(CollectionReflectionUtil collectionReflectionUtil) |
getComposedValueConverter, setComposedValueConverter
convert, getReflectionUtil, setReflectionUtil
createLogger, getLogger
doInitialized, getInitializationState, initialize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getTargetType
protected static final char ELEMENT_SEPARATOR
protected static final String ELEMENT_ESCAPE_START
ELEMENT_SEPARATOR
).protected static final String ELEMENT_ESCAPE_END
ELEMENT_SEPARATOR
).private CollectionReflectionUtil collectionReflectionUtil
public AbstractValueConverterToContainer()
protected CollectionReflectionUtil getCollectionReflectionUtil()
CollectionReflectionUtilImpl
instance to use.CollectionReflectionUtilImpl
to use.@Inject public void setCollectionReflectionUtil(CollectionReflectionUtil collectionReflectionUtil)
collectionReflectionUtil
- is the collectionReflectionUtil to setprotected void doInitialize()
AbstractComponent
initialization
. It is called when AbstractComponent.initialize()
is
invoked for the first time. super.
AbstractComponent.doInitialize()
.doInitialize
in class AbstractRecursiveValueConverter<Object,CONTAINER>
public Class<Object> getSourceType()
ValueConverter
Object
if you want to accept any
value. A very common source-type
is String
.public <T extends CONTAINER> T convert(Object value, Object valueSource, GenericType<T> targetType)
ValueConverter
pojo
to the <TARGET>-type.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.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 <T extends CONTAINER> T convertFromCollection(Collection collectionValue, Object valueSource, GenericType<T> targetType)
conversion
for Collection
values.T
- is the generic type of targetType
.collectionValue
- is the Collection
value to convert.valueSource
- describes the source of the value or null
if NOT available.targetType
- is the target-type
to convert to.protected <T extends CONTAINER> T convertFromString(String stringValue, Object valueSource, GenericType<T> targetType)
conversion
for String
values.T
- is the generic type of targetType
.stringValue
- is the String
value to convert.valueSource
- describes the source of the value or null
if NOT available.targetType
- is the target-type
to convert to.protected <T extends CONTAINER> T convertFromArray(Object arrayValue, Object valueSource, GenericType<T> targetType)
conversion
for array values.T
- is the generic type of targetType
.arrayValue
- is the array value to convert.valueSource
- describes the source of the value or null
if NOT available.targetType
- is the target-type
to convert to.protected abstract void convertContainerEntry(Object element, int index, CONTAINER container, Object valueSource, GenericType<? extends CONTAINER> targetType, Object value)
element
- is the single entry (element) of the container to convert.index
- is the index of the given element
in the order of occurrence.container
- is the current container where to add the given element
as entry.valueSource
- describes the source of the value or null
if NOT available.targetType
- is the target-type
to convert to.value
- is the original value to convert.protected abstract <T extends CONTAINER> T createContainer(GenericType<T> targetType, int length)
containerType
.T
- is the generic type of targetType
.targetType
- is the GenericType
of the container.length
- is the length (or capacity) of the container to create.Copyright © 2001–2016 mmm-Team. All rights reserved.