net.sf.mmm.util.value.base
Class AbstractComposedValueConverter

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.AbstractGenericValueConverter<Object>
              extended by net.sf.mmm.util.value.base.AbstractComposedValueConverter
All Implemented Interfaces:
ComposedValueConverter, GenericValueConverter<Object>, SimpleValueConverter<Object,Object>, ValueConverter<Object,Object>
Direct Known Subclasses:
ComposedValueConverterImpl

public abstract class AbstractComposedValueConverter
extends AbstractGenericValueConverter<Object>
implements ComposedValueConverter

This is the abstract base implementation of the ComposedValueConverter interface.

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

Field Summary
private  ReflectionUtil reflectionUtil
           
 
Constructor Summary
AbstractComposedValueConverter()
          The constructor.
 
Method Summary
 Object convert(Object value, Object valueSource, Class<? extends Object> targetClass)
          This method converts the given pojo to the <TARGET>-type.
<TARGET> TARGET
convertValue(Object value, Object valueSource, Class<TARGET> targetClass)
          This method converts the given value to the given type.
<TARGET> TARGET
convertValue(Object value, Object valueSource, Class<TARGET> targetClass, Type targetType)
          This method converts the given value to the given type.
protected  void doInitialize()
          This method performs the actual initialization.
 ReflectionUtil getReflectionUtil()
          This method gets the ReflectionUtilImpl instance to use.
 Class<Object> getSourceType()
          This the type of the value accepted by this converter.
 Class<Object> getTargetType()
          Is the guaranteed return-type of the conversion.
 void setReflectionUtil(ReflectionUtil reflectionUtil)
           
 
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.ValueConverter
convert
 
Methods inherited from interface net.sf.mmm.util.value.api.GenericValueConverter
convertValue, convertValue, convertValue, convertValue
 

Field Detail

reflectionUtil

private ReflectionUtil reflectionUtil
See Also:
getReflectionUtil()
Constructor Detail

AbstractComposedValueConverter

public AbstractComposedValueConverter()
The constructor.

Method Detail

getReflectionUtil

public ReflectionUtil getReflectionUtil()
This method gets the ReflectionUtilImpl instance to use.

Returns:
the ReflectionUtilImpl to use.

setReflectionUtil

@Inject
public void setReflectionUtil(ReflectionUtil reflectionUtil)
Parameters:
reflectionUtil - is the reflectionUtil to set

doInitialize

protected void doInitialize()
This method performs the actual initialization. It is called when AbstractComponent.initialize() is invoked for the first time.
ATTENTION:
When you override this method from a sub-class you need to do a super.AbstractComponent.doInitialize().

Overrides:
doInitialize in class AbstractLoggableComponent

getSourceType

public final Class<Object> getSourceType()
This the type of the value accepted by this converter. Use Object if you want to accept any value. A very common source-type is String.

Specified by:
getSourceType in interface ValueConverter<Object,Object>
Returns:
the source-type.

getTargetType

public final Class<Object> 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.

Specified by:
getTargetType in interface ValueConverter<Object,Object>
Returns:
the target-type.

convert

public final Object convert(Object value,
                            Object valueSource,
                            Class<? extends Object> targetClass)
This method converts the given pojo to the <TARGET>-type.

Specified by:
convert in interface SimpleValueConverter<Object,Object>
Specified by:
convert in interface ValueConverter<Object,Object>
Parameters:
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.
Returns:
the converted value or null if the conversion is NOT possible. The returned value has to be an instance of the given targetType.
See Also:
ValueConverter.convert(Object, Object, GenericType)

convertValue

public <TARGET> TARGET convertValue(Object value,
                                    Object valueSource,
                                    Class<TARGET> targetClass)
                    throws ValueNotSetException,
                           WrongValueTypeException
This method converts the given value to the given type.

Specified by:
convertValue in interface GenericValueConverter<Object>
Overrides:
convertValue in class AbstractGenericValueConverter<Object>
Type Parameters:
TARGET - is the type to convert to.
Parameters:
value - is the value to convert. It may be null.
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 the value should be converted to.
Returns:
the value converted to type.
Throws:
ValueNotSetException - if the given value is null.
WrongValueTypeException - if the given value is NOT null but can NOT be converted to the given type (e.g. if value is "12x" and type is Integer.class).

convertValue

public <TARGET> TARGET convertValue(Object value,
                                    Object valueSource,
                                    Class<TARGET> targetClass,
                                    Type targetType)
                    throws ValueNotSetException,
                           WrongValueTypeException
This method converts the given value to the given type.

Specified by:
convertValue in interface GenericValueConverter<Object>
Type Parameters:
TARGET - is the type to convert to.
Parameters:
value - is the value to convert. It may be null.
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 the value should be converted to. It is the raw-type of the given targetType.
targetType - is the type to convert the value to. It is potentially generic and therefore contains more detailed information than targetClass. E.g. the targetClass may be java.util.List while this targetType could be java.util.List<Long>. This could help e.g. if the value is a string like "2, 47, 4252525". The caller may supply the targetClass again here.
Returns:
the value converted to type.
Throws:
ValueNotSetException - if the given value is null.
WrongValueTypeException - if the given value is NOT null but can NOT be converted to the given type (e.g. if value is "12x" and type is Integer.class).


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