net.sf.beanlib.provider
Class BeanPopulator

java.lang.Object
  extended by net.sf.beanlib.provider.BeanPopulator
All Implemented Interfaces:
BeanPopulatorBaseSpi, BeanPopulatorSpi

@NotThreadSafe
public class BeanPopulator
extends Object
implements BeanPopulatorSpi

Bean Populator.

Author:
Joe D. Velopar

Nested Class Summary
static class BeanPopulator.Factory
          Bean Populator Factory.
 
Field Summary
private  BeanPopulatorBaseConfig baseConfig
           
static BeanPopulator.Factory factory
           
private  Object fromBean
           
private  Log log
           
private  Object toBean
           
private  Transformable transformer
           
 
Constructor Summary
private BeanPopulator(Object fromBean, Object toBean)
           
 
Method Summary
private
<T> void
doit(Method setterMethod, Method readerMethod, Class<T> paramType, String propertyName)
           
 Transformable getTransformer()
           
private  BeanTransformerSpi getTransformerSpi()
           
 BeanPopulator initBeanPopulatable(BeanPopulatable beanPopulatable)
           
 BeanPopulator initBeanPopulationExceptionHandler(BeanPopulationExceptionHandler beanPopulationExceptionHandler)
           
 BeanPopulator initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig baseConfig)
           
 BeanPopulator initBeanSourceHandler(BeanSourceHandler beanSourceHandler)
           
 BeanPopulator initDebug(boolean debug)
           
 BeanPopulator initDetailedBeanPopulatable(DetailedBeanPopulatable detailedBeanPopulatable)
           
 BeanPopulator initReaderMethodFinder(BeanMethodFinder readerMethodFinder)
           
 BeanPopulator initSetterMethodCollector(BeanMethodCollector setterMethodCollector)
           
 BeanPopulator initTransformer(Transformable transformer)
           
private  Object invokeMethodAsPrivileged(Object target, Method method, Object[] args)
          Invoke the given method as a privileged action, if necessary.
static BeanPopulator newBeanPopulator(Object from, Object to)
           
<T> T
populate()
          Returns the to-bean with setter methods invoked with values retreived from the getter methods of the from-bean.
private  void processSetterMethod(Method setterMethod)
          Processes a specific setter method for the toBean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

public static final BeanPopulator.Factory factory

log

private final Log log

fromBean

private final Object fromBean

toBean

private final Object toBean

baseConfig

private BeanPopulatorBaseConfig baseConfig

transformer

private Transformable transformer
Constructor Detail

BeanPopulator

private BeanPopulator(Object fromBean,
                      Object toBean)
Parameters:
fromBean - from bean
toBean - to bean
Method Detail

newBeanPopulator

public static BeanPopulator newBeanPopulator(Object from,
                                             Object to)

getTransformerSpi

private BeanTransformerSpi getTransformerSpi()

populate

public <T> T populate()
Returns the to-bean with setter methods invoked with values retreived from the getter methods of the from-bean.

Specified by:
populate in interface BeanPopulatorSpi

processSetterMethod

private void processSetterMethod(Method setterMethod)
Processes a specific setter method for the toBean.

Parameters:
setterMethod - a specific method of the toBean

doit

private <T> void doit(Method setterMethod,
                      Method readerMethod,
                      Class<T> paramType,
                      String propertyName)

invokeMethodAsPrivileged

private Object invokeMethodAsPrivileged(Object target,
                                        Method method,
                                        Object[] args)
Invoke the given method as a privileged action, if necessary.

Throws:
InvocationTargetException
IllegalAccessException
IllegalArgumentException

initBeanPopulatable

public BeanPopulator initBeanPopulatable(BeanPopulatable beanPopulatable)
Specified by:
initBeanPopulatable in interface BeanPopulatorBaseSpi
Specified by:
initBeanPopulatable in interface BeanPopulatorSpi
Parameters:
beanPopulatable - optionally used to control if a specific value read should get populated across

initBeanSourceHandler

public BeanPopulator initBeanSourceHandler(BeanSourceHandler beanSourceHandler)
Specified by:
initBeanSourceHandler in interface BeanPopulatorBaseSpi
Specified by:
initBeanSourceHandler in interface BeanPopulatorSpi
Parameters:
beanSourceHandler - optionally used to do something with the value read before the population

initDebug

public BeanPopulator initDebug(boolean debug)
Specified by:
initDebug in interface BeanPopulatorBaseSpi
Specified by:
initDebug in interface BeanPopulatorSpi
Parameters:
debug - debug mode.

initDetailedBeanPopulatable

public BeanPopulator initDetailedBeanPopulatable(DetailedBeanPopulatable detailedBeanPopulatable)
Specified by:
initDetailedBeanPopulatable in interface BeanPopulatorBaseSpi
Specified by:
initDetailedBeanPopulatable in interface BeanPopulatorSpi
Parameters:
detailedBeanPopulatable - optionally used to override the population decisions.

initReaderMethodFinder

public BeanPopulator initReaderMethodFinder(BeanMethodFinder readerMethodFinder)
Specified by:
initReaderMethodFinder in interface BeanPopulatorBaseSpi
Specified by:
initReaderMethodFinder in interface BeanPopulatorSpi

initSetterMethodCollector

public BeanPopulator initSetterMethodCollector(BeanMethodCollector setterMethodCollector)
Specified by:
initSetterMethodCollector in interface BeanPopulatorBaseSpi
Specified by:
initSetterMethodCollector in interface BeanPopulatorSpi

getTransformer

public Transformable getTransformer()
Specified by:
getTransformer in interface BeanPopulatorSpi

initTransformer

public BeanPopulator initTransformer(Transformable transformer)
Specified by:
initTransformer in interface BeanPopulatorSpi
Parameters:
transformer - optionally used to transform the value for the population

initBeanPopulationExceptionHandler

public BeanPopulator initBeanPopulationExceptionHandler(BeanPopulationExceptionHandler beanPopulationExceptionHandler)
Specified by:
initBeanPopulationExceptionHandler in interface BeanPopulatorBaseSpi
Specified by:
initBeanPopulationExceptionHandler in interface BeanPopulatorSpi

initBeanPopulatorBaseConfig

public BeanPopulator initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig baseConfig)
Specified by:
initBeanPopulatorBaseConfig in interface BeanPopulatorBaseSpi
Specified by:
initBeanPopulatorBaseConfig in interface BeanPopulatorSpi