net.sf.mmm.util.value.impl
Class ValueConverterToCollection

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.value.base.AbstractValueConverter<SOURCE,TARGET>
              extended by net.sf.mmm.util.value.base.AbstractRecursiveValueConverter<Object,CONTAINER>
                  extended by net.sf.mmm.util.value.impl.AbstractValueConverterToContainer<Collection>
                      extended by net.sf.mmm.util.value.impl.ValueConverterToCollection
All Implemented Interfaces:
SimpleValueConverter<Object,Collection>, ValueConverter<Object,Collection>

@Singleton
@Named
public class ValueConverterToCollection
extends AbstractValueConverterToContainer<Collection>

This is an implementation of the ValueConverter interface that converts an Object to a Collection.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
 
Fields inherited from class net.sf.mmm.util.value.impl.AbstractValueConverterToContainer
ELEMENT_ESCAPE_END, ELEMENT_ESCAPE_START, ELEMENT_SEPARATOR
 
Constructor Summary
ValueConverterToCollection()
          The constructor.
 
Method Summary
protected  void convertContainerEntry(Object element, int index, Collection container, Object valueSource, GenericType<? extends Collection> targetType, Object value)
          This method converts a single entry of a container.
protected  Collection createContainer(GenericType<? extends Collection> targetType, int length)
          This method creates the according container for the given containerType.
 Class<Collection> getTargetType()
          Is the guaranteed return-type of the conversion.
 
Methods inherited from class net.sf.mmm.util.value.impl.AbstractValueConverterToContainer
convert, convertFromArray, convertFromCollection, convertFromString, doInitialize, getCollectionReflectionUtil, getSourceType, setCollectionReflectionUtil
 
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
 

Constructor Detail

ValueConverterToCollection

public ValueConverterToCollection()
The constructor.

Method Detail

getTargetType

public Class<Collection> 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.

Returns:
the target-type.

convertContainerEntry

protected void convertContainerEntry(Object element,
                                     int index,
                                     Collection container,
                                     Object valueSource,
                                     GenericType<? extends Collection> targetType,
                                     Object value)
This method converts a single entry of a container.

Specified by:
convertContainerEntry in class AbstractValueConverterToContainer<Collection>
Parameters:
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.

createContainer

protected Collection createContainer(GenericType<? extends Collection> targetType,
                                     int length)
This method creates the according container for the given containerType.

Specified by:
createContainer in class AbstractValueConverterToContainer<Collection>
Parameters:
targetType - is the GenericType of the container.
length - is the length (or capacity) of the container to create.
Returns:
the container instance.


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