wiki:uka.transport/DeepClone

Implementing methods for deep object cloning

In a transparent local invocation on a remote object it is necessary to create deep clones of the objects passed as arguments. A deep clone of an object is identical to the result of a consecutive marshal/unmarshal operation on that object. Since it is extremely inefficient deeply clone an object by marshaling it into a memory buffer and reading it back, the uka.transport serialization also provides a facility for fast deep object cloning.

The following example shows how to implement the deep cloning part of interface Transportable. Please note that the methods shown below don't have to care about fields of basic type. Because they are based on the cloning mechanism provided by the regular Java API, these fields are already initialized correctly:

//
// Deep clone: Methods and declarations for class TParam
//
public final Object deepClone(uka.transport.DeepClone _helper)
    throws CloneNotSupportedException
{
    Object _copy = clone();
    _helper.add(this, _copy);
    ((TParam) _copy).deepCloneReferences(_helper);
    return _copy;
}

protected void deepCloneReferences(uka.transport.DeepClone _helper)
    throws CloneNotSupportedException
{
    this.objectReference = 
       (java.lang.Object) _helper.doDeepClone(this.objectReference);
}
Last modified 12 years ago Last modified on Aug 22, 2005 9:11:34 AM