com.ferri.core.vo.commons.converters
Class BeansConverter

java.lang.Object
  extended by com.ferri.core.vo.commons.converters.BeansConverter
All Implemented Interfaces:
Initializable

public class BeansConverter
extends Object
implements Initializable

Author:
dferri

Field Summary
private  Map<Class<?>,AbstractConverter<?,?>> converters
           
private  Collection<AbstractConverter<?,?>> convertersCollection
           
private  org.apache.log4j.Logger logger
           
 int TYPE_DTO
           
 int TYPE_VO
           
 
Constructor Summary
BeansConverter()
           
BeansConverter(Collection<AbstractConverter<?,?>> convertersCollection)
           
 
Method Summary
 BaseVO convert(BaseDTO baseDTO)
           
 BaseVO convert(BaseDTO baseDTO, String methodName)
           
 BaseDTO convert(BaseVO baseVO)
           
 BaseDTO convert(BaseVO baseVO, String methodName)
           
private  AbstractBase convertBase(AbstractBase baseOrigin, String methodName, int type)
           
 Collection<? extends AbstractBase> convertCollection(Collection<? extends AbstractBase> collection)
           
 Collection<? extends AbstractBase> convertCollection(Collection<? extends AbstractBase> collection, String methodName)
           
 void deregister(Class<?> clazz)
          Remove any registered AbstractConverter for the specified destination Class.
private  String getConvertedDescription(Class<?> clazzTypeFrom, Class<?> clazzTypeTO)
          Return a description for the given method invocation.
private  String getConvertedType(int type)
           
private  Map<Class<?>,AbstractConverter<?,?>> getConverters()
           
 Collection<AbstractConverter<?,?>> getConvertersCollection()
           
private  Object getFirstCollectionObject(Collection<?> collection)
           
private  org.apache.log4j.Logger getLogger()
           
 void initialize()
          Execute the first operations to complete the instanciation.
 void initiateConverters()
           
private  AbstractConverter<?,?> lookup(Class<?> clazz)
          Look up and return any registered AbstractConverter for the specified destination class; if there is no registered Converter, return null.
private  AbstractConverter<?,?> lookup(Object object)
          Look up and return any registered AbstractConverter for the specified destination class; if there is no registered Converter, return null.
 void register(Class<?> clazz, AbstractConverter<BaseDTO,BaseVO> converter)
          Register a custom AbstractConverter for the specified destination Class, replacing any previously registered Converter.
 void resetConverters()
           
 void setConvertersCollection(Collection<AbstractConverter<?,?>> convertersCollection)
           
private  Class<?> translateProxyType(Object object)
          Retrieve the class type of the given object, looking for a proxy from Hibernate.
private  boolean validObject(Object obj)
          Checks for null Objects
private  boolean validType(int type)
          Checks for recognized type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_DTO

public int TYPE_DTO

TYPE_VO

public int TYPE_VO

logger

private org.apache.log4j.Logger logger

converters

private Map<Class<?>,AbstractConverter<?,?>> converters

convertersCollection

private Collection<AbstractConverter<?,?>> convertersCollection
Constructor Detail

BeansConverter

public BeansConverter()

BeansConverter

public BeansConverter(Collection<AbstractConverter<?,?>> convertersCollection)
Method Detail

initiateConverters

public void initiateConverters()

resetConverters

public void resetConverters()

initialize

public void initialize()
Description copied from interface: Initializable
Execute the first operations to complete the instanciation.

Specified by:
initialize in interface Initializable

register

public void register(Class<?> clazz,
                     AbstractConverter<BaseDTO,BaseVO> converter)
Register a custom AbstractConverter for the specified destination Class, replacing any previously registered Converter.

Parameters:
converter - Converter to be registered
clazz - Destination class for conversions performed by this AbstractConverter

deregister

public void deregister(Class<?> clazz)
Remove any registered AbstractConverter for the specified destination Class.

Parameters:
clazz - Class for which to remove a registered AbstractConverter

lookup

private AbstractConverter<?,?> lookup(Class<?> clazz)
                               throws ConverterNotFoundException
Look up and return any registered AbstractConverter for the specified destination class; if there is no registered Converter, return null.

Parameters:
clazz - Class for which to return a registered AbstractConverter
Throws:
ConverterNotFoundException - if the converter is not found.

lookup

private AbstractConverter<?,?> lookup(Object object)
                               throws ConverterNotFoundException
Look up and return any registered AbstractConverter for the specified destination class; if there is no registered Converter, return null.

Parameters:
object - Object for which to return a registered AbstractConverter
Throws:
ConverterNotFoundException - if the converter is not found.

translateProxyType

private Class<?> translateProxyType(Object object)
Retrieve the class type of the given object, looking for a proxy from Hibernate.

Parameters:
object - the object to determine th class type
Returns:
the Class type expected

convertBase

private AbstractBase convertBase(AbstractBase baseOrigin,
                                 String methodName,
                                 int type)

convert

public BaseVO convert(BaseDTO baseDTO,
                      String methodName)

convert

public BaseDTO convert(BaseVO baseVO,
                       String methodName)

convert

public BaseVO convert(BaseDTO baseDTO)

convert

public BaseDTO convert(BaseVO baseVO)

convertCollection

public Collection<? extends AbstractBase> convertCollection(Collection<? extends AbstractBase> collection)

convertCollection

public Collection<? extends AbstractBase> convertCollection(Collection<? extends AbstractBase> collection,
                                                            String methodName)

getConvertedDescription

private String getConvertedDescription(Class<?> clazzTypeFrom,
                                       Class<?> clazzTypeTO)
Return a description for the given method invocation.

Parameters:
clazzTypeFrom - the class incomming to describe
clazzTypeTO - the class outcomming to describe
Returns:
the description

getConvertedType

private String getConvertedType(int type)

validType

private boolean validType(int type)
Checks for recognized type

Parameters:
type - the style
Returns:

validObject

private boolean validObject(Object obj)
Checks for null Objects

Parameters:
type - the style
Returns:

getFirstCollectionObject

private Object getFirstCollectionObject(Collection<?> collection)

getConverters

private Map<Class<?>,AbstractConverter<?,?>> getConverters()
Returns:
the converters

getLogger

private org.apache.log4j.Logger getLogger()
Returns:
the logger

getConvertersCollection

public Collection<AbstractConverter<?,?>> getConvertersCollection()
Returns:
the convertersCollection

setConvertersCollection

public void setConvertersCollection(Collection<AbstractConverter<?,?>> convertersCollection)
Parameters:
convertersCollection - the convertersCollection to set