net.sf.beanlib.provider.replicator
Class ReplicatorTemplate
java.lang.Object
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
Method Summary |
protected
|
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
|
createToInstance(Object from,
Class<T> toClass)
|
private
|
createToInstanceWithComparator(Class<T> toClass,
Comparator comparator)
|
protected Object |
createToInstanceWithComparator(Object from,
Comparator comparator)
|
protected Object |
getTargetCloned(Object from)
|
protected
|
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
|
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
|
replicate(Object from,
Class<T> toClass)
Recursively replicate, if necessary, the given objects. |
protected
|
replicateByBeanReplicatable(Object from,
Class<T> toClass)
|
protected
|
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 |
log
protected final org.apache.log4j.Logger log
beanTransformer
private final BeanTransformerSpi beanTransformer
ReplicatorTemplate
protected ReplicatorTemplate(BeanTransformerSpi beanTransformer)
ReplicatorTemplate
protected ReplicatorTemplate()
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 classtoClass
- 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)