net.sf.beanlib.hibernate
Class HibernateBeanReplicator

java.lang.Object
  extended by net.sf.beanlib.hibernate.HibernateBeanReplicator
All Implemented Interfaces:
net.sf.beanlib.spi.BeanPopulatorBaseSpi
Direct Known Subclasses:
Hibernate3BeanReplicator

@NotThreadSafe
public abstract class HibernateBeanReplicator
extends java.lang.Object
implements net.sf.beanlib.spi.BeanPopulatorBaseSpi

Hibernate Bean Replicator.

This class can be used to conveniently replicate Hibernate objects that follow the JavaBean getter/setter convention on a best attempt basis. The replication is typically recursive in that the whole object graph of the input object is replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary. However, the exact behavior of the replication process including

can be controlled and/or supplemented by the client code via various options:

  1. All the configurable options of BeanPopulatorBaseSpi are available, as the replication of JavaBean properties inevitably involves bean population.
  2. If the default property filter HibernatePropertyFilter is used,

  3. For anything else that the existing implementation fails to transform, client can provide one or multiple custom transformer factories via initCustomTransformerFactory(net.sf.beanlib.spi.CustomBeanTransformerSpi.Factory...).

This was originally the base class for both the Hibernate 2.x and Hibernate 3.x replicators, but now Hibernate 2 is no longer supported.

Author:
Joe D. Velopar
See Also:
CustomBeanTransformerSpi, Hibernate3BeanReplicator

Constructor Summary
protected HibernateBeanReplicator(net.sf.beanlib.spi.BeanTransformerSpi hibernateBeanTransformer)
          You probably want to construct a Hibernate3BeanReplicator directly instead of this ?
 
Method Summary
<T> T
copy(java.lang.Object from, java.lang.Class<T> toClass)
          Returns an instance of the given class with values copied from the given object.
<T> T
copy(T from)
          Returns a copy of the given object.
<T> T
deepCopy(java.lang.Object from, java.lang.Class<T> toClass)
          Convenient method to deep copy the given object to an instance of the given class using the default behavior.
<T> T
deepCopy(T from)
          Convenient method to deep copy the given object using the default behavior.
 net.sf.beanlib.spi.BeanPopulationExceptionHandler getBeanPopulationExceptionHandler()
           
 net.sf.beanlib.spi.BeanPopulatorBaseConfig getBeanPopulatorBaseConfig()
          Notes if the returned base config is modified, a subsequent BeanPopulator.initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig) needs to be invoked to keep the configuration in sync.
 net.sf.beanlib.spi.BeanSourceHandler getBeanSourceHandler()
           
 net.sf.beanlib.spi.DetailedPropertyFilter getDetailedPropertyFilter()
           
 HibernatePropertyFilter getHibernatePropertyFilter()
          Convenient method to return the current property filter as HibernatePropertyFilter if the type matches; or null otherwise.
 net.sf.beanlib.spi.PropertyFilter getPropertyFilter()
          Returns the property filter that is used to control what properties get propagated across and what get skipped.
 net.sf.beanlib.spi.BeanMethodFinder getReaderMethodFinder()
           
 net.sf.beanlib.spi.BeanMethodCollector getSetterMethodCollector()
           
 HibernateBeanReplicator initBeanPopulationExceptionHandler(net.sf.beanlib.spi.BeanPopulationExceptionHandler beanPopulationExceptionHandler)
           
 net.sf.beanlib.spi.BeanPopulatorBaseSpi initBeanPopulatorBaseConfig(net.sf.beanlib.spi.BeanPopulatorBaseConfig baseConfig)
          Used to conveniently provide the bean population related configuration options as a single configuration object.
 HibernateBeanReplicator initBeanSourceHandler(net.sf.beanlib.spi.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.
 HibernateBeanReplicator initCustomTransformerFactory(net.sf.beanlib.spi.CustomBeanTransformerSpi.Factory... customBeanTransformerFactories)
          Initializes with one or more custom bean transformer factories that will be chained together.
 HibernateBeanReplicator initDebug(boolean debug)
          Used to control whether debug messages should be logged.
 HibernateBeanReplicator initDetailedPropertyFilter(net.sf.beanlib.spi.DetailedPropertyFilter detailedPropertyFilter)
          Note this method is only applicable if either the copy(Object) or copy(Object, Class) is directly invoked, and is ignored otherwise (ie ignored if deep or shallow copy is invoked instead).
 HibernateBeanReplicator initPropertyFilter(net.sf.beanlib.spi.PropertyFilter propertyFilter)
          Note this method is only applicable if either the copy(Object) or copy(Object, Class) is directly invoked, and is ignored otherwise (ie ignored if deep or shallow copy is invoked instead).
 HibernateBeanReplicator initReaderMethodFinder(net.sf.beanlib.spi.BeanMethodFinder readerMethodFinder)
          Used to configure a finder to find the property getter methods of a source JavaBean.
 HibernateBeanReplicator initSetterMethodCollector(net.sf.beanlib.spi.BeanMethodCollector setterMethodCollector)
          Used to configure a collector to collect the property setter methods of a target JavaBean.
 boolean isDebug()
           
<T> T
shallowCopy(java.lang.Object from, java.lang.Class<T> toClass)
          Convenient method to shallow copy the given object to an instance of the given class using the default behavior.
<T> T
shallowCopy(T from)
          Convenient method to shallow copy the given object using the default behavior.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateBeanReplicator

protected HibernateBeanReplicator(net.sf.beanlib.spi.BeanTransformerSpi hibernateBeanTransformer)
You probably want to construct a Hibernate3BeanReplicator directly instead of this ?

Method Detail

copy

public final <T> T copy(T from)
Returns a copy of the given object. The exact behavior of the copy depends on how the replicator has been configured via the init* methods.

In the case when none of the init* methods is invoked, this method behaves like deepCopy(Object), but without using the HibernatePropertyFilter.

Type Parameters:
T - type of the given object.
Parameters:
from - given object.

copy

public final <T> T copy(java.lang.Object from,
                        java.lang.Class<T> toClass)
Returns an instance of the given class with values copied from the given object. The exact behavior of the copy depends on how the replicator has been configured via the init* methods.

In the case when none of the init* methods is invoked, this method behaves exactly like deepCopy(Object, Class).

Type Parameters:
T - type of the given object.
Parameters:
from - given object.
toClass - target class of the returned object.

deepCopy

public final <T> T deepCopy(T from)
Convenient method to deep copy the given object using the default behavior.

Notes:

Type Parameters:
T - from object type.
Parameters:
from - given object to be copied.
Returns:
a deep clone of the from object.

deepCopy

public final <T> T deepCopy(java.lang.Object from,
                            java.lang.Class<T> toClass)
Convenient method to deep copy the given object to an instance of the given class using the default behavior.

Notes:

Type Parameters:
T - to object type.
Parameters:
from - given object to be copied.
toClass - target class of the returned object.
Returns:
an instance of the given class with values deeply copied from the given object.

shallowCopy

public final <T> T shallowCopy(T from)
Convenient method to shallow copy the given object using the default behavior. Shallow copy means skipping those properties that are of type collection, map or under a package that doesn't start with "java.".

Notes:

Type Parameters:
T - from object type.
Parameters:
from - given object to be copied.
Returns:
a shallow clone of the from object.
See Also:
HibernatePropertyFilter

shallowCopy

public final <T> T shallowCopy(java.lang.Object from,
                               java.lang.Class<T> toClass)
Convenient method to shallow copy the given object to an instance of the given class using the default behavior. Shallow copy means skipping those properties that are of type collection, map or under a package that doesn't start with "java.".

Notes:

Type Parameters:
T - to object type.
Parameters:
from - given object to be copied.
Returns:
an instance of the given class with values shallow copied from the given object.

initCustomTransformerFactory

public final HibernateBeanReplicator initCustomTransformerFactory(net.sf.beanlib.spi.CustomBeanTransformerSpi.Factory... customBeanTransformerFactories)
Initializes with one or more custom bean transformer factories that will be chained together.

See Also:
ChainedCustomBeanTransformer

getPropertyFilter

public final net.sf.beanlib.spi.PropertyFilter getPropertyFilter()
Returns the property filter that is used to control what properties get propagated across and what get skipped.

Specified by:
getPropertyFilter in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

initPropertyFilter

public final HibernateBeanReplicator initPropertyFilter(net.sf.beanlib.spi.PropertyFilter propertyFilter)
Note this method is only applicable if either the copy(Object) or copy(Object, Class) is directly invoked, and is ignored otherwise (ie ignored if deep or shallow copy is invoked instead).

Specified by:
initPropertyFilter in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
propertyFilter - is similar to DetailedPropertyFilter but with a simpler API that is used to control whether a specific JavaBean property should be propagated from a source bean to a target bean.
Returns:
the current object (ie this) for method chaining purposes.

initDetailedPropertyFilter

public final HibernateBeanReplicator initDetailedPropertyFilter(net.sf.beanlib.spi.DetailedPropertyFilter detailedPropertyFilter)
Note this method is only applicable if either the copy(Object) or copy(Object, Class) is directly invoked, and is ignored otherwise (ie ignored if deep or shallow copy is invoked instead).

Specified by:
initDetailedPropertyFilter in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
detailedPropertyFilter - is used to control whether a specific JavaBean property should be propagated from the source bean to the target bean.
Returns:
the current object (ie this) for method chaining purposes.

initBeanSourceHandler

public final HibernateBeanReplicator initBeanSourceHandler(net.sf.beanlib.spi.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.

Specified by:
initBeanSourceHandler in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
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.
Returns:
the current object (ie this) for method chaining purposes.

initDebug

public final HibernateBeanReplicator initDebug(boolean debug)
Used to control whether debug messages should be logged.

Specified by:
initDebug in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Returns:
the current object (ie this) for method chaining purposes.

initReaderMethodFinder

public final HibernateBeanReplicator initReaderMethodFinder(net.sf.beanlib.spi.BeanMethodFinder readerMethodFinder)
Used to configure a finder to find the property getter methods of a source JavaBean.

Specified by:
initReaderMethodFinder in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
readerMethodFinder - can be used to find the property getter methods of a source JavaBean.
Returns:
the current object (ie this) for method chaining purposes.

initSetterMethodCollector

public final HibernateBeanReplicator initSetterMethodCollector(net.sf.beanlib.spi.BeanMethodCollector setterMethodCollector)
Used to configure a collector to collect the property setter methods of a target JavaBean.

Specified by:
initSetterMethodCollector in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
setterMethodCollector - can be used to collect the property setter methods of a target JavaBean.
Returns:
the current object (ie this) for method chaining purposes.

initBeanPopulationExceptionHandler

public HibernateBeanReplicator initBeanPopulationExceptionHandler(net.sf.beanlib.spi.BeanPopulationExceptionHandler beanPopulationExceptionHandler)
Specified by:
initBeanPopulationExceptionHandler in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

initBeanPopulatorBaseConfig

public net.sf.beanlib.spi.BeanPopulatorBaseSpi initBeanPopulatorBaseConfig(net.sf.beanlib.spi.BeanPopulatorBaseConfig baseConfig)
Used to conveniently provide the bean population related configuration options as a single configuration object.

Specified by:
initBeanPopulatorBaseConfig in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi
Parameters:
baseConfig - is used to conveniently group all the other initializable options into a single unit.
Returns:
the current object (ie this) for method chaining purposes.

getBeanPopulationExceptionHandler

public net.sf.beanlib.spi.BeanPopulationExceptionHandler getBeanPopulationExceptionHandler()
Specified by:
getBeanPopulationExceptionHandler in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getBeanPopulatorBaseConfig

public net.sf.beanlib.spi.BeanPopulatorBaseConfig getBeanPopulatorBaseConfig()
Notes if the returned base config is modified, a subsequent BeanPopulator.initBeanPopulatorBaseConfig(BeanPopulatorBaseConfig) needs to be invoked to keep the configuration in sync.

Specified by:
getBeanPopulatorBaseConfig in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getBeanSourceHandler

public net.sf.beanlib.spi.BeanSourceHandler getBeanSourceHandler()
Specified by:
getBeanSourceHandler in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

isDebug

public boolean isDebug()
Specified by:
isDebug in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getDetailedPropertyFilter

public net.sf.beanlib.spi.DetailedPropertyFilter getDetailedPropertyFilter()
Specified by:
getDetailedPropertyFilter in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getReaderMethodFinder

public net.sf.beanlib.spi.BeanMethodFinder getReaderMethodFinder()
Specified by:
getReaderMethodFinder in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getSetterMethodCollector

public net.sf.beanlib.spi.BeanMethodCollector getSetterMethodCollector()
Specified by:
getSetterMethodCollector in interface net.sf.beanlib.spi.BeanPopulatorBaseSpi

getHibernatePropertyFilter

public HibernatePropertyFilter getHibernatePropertyFilter()
Convenient method to return the current property filter as HibernatePropertyFilter if the type matches; or null otherwise.



Copyright © 2009. All Rights Reserved.