Class ClassCopierBase
java.lang.Object
org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierBase
- All Implemented Interfaces:
ClassCopier
- Direct Known Subclasses:
ClassCopierOrdinaryImpl
A convenient base class for making ClassCopier types.
This takes care of checking oldToNew and updating oldToNew
when an actual copy is made. All subclasses must override
createCopy, which allocates a new result. In some simple
cases, this is all that is needed. In the more complex
cases, doCopy must also be overridden to make the actual copy.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedClassCopierBase(String name) Pass a name here that can be used for toString, hashCode, and equals.protectedClassCopierBase(String name, boolean isReflective) -
Method Summary
Modifier and TypeMethodDescriptionfinal ObjectMake the actual copy of source, using oldToNew to preserve aliasing.protected abstract ObjectcreateCopy(Object source) Create a copy of source.protected ObjectDo the copying of data from source to result.final booleanfinal inthashCode()booleanWe need to know whether this class copier operates via reflection or not, as the reflective class copier must be able to tell when a super class is copied by an incompatible copier.final StringtoString()
-
Constructor Details
-
ClassCopierBase
Pass a name here that can be used for toString, hashCode, and equals. All different ClassCopier classes derived from this base should have unique names. -
ClassCopierBase
-
-
Method Details
-
toString
-
hashCode
public final int hashCode() -
equals
-
copy
Make the actual copy of source, using oldToNew to preserve aliasing. This first checks to see whether source has been previously copied. If so, the value obtained from oldToNew is returned. Otherwise,- createCopy( source ) is called to create a new copy of source.
- The new copy is placed in oldToNew with source as its key.
- doCopy is called to complete the copy.
- Specified by:
copyin interfaceClassCopier- Throws:
ReflectiveCopyException
-
isReflectiveClassCopier
public boolean isReflectiveClassCopier()Description copied from interface:ClassCopierWe need to know whether this class copier operates via reflection or not, as the reflective class copier must be able to tell when a super class is copied by an incompatible copier.- Specified by:
isReflectiveClassCopierin interfaceClassCopier
-
createCopy
Create a copy of source. The copy may or may not be fully initialized. This method must always be overridden in a subclass.- Throws:
ReflectiveCopyException
-
doCopy
protected Object doCopy(Map<Object, Object> oldToNew, Object source, Object result) throws ReflectiveCopyExceptionDo the copying of data from source to result. This just returns the result by default, but it may be overrideden in a subclass. When this method completes, result must be fully initialized.- Throws:
ReflectiveCopyException
-