|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.beanlib.provider.BeanPopulator
@NotThreadSafe public class BeanPopulator
Default implementation of BeanPopulatorSpi.
A Bean Populator can be used to populate the properties from a JavaBean instance to another JavaBean instance. For example,
By default, every public setter method of the target JavaBean is invoked with the value retrieved from the corresponding public getter method (of the same property name and type) of the source JavaBean.Bean from = ... Bean to = ... new BeanPopulator(from, to).populate();
How the set of setter methods and getter methods are determined can be overridden
via the methods initSetterMethodCollector(BeanMethodCollector)
and initReaderMethodFinder(BeanMethodFinder)
before the populate() method is invoked.
During the property propagation process, various options exist to override the default behavior:
DetailedPropertyFilter can be used to control whether a specific JavaBean property
should be propagated across.initDetailedPropertyFilter(DetailedPropertyFilter).DetailedPropertyFilter but with a simpler API,
a PropertyFilter can be used to control whether a specific JavaBean property
should be propagated across.initPropertyFilter(PropertyFilter).BeanSourceHandler can be used to act as a call-back
(to produce whatever side-effects deemed necessary)
after the property value has been retrieved from the source bean,
but before being propagated across to the target bean. initBeanSourceHandler(BeanSourceHandler).Transformable can be used to transform and replace the property value
to be propagated across to the target bean.initTransformer(Transformable).BeanPopulationExceptionHandler can be used to handle any exception thrown.initBeanPopulationExceptionHandler(BeanPopulationExceptionHandler) and
BeanPopulationExceptionHandler.initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig).
| Nested Class Summary | |
|---|---|
static class |
BeanPopulator.Factory
Bean Populator Factory, which implements the general factory interface of a BeanPopulatorSpi instance. |
| Field Summary | |
|---|---|
private BeanPopulatorBaseConfig |
baseConfig
|
static BeanPopulator.Factory |
factory
|
private Object |
fromBean
|
private org.apache.log4j.Logger |
log
|
private Object |
toBean
|
private Transformable |
transformer
|
| Constructor Summary | |
|---|---|
BeanPopulator(Object fromBean,
Object toBean)
|
|
| Method Summary | ||
|---|---|---|
private
|
doit(Method setterMethod,
Method readerMethod,
Class<T> paramType,
String propertyName)
|
|
BeanPopulationExceptionHandler |
getBeanPopulationExceptionHandler()
Returns the exception handler configured for bean population. |
|
BeanPopulatorBaseConfig |
getBeanPopulatorBaseConfig()
Notes if the returned base config is modified, a subsequent initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig)
needs to be invoked to keep the configuration in sync. |
|
BeanSourceHandler |
getBeanSourceHandler()
Returns the call-back configured that would be invoked after the property value has been retrieved from the source bean, but before being propagated across to the target bean. |
|
private BeanTransformerSpi |
getBeanTransformerSpi()
|
|
DetailedPropertyFilter |
getDetailedPropertyFilter()
Returns the detailed property filter configured. |
|
PropertyFilter |
getPropertyFilter()
Returns the property filter configured. |
|
BeanMethodFinder |
getReaderMethodFinder()
Returns the finder configured to find the property getter methods of a source JavaBean. |
|
BeanMethodCollector |
getSetterMethodCollector()
Returns the collector configured to collect the property setter methods of a target JavaBean. |
|
Transformable |
getTransformer()
Returns the transformer used by this bean populator. |
|
BeanPopulator |
initBeanPopulationExceptionHandler(BeanPopulationExceptionHandler beanPopulationExceptionHandler)
Used to configure a handler to handle any exception thrown. |
|
BeanPopulator |
initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig baseConfig)
Used to conveniently provide all the other configuration options as a single configuration object. |
|
BeanPopulator |
initBeanSourceHandler(BeanSourceHandler beanSourceHandler)
Used to configure a call-back (to produce whatever side-effects deemed necessary) that is invoked after the property value has been retrieved from the source bean, but before being propagated across to the target bean. |
|
BeanPopulator |
initDebug(boolean debug)
Used to control whether debug messages should be logged. |
|
BeanPopulator |
initDetailedPropertyFilter(DetailedPropertyFilter detailedPropertyFilter)
Used to configure a detailed prperty filter (which has more context information) to determine whether a specific property should be propagated from the source bean to the target bean. |
|
BeanPopulator |
initPropertyFilter(PropertyFilter propertyFilter)
Used to configure a property filter to determine whether a specific property should be propagated from a source bean to a target bean. |
|
BeanPopulator |
initReaderMethodFinder(BeanMethodFinder readerMethodFinder)
Used to configure a finder to find the property getter methods of a source JavaBean. |
|
BeanPopulator |
initSetterMethodCollector(BeanMethodCollector setterMethodCollector)
Used to configure a collector to collect the property setter methods of a target JavaBean. |
|
BeanPopulator |
initTransformer(Transformable transformer)
Used to configure a transformer to transform a property value read from a source JavaBean into a value to be to set the corresponding property of a target JavaBean. |
|
private Object |
invokeMethodAsPrivileged(Object target,
Method method,
Object[] args)
Invoke the given method as a privileged action, if necessary. |
|
boolean |
isDebug()
Returns true if debug message logging is on; false otherwise. |
|
|
populate()
Propagates properties from the source JavaBean to the target JavaBean. |
|
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 |
|---|
public static final BeanPopulator.Factory factory
private final org.apache.log4j.Logger log
private final Object fromBean
private final Object toBean
private BeanPopulatorBaseConfig baseConfig
private Transformable transformer
| Constructor Detail |
|---|
public BeanPopulator(Object fromBean,
Object toBean)
fromBean - from beantoBean - to bean| Method Detail |
|---|
private BeanTransformerSpi getBeanTransformerSpi()
private void processSetterMethod(Method setterMethod)
setterMethod - a specific method of the toBean
private <T> void doit(Method setterMethod,
Method readerMethod,
Class<T> paramType,
String propertyName)
private Object invokeMethodAsPrivileged(Object target,
Method method,
Object[] args)
public Transformable getTransformer()
BeanPopulatorSpi
getTransformer in interface BeanPopulatorSpipublic BeanPopulator initTransformer(Transformable transformer)
BeanPopulatorSpi
initTransformer in interface BeanPopulatorSpitransformer - is used to transform every property value read from a source JavaBean
into a value to be to set the corresponding property of a target JavaBean.
public <T> T populate()
BeanPopulatorSpi
populate in interface BeanPopulatorSpipublic BeanPopulator initPropertyFilter(PropertyFilter propertyFilter)
BeanPopulatorBaseSpi
initPropertyFilter in interface BeanPopulatorBaseSpiinitPropertyFilter in interface BeanPopulatorSpipropertyFilter - is similar to DetailedPropertyFilter but with a simpler API
that is used to control whether a specific property should be propagated
from a source bean to a target bean.
public BeanPopulator initBeanSourceHandler(BeanSourceHandler beanSourceHandler)
BeanPopulatorBaseSpi
initBeanSourceHandler in interface BeanPopulatorBaseSpiinitBeanSourceHandler in interface BeanPopulatorSpibeanSourceHandler - can be used to act as a call-back
(to produce whatever side-effects deemed necessary)
after the property value has been retrieved from the source bean,
but before being propagated across to the target bean.
public BeanPopulator initDebug(boolean debug)
BeanPopulatorBaseSpi
initDebug in interface BeanPopulatorBaseSpiinitDebug in interface BeanPopulatorSpipublic BeanPopulator initDetailedPropertyFilter(DetailedPropertyFilter detailedPropertyFilter)
BeanPopulatorBaseSpi
initDetailedPropertyFilter in interface BeanPopulatorBaseSpiinitDetailedPropertyFilter in interface BeanPopulatorSpidetailedPropertyFilter - is used to control whether a specific property
should be propagated from the source bean to the target bean.
public BeanPopulator initReaderMethodFinder(BeanMethodFinder readerMethodFinder)
BeanPopulatorBaseSpi
initReaderMethodFinder in interface BeanPopulatorBaseSpiinitReaderMethodFinder in interface BeanPopulatorSpireaderMethodFinder - can be used to find the property getter methods of a source JavaBean.
public BeanPopulator initSetterMethodCollector(BeanMethodCollector setterMethodCollector)
BeanPopulatorBaseSpi
initSetterMethodCollector in interface BeanPopulatorBaseSpiinitSetterMethodCollector in interface BeanPopulatorSpisetterMethodCollector - can be used to collect the property setter methods of a target JavaBean.
public BeanPopulator initBeanPopulationExceptionHandler(BeanPopulationExceptionHandler beanPopulationExceptionHandler)
BeanPopulatorBaseSpi
initBeanPopulationExceptionHandler in interface BeanPopulatorBaseSpiinitBeanPopulationExceptionHandler in interface BeanPopulatorSpibeanPopulationExceptionHandler - can be used to handle any exception thrown.
public BeanPopulator initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig baseConfig)
BeanPopulatorBaseSpi
initBeanPopulatorBaseConfig in interface BeanPopulatorBaseSpiinitBeanPopulatorBaseConfig in interface BeanPopulatorSpibaseConfig - is used to conveniently group all the other initializable options into a single unit.
public PropertyFilter getPropertyFilter()
BeanPopulatorBaseSpi
getPropertyFilter in interface BeanPopulatorBaseSpipublic BeanPopulationExceptionHandler getBeanPopulationExceptionHandler()
BeanPopulatorBaseSpi
getBeanPopulationExceptionHandler in interface BeanPopulatorBaseSpipublic BeanPopulatorBaseConfig getBeanPopulatorBaseConfig()
initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig)
needs to be invoked to keep the configuration in sync.
getBeanPopulatorBaseConfig in interface BeanPopulatorBaseSpipublic BeanSourceHandler getBeanSourceHandler()
BeanPopulatorBaseSpi
getBeanSourceHandler in interface BeanPopulatorBaseSpipublic boolean isDebug()
BeanPopulatorBaseSpi
isDebug in interface BeanPopulatorBaseSpipublic DetailedPropertyFilter getDetailedPropertyFilter()
BeanPopulatorBaseSpi
getDetailedPropertyFilter in interface BeanPopulatorBaseSpipublic BeanMethodFinder getReaderMethodFinder()
BeanPopulatorBaseSpi
getReaderMethodFinder in interface BeanPopulatorBaseSpipublic BeanMethodCollector getSetterMethodCollector()
BeanPopulatorBaseSpi
getSetterMethodCollector in interface BeanPopulatorBaseSpi
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||