net.sf.beanlib.provider.replicator
Class ReplicatorTemplate

java.lang.Object
  extended by net.sf.beanlib.provider.replicator.ReplicatorTemplate
Direct Known Subclasses:
ArrayReplicator, BeanReplicator, BeanTransformer, 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  Object createToInstance(Object from)
           
protected
<T> T
createToInstance(Object from, Class<T> toClass)
           
private
<T> T
createToInstanceWithComparator(Class<T> toClass, Comparator comparator)
           
protected  Object createToInstanceWithComparator(Object from, Comparator comparator)
           
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  Object replicate(Object from)
           
protected
<T> T
replicate(Object from, Class<T> toClass)
          Recursively replicate, if necessary, the given objects.
protected
<T> T
replicateByBeanReplicatable(Object from, Class<T> toClass)
           
protected
<T> T
transform(Object in, Class<T> toClass, PropertyInfo propertyInfo)
           
 
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

replicate

protected Object replicate(Object from)

replicate

protected <T> T replicate(Object from,
                          Class<T> toClass)
               throws SecurityException
Recursively replicate, if necessary, the given objects. Currently an object 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 Object createToInstance(Object from)
                                 throws InstantiationException,
                                        IllegalAccessException,
                                        SecurityException,
                                        NoSuchMethodException
Throws:
InstantiationException
IllegalAccessException
SecurityException
NoSuchMethodException

createToInstance

protected <T> T createToInstance(Object from,
                                 Class<T> toClass)
                      throws InstantiationException,
                             IllegalAccessException,
                             SecurityException,
                             NoSuchMethodException
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 Object createToInstanceWithComparator(Object 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

getTargetCloned

protected Object getTargetCloned(Object from)

putTargetCloned

protected Object putTargetCloned(Object from,
                                 Object to)