introduced hashCode based object change detection that works (see vamsas.test.example...
[vamsas.git] / src / uk / ac / vamsas / client / VorbaXmlBinder.java
index 12543f2..dadd3fa 100644 (file)
@@ -25,7 +25,6 @@ import org.exolab.castor.xml.UnmarshalListener;
 import org.exolab.castor.xml.Unmarshaller;
 import org.exolab.castor.xml.ValidationException;
 
-import uk.ac.vamsas.client.utils.ChecksummedReader;
 import uk.ac.vamsas.objects.core.VamsasDocument;
 /**
  * Implements the Vamsas Vobject ID machinery for translating 
@@ -43,14 +42,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
   private final Hashtable oldobjhashes;
   private final Hashtable objrefs;
   private final Vector updatedobjs; // not yet used elswhere ?
-  private final ChecksummedReader inStream;
-  public VorbaXmlBinder(IVorbaIdFactory vorbafactory, Vector obj, Hashtable objrefs, Hashtable oldobjhashes, Vector updatedobjs) {
-    this(vorbafactory, obj, objrefs, oldobjhashes, updatedobjs, null);
-
-  }
-
-  public VorbaXmlBinder(IVorbaIdFactory vorbafactory2, Vector unrefedObj, Hashtable objrefs2, Hashtable oldobjhashes, Vector updatedObj, ChecksummedReader ckedInstream) {
-    this.inStream = ckedInstream;
+  public VorbaXmlBinder(IVorbaIdFactory vorbafactory2, Vector unrefedObj, Hashtable objrefs2, Hashtable oldobjhashes, Vector updatedObj) {
     this.vorbafactory = vorbafactory2;
     this.obj = unrefedObj;
     this.objrefs = objrefs2;
@@ -90,8 +82,6 @@ public class VorbaXmlBinder implements UnmarshalListener {
   public void initialized(Object object) {
     if (object instanceof Vobject) {
       Vobject nobj = (Vobject) object;
-      if (nobj.isRegisterable() && nobj.___id_field!=null && inStream!=null)
-        nobj.__setInitHash(inStream.getChecksum()); // record start tag position
     }
   }
 
@@ -107,8 +97,6 @@ public class VorbaXmlBinder implements UnmarshalListener {
       nobj.set__stored_in_document(true);
       try {
         if (nobj.isRegisterable() && nobj.___id_field!=null) {
-          if (inStream!=null)
-            nobj.__setFinalHash(inStream.getChecksum()); // compute LHash as difference between end and start tag positions
           VorbaId nobj_id=null;
           // look for the id field (should be an NCName string)
           nobj.__vorba = vorbafactory;
@@ -131,8 +119,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
             // TODO: add to list of objects without a valid vorbaId
             obj.add(nobj);
           }
-          nobj.doHash(); // TODO: DECIDE IF WE NEED TO DO THIS STILL: THIS DOESNT WORK! updates detected by comparing with last hash when marshalling
-
+          nobj.doHash(); // updates detected by comparing with last hash when marshalling
           // check to see if new object was present in old object hash
           if (nobj_id!=null) {
             if (oldobjhashes.containsKey(nobj_id)) {
@@ -140,7 +127,6 @@ public class VorbaXmlBinder implements UnmarshalListener {
               if (oldhash.isUpdated(nobj)) {
                 // mark the object as updated in this document read.
                 nobj.set__updated_since_last_read(true);
-                oldobjhashes.put(nobj_id, new Vobjhash(nobj));
                 updatedobjs.addElement(nobj);
               }
             } else {
@@ -242,14 +228,13 @@ public class VorbaXmlBinder implements UnmarshalListener {
     final VorbaIdFactory vorbafactory = factory;
     final Vector unrefedObj =  new Vector();
     final Vector updatedObj = new Vector();
-    ChecksummedReader ckedInstream = new ChecksummedReader(instream);
-    unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes,updatedObj, ckedInstream));
+    unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes,updatedObj));
     // Call the unmarshaller.
     try {
       while (instream.ready()) {
         // TODO: mark objects in oobjhash prior to unmarshalling, to detect when objects have been lost through an update.
         //tohere
-        Object obj = unmarshaller.unmarshal(ckedInstream);
+        Object obj = unmarshaller.unmarshal(instream);
         boolean sync=ensure_references(unrefedObj, objrefs);
         if (!(obj instanceof Vobject))
           return null;