org.dozer
Class DozerConverter<A,B>

java.lang.Object
  extended by org.dozer.DozerConverter<A,B>
All Implemented Interfaces:
ConfigurableCustomConverter, CustomConverter

public abstract class DozerConverter<A,B>
extends Object
implements ConfigurableCustomConverter

This class should be extended in order to implement new Custom Converters for value transformation.


Constructor Summary
DozerConverter(Class<A> prototypeA, Class<B> prototypeB)
          Defines two types, which will take part transformation.
 
Method Summary
 Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass)
           
 A convertFrom(B source)
          Converts the source field to the destination field and return the resulting destination value
abstract  A convertFrom(B source, A destination)
          Converts the source field to the destination field and return the resulting destination value
 B convertTo(A source)
          Converts the source field to the destination field and return the resulting destination value.
abstract  B convertTo(A source, B destination)
          Converts the source field to the destination field and return the resulting destination value.
 String getParameter()
          Retrieves the static parameter configured for this particular converter instance.
 void setParameter(String parameter)
          Sets the configured parameter value for this converter instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DozerConverter

public DozerConverter(Class<A> prototypeA,
                      Class<B> prototypeB)
Defines two types, which will take part transformation. As Dozer supports bi-directional mapping it is not known which of the classes is source and which is destination. It will be decided in runtime.

Parameters:
prototypeA - type one
prototypeB - type two
Method Detail

convert

public Object convert(Object existingDestinationFieldValue,
                      Object sourceFieldValue,
                      Class<?> destinationClass,
                      Class<?> sourceClass)
Specified by:
convert in interface CustomConverter

convertTo

public abstract B convertTo(A source,
                            B destination)
Converts the source field to the destination field and return the resulting destination value.

Parameters:
source - the value of the source field
destination - the current value of the desitinatino field (or null)
Returns:
the resulting value for the destinatino field

convertTo

public B convertTo(A source)
Converts the source field to the destination field and return the resulting destination value.

Parameters:
source - the value of the source field
Returns:
the resulting value for the destinatino field

convertFrom

public abstract A convertFrom(B source,
                              A destination)
Converts the source field to the destination field and return the resulting destination value

Parameters:
source - the value of the source field
destination - the current value of the desitinatino field (or null)
Returns:
the resulting value for the destinatino field

convertFrom

public A convertFrom(B source)
Converts the source field to the destination field and return the resulting destination value

Parameters:
source - the value of the source field
Returns:
the resulting value for the destinatino field

setParameter

public void setParameter(String parameter)
Sets the configured parameter value for this converter instance. Should be called by Dozer internaly before actual mapping.

Specified by:
setParameter in interface ConfigurableCustomConverter
Parameters:
parameter - configured parameter value

getParameter

public String getParameter()
Retrieves the static parameter configured for this particular converter instance. It is not advisable to call this method from converter constructor as the parameter is not yet there.

Returns:
parameter value
Throws:
IllegalStateException - if parameter has not been set yet.


Copyright © 2005-2011 dozer. All Rights Reserved.