uka.patch
Class PatchAdapter

java.lang.Object
  extended byuka.patch.PatchAdapter
Direct Known Subclasses:
PatchAdapterImpl

public abstract class PatchAdapter
extends java.lang.Object

Monitors an arbitrary patchable object for changes. A patch adapter can be used to create a patch from a changed object and apply this patch to a patch adapter of a corresponding object to redo the same changes to the second object.


Constructor Summary
PatchAdapter()
           
 
Method Summary
abstract  void applyPatch(PatchReader reader)
          Applies a patch read from the passed input stream to the own monitored object.
abstract  void createPatch(AbstractPatchWriter writer)
           
abstract  AbstractPatchWriter createPatch(MarshalStream marshal)
          Compares the monitored object of this patch adapter with its backup copy.
abstract  PatchReader createPatchReader(UnmarshalStream in)
           
abstract  ObjectSpace getObjectSpace()
          Returns the object space of original objects.
abstract  java.lang.Object getRoot()
           
static PatchAdapter newInstance(java.lang.Object root)
          Creates a new patch adapter for the specified object.
abstract  void updateAfterApplyPatch()
           
abstract  void updateAfterCreatePatch()
           
abstract  void updateAfterDistributionUpdate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatchAdapter

public PatchAdapter()
Method Detail

newInstance

public static PatchAdapter newInstance(java.lang.Object root)
                                throws java.io.IOException

Creates a new patch adapter for the specified object. Changes that are made to the monitored object after the patch adapter is created result in a non-empty patch, when createPatch(MarshalStream) is called. For monitoring changes to an object, the patch adapter internally creates a backup copy of the specified object. During patch creation, the original object is compared with the backup copy.

The passed object and all its referenced objects (object in the transitive hull of the reference relation) must either implement the Patchable interface, or a PatchDescriptor must exist for the object's class.

Throws:
java.io.IOException

getObjectSpace

public abstract ObjectSpace getObjectSpace()
Returns the object space of original objects. This object space is required to create concrete patch writers.

See Also:
AbstractPatchWriter

getRoot

public abstract java.lang.Object getRoot()
Returns:
the object the patch adapter was created for. This object was passed as argument to the call to newInstance(Object).

createPatch

public abstract AbstractPatchWriter createPatch(MarshalStream marshal)
                                         throws java.io.IOException

Compares the monitored object of this patch adapter with its backup copy. The result of the comparison is written to the output stream. Each difference of the original and the backup copy results in a patch record written to the stream. During patch creation, the backup copy is concurrently updated to the current state of the monitored object. When applying createPatch(MarshalStream) twice without modifying the monitored object in between, then the second patch that is created will be the empty patch.

The patch data written to the output stream can be passed to the applyPatch(PatchReader) method of another patch adapter that monitors a corresponding object for applying the patch to this object. A patch adapter that monitors a corresponding object can be created by marshaling this patch adapter in a remote method invocation to another computer, or by deeply cloning this patch adapter. Especially, one can not create a second patch adapter using newInstance(Object) and pass another object of the same class as this patch adapter's monitored object. Such two patch adapters are out of synch and cannot apply each others patches.

Parameters:
marshal - the stream, the patch is written to.
Throws:
java.io.IOException
See Also:
DeepClone

createPatch

public abstract void createPatch(AbstractPatchWriter writer)
                          throws java.io.IOException
Throws:
java.io.IOException

updateAfterCreatePatch

public abstract void updateAfterCreatePatch()
                                     throws java.io.IOException
Throws:
java.io.IOException

updateAfterDistributionUpdate

public abstract void updateAfterDistributionUpdate()
                                            throws java.io.IOException
Throws:
java.io.IOException

updateAfterApplyPatch

public abstract void updateAfterApplyPatch()
                                    throws java.io.IOException
Throws:
java.io.IOException

createPatchReader

public abstract PatchReader createPatchReader(UnmarshalStream in)
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

applyPatch

public abstract void applyPatch(PatchReader reader)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Applies a patch read from the passed input stream to the own monitored object. The patch must be created by a corresponding patch adapter see createPatch(MarshalStream).

Throws:
java.io.IOException
java.lang.ClassNotFoundException