public abstract class AbstractCloneStrategy extends Object implements CloneStrategy
CloneStrategy
implementation providing functionality which is
common across class and field access mechanisms.Constructor and Description |
---|
AbstractCloneStrategy() |
Modifier and Type | Method and Description |
---|---|
boolean |
canClone(Class<?> clazz)
True if this implementor can clone the given class
|
<T> T |
clone(T obj,
CloneDriver context,
IdentityHashMap<Object,Object> referencesToReuse,
long stackDepth)
Performs a clone.
|
protected abstract <W> ClassModel<W> |
getClassModel(Class<W> clazz)
Obtain a ClassModel instance for the given class
|
protected abstract <T> Object |
getFieldValue(T obj,
FieldModel<T> f)
Method to retrieve the value of a particular field
|
protected <T> T |
handleArray(T origFieldValue,
CloneDriver context,
IdentityHashMap<Object,Object> visited,
long stackDepth)
Clone an array
|
protected <T> void |
handleCloneField(T obj,
T copy,
CloneDriver driver,
FieldModel<T> f,
IdentityHashMap<Object,Object> referencesToReuse,
long stackDepth)
Clone a Field
|
protected abstract <T> void |
handleClonePrimitiveField(T obj,
T copy,
CloneDriver driver,
FieldModel<T> f,
IdentityHashMap<Object,Object> referencesToReuse)
Method should clone the given primitive field
|
protected abstract <T> void |
handleTransientField(T copy,
FieldModel<T> f)
Implementations should ensure that transient fields are left with the correct default (unset) value
|
void |
initialiseFor(Class<?>... classes) |
abstract <T> T |
newInstance(Class<T> c)
Create a new, uninitialised instance of the given class (if supported).
|
protected <T> T |
performCloneForCloneableMethod(T object,
CloneDriver context)
Helper method for performing cloning for objects of classes implementing java.lang.Cloneable
|
protected abstract <T> void |
putFieldValue(T obj,
FieldModel<T> f,
Object value)
Put the given value into the target field
|
public AbstractCloneStrategy()
public abstract <T> T newInstance(Class<T> c)
CloneImplementor
newInstance
in interface CloneImplementor
T
- The type of the instance to be constructedc
- Type to create instance ofpublic boolean canClone(Class<?> clazz)
CloneImplementor
canClone
in interface CloneImplementor
clazz
- The classpublic <T> T clone(T obj, CloneDriver context, IdentityHashMap<Object,Object> referencesToReuse, long stackDepth)
CloneImplementor
clone
in interface CloneImplementor
T
- The type of the object to be clonedobj
- Object to clonecontext
- The CloneDriver that initiated the requestreferencesToReuse
- Any references for objects already cloned to ensure reference
identity is preservedstackDepth
- The number of objects already cloned in the current data structureprotected <T> T performCloneForCloneableMethod(T object, CloneDriver context)
T
- The type being copiedobject
- The object to be cloned.context
- The CloneDriver to be usedprotected abstract <W> ClassModel<W> getClassModel(Class<W> clazz)
W
- The type of classclazz
- Class to modelprotected <T> T handleArray(T origFieldValue, CloneDriver context, IdentityHashMap<Object,Object> visited, long stackDepth)
T
- The type being copiedorigFieldValue
- The original valuecontext
- The CloneDrivervisited
- Used for tracking objects that have already been seenstackDepth
- The current depth of the stack - used to switch from recursion to iteration if the stack grows too deep.protected <T> void handleCloneField(T obj, T copy, CloneDriver driver, FieldModel<T> f, IdentityHashMap<Object,Object> referencesToReuse, long stackDepth)
T
- The type containing the field being clonedobj
- The original objectcopy
- The destination objectdriver
- The CloneDriverf
- The FieldModel for the target fieldreferencesToReuse
- Used for tracking objects that have already been seenstackDepth
- The current depth of the stack - used to switch from recursion to iteration if the stack grows too deep.protected abstract <T> void handleTransientField(T copy, FieldModel<T> f)
T
- The type containing the fieldcopy
- The target objectf
- The FieldModel for the Field that should stay as a defaultprotected abstract <T> void handleClonePrimitiveField(T obj, T copy, CloneDriver driver, FieldModel<T> f, IdentityHashMap<Object,Object> referencesToReuse)
T
- The type being copiedobj
- Source objectcopy
- The target objectdriver
- The CloneDriver to usef
- The FieldModel for the Field that should stay as a defaultreferencesToReuse
- Used for tracking objects that have already been seenprotected abstract <T> Object getFieldValue(T obj, FieldModel<T> f)
T
- The type containing the fieldobj
- Source objectf
- The FieldModel for the Field that should stay as a defaultprotected abstract <T> void putFieldValue(T obj, FieldModel<T> f, Object value)
T
- The type containing the fieldobj
- Source objectf
- The FieldModel for the Field that should stay as a defaultvalue
- The value to putpublic void initialiseFor(Class<?>... classes)
initialiseFor
in interface CloneStrategy
classes
- Classes to initialise forCopyright © 2010–2018 Jadira Systems. All rights reserved.