net.sf.beanlib.provider.replicator
Class ReplicatorTemplate

java.lang.Object
  extended by net.sf.beanlib.provider.replicator.ReplicatorTemplate
Direct Known Subclasses:
ArrayReplicator, BeanReplicator, BeanTransformer, CalendarReplicator, CollectionReplicator, DateReplicator, MapReplicator

public abstract class ReplicatorTemplate
extends Object

A useful base class for the replicator implementations.

Author:
Joe D. Velopar

Field Summary
private  BeanTransformerSpi beanTransformer
           
protected  org.apache.log4j.Logger log
           
 
Constructor Summary
protected ReplicatorTemplate()
           
protected ReplicatorTemplate(BeanTransformerSpi beanTransformer)
           
 
Method Summary
protected
<T> Class<T>
chooseClass(Class<?> fromClass, Class<T> toClass)
          Chooses a target class from the given "from" and "to" classes, giving priority to the one which is more specific whenever possible.
protected  boolean containsTargetCloned(Object from)
           
protected
<T> T
createToInstance(Object from, Class<T> toClass)
          Creates a target instance from either the class of the given "from" object or the given toClass, giving priority to the one which is more specific whenever possible.
protected
<T> T
createToInstance(T from)
          Creates a target instance using the class of the given object.
private
<T> T
createToInstanceWithComparator(Class<T> toClass, Comparator<?> comparator)
           
protected
<T> T
createToInstanceWithComparator(T from, Comparator<?> comparator)
           
protected  CustomBeanTransformerSpi getCustomerBeanTransformer()
           
protected  Object getTargetCloned(Object from)
           
protected
<T> T
newInstanceAsPrivileged(Class<T> c)
          Creates a new instance of the given class via the no-arg constructor, invoking the constructor as a privileged action if it is protected or private.
private
<T> T
newInstanceWithComparatorAsPrivileged(Class<T> c, Comparator<?> comparator)
           
protected  void populateBean(Object fromMember, Object toMember)
           
protected  Object putTargetCloned(Object from, Object to)
           
protected
<T> T
replicate(Object from, Class<T> toClass)
          Replicate the given from object, recursively if necessary, to an instance of the toClass.
protected
<T> T
replicate(T from)
          Replicate the given from object, recursively if necessary.
protected
<T> T
replicateByBeanReplicatable(Object from, Class<T> toClass)
           
protected
<T> T
transform(Object in, Class<T> toClass, PropertyInfo propertyInfo)
           
protected
<T> T
unenhanceObject(T object)
          Returns an equivalent object un-enhanced from the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.log4j.Logger log

beanTransformer

private final BeanTransformerSpi beanTransformer
Constructor Detail

ReplicatorTemplate

protected ReplicatorTemplate(BeanTransformerSpi beanTransformer)

ReplicatorTemplate

protected ReplicatorTemplate()
Method Detail

getCustomerBeanTransformer

protected final CustomBeanTransformerSpi getCustomerBeanTransformer()

replicate

protected <T> T replicate(T from)
Replicate the given from object, recursively if necessary. Currently a property is replicated if it is an instance of Collection, Map, Timestamp, Date, Blob, Hibernate entity, JavaBean, or an array.


replicate

protected <T> T replicate(Object from,
                          Class<T> toClass)
               throws SecurityException
Replicate the given from object, recursively if necessary, to an instance of the toClass. If, however, the from object is an enhanced object and the toClass is the same as the from object's class, the class of the un-enhanced object will be used as the toClass instead of the original toClass. Currently a property is replicated if it is an instance of Collection, Map, Timestamp, Date, Blob, Hibernate entity, JavaBean, or an array.

Throws:
SecurityException

replicateByBeanReplicatable

protected <T> T replicateByBeanReplicatable(Object from,
                                            Class<T> toClass)

createToInstance

protected final <T> T createToInstance(T from)
                            throws InstantiationException,
                                   IllegalAccessException,
                                   SecurityException,
                                   NoSuchMethodException
Creates a target instance using the class of the given object.

Throws:
InstantiationException
IllegalAccessException
SecurityException
NoSuchMethodException

createToInstance

protected <T> T createToInstance(Object from,
                                 Class<T> toClass)
                      throws InstantiationException,
                             IllegalAccessException,
                             SecurityException,
                             NoSuchMethodException
Creates a target instance from either the class of the given "from" object or the given toClass, giving priority to the one which is more specific whenever possible.

Throws:
InstantiationException
IllegalAccessException
SecurityException
NoSuchMethodException

chooseClass

protected final <T> Class<T> chooseClass(Class<?> fromClass,
                                         Class<T> toClass)
Chooses a target class from the given "from" and "to" classes, giving priority to the one which is more specific whenever possible.

Type Parameters:
T - target type
Parameters:
fromClass - from class
toClass - target class
Returns:
the target class if either the "from" class is not assignable to the "to" class, or if the from class is abstract; otherwise, returns the from class.

transform

protected <T> T transform(Object in,
                          Class<T> toClass,
                          PropertyInfo propertyInfo)

populateBean

protected void populateBean(Object fromMember,
                            Object toMember)

createToInstanceWithComparator

protected <T> T createToInstanceWithComparator(T from,
                                               Comparator<?> comparator)
                                    throws SecurityException,
                                           NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

createToInstanceWithComparator

private <T> T createToInstanceWithComparator(Class<T> toClass,
                                             Comparator<?> comparator)
                                  throws SecurityException,
                                         NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

newInstanceAsPrivileged

protected final <T> T newInstanceAsPrivileged(Class<T> c)
                                   throws SecurityException,
                                          NoSuchMethodException,
                                          InstantiationException,
                                          IllegalAccessException
Creates a new instance of the given class via the no-arg constructor, invoking the constructor as a privileged action if it is protected or private.

Parameters:
c - given class
Returns:
a new instance of the given class via the no-arg constructor
Throws:
SecurityException
NoSuchMethodException
InstantiationException
IllegalAccessException

newInstanceWithComparatorAsPrivileged

private <T> T newInstanceWithComparatorAsPrivileged(Class<T> c,
                                                    Comparator<?> comparator)
                                         throws SecurityException,
                                                NoSuchMethodException
Throws:
SecurityException
NoSuchMethodException

containsTargetCloned

protected final boolean containsTargetCloned(Object from)

getTargetCloned

protected final Object getTargetCloned(Object from)

putTargetCloned

protected final Object putTargetCloned(Object from,
                                       Object to)

unenhanceObject

protected <T> T unenhanceObject(T object)
Returns an equivalent object un-enhanced from the given object. By default, the input object is returned. Subclass must override this method to perform any such un-enhancement, if necessary.