try to set sessionmodified flag if the client document was actually modified.
[vamsas.git] / src / uk / ac / vamsas / client / VorbaXmlBinder.java
index 9a94047..9462494 100644 (file)
@@ -41,14 +41,13 @@ public class VorbaXmlBinder implements UnmarshalListener {
   private final Vector obj;
   private final Hashtable oldobjhashes;
   private final Hashtable objrefs;
-  private final Vector updatedobjs;
-
-  public VorbaXmlBinder(IVorbaIdFactory vorbafactory, Vector obj, Hashtable objrefs, Hashtable oldobjhashes, Vector updatedobjs) {
-    this.vorbafactory = vorbafactory;
-    this.obj = obj;
-    this.objrefs = objrefs;
+  private final Vector updatedobjs; // not yet used elswhere ?
+  public VorbaXmlBinder(IVorbaIdFactory vorbafactory2, Vector unrefedObj, Hashtable objrefs2, Hashtable oldobjhashes, Vector updatedObj) {
+    this.vorbafactory = vorbafactory2;
+    this.obj = unrefedObj;
+    this.objrefs = objrefs2;
     this.oldobjhashes = oldobjhashes;
-    this.updatedobjs = updatedobjs;
+    this.updatedobjs = updatedObj;
   }
 
   /*
@@ -57,6 +56,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
    * @see org.exolab.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object)
    */
   public void attributesProcessed(Object object) {
+
   }
 
   /*
@@ -80,6 +80,9 @@ public class VorbaXmlBinder implements UnmarshalListener {
    * @see org.exolab.castor.xml.UnmarshalListener#initialized(java.lang.Object)
    */
   public void initialized(Object object) {
+    if (object instanceof Vobject) {
+      Vobject nobj = (Vobject) object;
+    }
   }
 
   /*
@@ -116,7 +119,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
             // TODO: add to list of objects without a valid vorbaId
             obj.add(nobj);
           }
-          nobj.doHash();
+          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)) {
@@ -124,14 +127,12 @@ 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 {
               // object has no entry in the oldhashvalue list but
               // there is a valid vorbaId so
               nobj.set__added_since_last_read(true);
-
             }
             // and record the just-unmarshalled hash value
             oldobjhashes.put(nobj_id, new Vobjhash(nobj));
@@ -166,7 +167,8 @@ public class VorbaXmlBinder implements UnmarshalListener {
     if (doc.__vorba==null)
       doc.__vorba = vorba;
     doc.__ensure_instance_ids(); // this may take a while. Do we allow for cyclic references ? 
-    doc.marshal(outstream);
+    Marshaller mshl = new Marshaller(outstream);
+    mshl.marshal(doc);
 
   }
   /**
@@ -215,8 +217,9 @@ public class VorbaXmlBinder implements UnmarshalListener {
     Unmarshaller unmarshaller = new Unmarshaller(root);
     unmarshaller.setIDResolver(new IDResolver() {
       public Object resolve(String id) {
+        // TODO: allow for external ID resolution
         VorbaXmlBinder.log.warn("Warning - id " + id
-            + " is not found in the Vamsas XML!");
+            + " is not found in the Vamsas XML! (TODO: Ignore if this is a forward reference!)");
         return null;
       }
     });
@@ -227,7 +230,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
     final VorbaIdFactory vorbafactory = factory;
     final Vector unrefedObj =  new Vector();
     final Vector updatedObj = new Vector();
-    unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes, updatedObj));
+    unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes,updatedObj));
     // Call the unmarshaller.
     try {
       while (instream.ready()) {