|
||||||||||
| 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.AbstractValueConverter<SOURCE,TARGET>
net.sf.mmm.util.value.base.AbstractRecursiveValueConverter<Object,CONTAINER>
net.sf.mmm.util.value.impl.AbstractValueConverterToContainer<CONTAINER>
CONTAINER - is the generic type of the container.@Singleton @Named public abstract class AbstractValueConverterToContainer<CONTAINER>
This is the abstract base-implementation of a
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.
Here are some examples:
| 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} |
| Field Summary | |
|---|---|
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 Summary | |
|---|---|
AbstractValueConverterToContainer()
The constructor. |
|
| Method Summary | |
|---|---|
CONTAINER |
convert(Object value,
Object valueSource,
GenericType<? extends CONTAINER> 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 CONTAINER |
convertFromArray(Object arrayValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
This method performs the conversion for array values. |
protected CONTAINER |
convertFromCollection(Collection collectionValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
This method performs the conversion for Collection values. |
protected CONTAINER |
convertFromString(String stringValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
This method performs the conversion for String values. |
protected abstract CONTAINER |
createContainer(GenericType<? extends CONTAINER> 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)
|
| Methods inherited from class net.sf.mmm.util.value.base.AbstractRecursiveValueConverter |
|---|
getComposedValueConverter, setComposedValueConverter |
| Methods inherited from class net.sf.mmm.util.value.base.AbstractValueConverter |
|---|
convert, getReflectionUtil, setReflectionUtil |
| 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.ValueConverter |
|---|
getTargetType |
| Field Detail |
|---|
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
getCollectionReflectionUtil()| Constructor Detail |
|---|
public AbstractValueConverterToContainer()
| Method Detail |
|---|
protected CollectionReflectionUtil getCollectionReflectionUtil()
CollectionReflectionUtilImpl instance to use.
CollectionReflectionUtilImpl to use.@Inject public void setCollectionReflectionUtil(CollectionReflectionUtil collectionReflectionUtil)
collectionReflectionUtil - is the collectionReflectionUtil to setprotected void doInitialize()
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()
Object
if you want to accept any value. A very common source-type is String.
public CONTAINER convert(Object value,
Object valueSource,
GenericType<? extends CONTAINER> 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 CONTAINER convertFromCollection(Collection collectionValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
conversion for Collection values.
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 CONTAINER convertFromString(String stringValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
conversion for String values.
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 CONTAINER convertFromArray(Object arrayValue,
Object valueSource,
GenericType<? extends CONTAINER> targetType)
conversion for array values.
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 CONTAINER createContainer(GenericType<? extends CONTAINER> targetType,
int length)
containerType.
targetType - is the GenericType of the container.length - is the length (or capacity) of the container to create.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||