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

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,Object>
                  extended by net.sf.mmm.util.value.impl.ValueConverterToCompatiblePojo
All Implemented Interfaces:
SimpleValueConverter<Object,Object>, ValueConverter<Object,Object>

@Singleton
@Named
public class ValueConverterToCompatiblePojo
extends AbstractRecursiveValueConverter<Object,Object>

This is an implementation of the ValueConverter interface that converts an POJO to a POJO with the same properties. E.g. this can be useful when you have generated transport-objects (maybe from some strange web-service-framework) and want to convert those from or to your nice equivalent handwritten POJOs.

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

Field Summary
private  PojoDescriptorBuilder pojoDescriptorBuilder
           
private  PojoDescriptorBuilderFactory pojoDescriptorBuilderFactory
           
private  PojoFactory pojoFactory
           
 
Constructor Summary
ValueConverterToCompatiblePojo()
          The constructor.
 
Method Summary
 Object convert(Object value, Object valueSource, GenericType<? extends Object> targetType)
          This method converts the given pojo to the <TARGET>-type.
protected  void doInitialize()
          This method performs the actual initialization.
protected  PojoDescriptorBuilder getPojoDescriptorBuilder()
           
protected  PojoDescriptorBuilderFactory getPojoDescriptorBuilderFactory()
           
 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 setPojoDescriptorBuilder(PojoDescriptorBuilder pojoDescriptorBuilder)
          This method sets the PojoDescriptorBuilder instance to use.
 void setPojoDescriptorBuilderFactory(PojoDescriptorBuilderFactory pojoDescriptorBuilderFactory)
          This method sets the PojoDescriptorBuilderFactory instance to use.
 void setPojoFactory(PojoFactory pojoFactory)
          This method sets the PojoFactory instance to used to create new instances of POJOs.
 
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
 

Field Detail

pojoFactory

private PojoFactory pojoFactory
See Also:
setPojoFactory(PojoFactory)

pojoDescriptorBuilder

private PojoDescriptorBuilder pojoDescriptorBuilder
See Also:
setPojoDescriptorBuilder(PojoDescriptorBuilder)

pojoDescriptorBuilderFactory

private PojoDescriptorBuilderFactory pojoDescriptorBuilderFactory
See Also:
setPojoDescriptorBuilderFactory(PojoDescriptorBuilderFactory)
Constructor Detail

ValueConverterToCompatiblePojo

public ValueConverterToCompatiblePojo()
The constructor.

Method Detail

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 AbstractRecursiveValueConverter<Object,Object>

getSourceType

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

Returns:
the source-type.

getTargetType

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

Returns:
the target-type.

convert

public Object convert(Object value,
                      Object valueSource,
                      GenericType<? extends Object> targetType)
               throws ValueException
This method converts the given pojo to the <TARGET>-type.

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.
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".
Returns:
the converted value or null if the conversion is NOT possible. The returned value has to be an instance of the given targetType.
Throws:
ValueException - if the conversion failed (e.g. the given value is illegal for the given targetClass).

setPojoFactory

@Inject
public void setPojoFactory(PojoFactory pojoFactory)
This method sets the PojoFactory instance to used to create new instances of POJOs.

Parameters:
pojoFactory - is the PojoFactory to use.

getPojoDescriptorBuilder

protected PojoDescriptorBuilder getPojoDescriptorBuilder()
Returns:
the PojoDescriptorBuilder.

setPojoDescriptorBuilder

public void setPojoDescriptorBuilder(PojoDescriptorBuilder pojoDescriptorBuilder)
This method sets the PojoDescriptorBuilder instance to use. If no such instance is set, the factory has to be set and an individual instance will be created automatically on initialization.

Parameters:
pojoDescriptorBuilder - is the PojoDescriptorBuilder to use.

setPojoDescriptorBuilderFactory

@Inject
public void setPojoDescriptorBuilderFactory(PojoDescriptorBuilderFactory pojoDescriptorBuilderFactory)
This method sets the PojoDescriptorBuilderFactory instance to use.

Parameters:
pojoDescriptorBuilderFactory - is the pojoDescriptorBuilderFactory to set

getPojoDescriptorBuilderFactory

protected PojoDescriptorBuilderFactory getPojoDescriptorBuilderFactory()
Returns:
the pojoDescriptorBuilderFactory


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