ensured that hash binding vorbaIds is passed to client document object for vorba...
[vamsas.git] / src / org / vamsas / client / VorbaXmlBinder.java
index c73d158..2cde9d2 100644 (file)
@@ -84,23 +84,20 @@ public class VorbaXmlBinder implements UnmarshalListener {
     if (newobj instanceof Vobject) {
       Vobject nobj = (Vobject) newobj;
       nobj.set__stored_in_document(true);
-      Field fd = null;
       try {
         if (nobj.isRegisterable() && nobj.___id_field!=null) {
           // look for the id field (should be an NCName string)
           nobj.__vorba = vorbafactory;
-          fd = nobj.___id_field;
           // use the Vobject accessor method to avoid unpleasant security exceptions.
           String idstring = nobj.__getInstanceIdField();
           if (idstring!=null) { 
             if (idstring.length() > 0) {
-              if (!objrefs.containsKey(idstring)) {
-                objrefs.put(idstring, nobj);
-                nobj.setVorbaId(VorbaId.newId(idstring));
-              } else {
+              nobj.setVorbaId(VorbaId.newId(idstring));
+              if (objrefs.containsKey(nobj.getVorbaId()) && !objrefs.get(nobj.getVorbaId()).equals(nobj)) {
                 System.err.println("Serious problem : duplicate id '"+idstring+"' found! expect badness.");
                 // TODO: HANDLE duplicate XML ids correctly
               }
+              objrefs.put(nobj.getVorbaId(), nobj);
             } else {
               // add to list of objects without a valid vorbaId
               obj.add(nobj);
@@ -150,9 +147,10 @@ public class VorbaXmlBinder implements UnmarshalListener {
         // forces registration and id field update.
         VorbaId id = o.getVorbaId();
         if (!objrefs.containsKey(id)) {
-          objrefs.put(id.id, o);
+          objrefs.put(id, o);
         } else {
-          throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
+          if (!objrefs.get(id).equals(o))
+            throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
         }
       }
     }
@@ -173,7 +171,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
      * @return null or {(Object) VamsasDocument Vobject, (Object) Hashtable of Vobject references, (Object) Boolean(sync) }
      */
   public static Object[] getVamsasObjects(Reader instream,
-        IVorbaIdFactory factory, Vobject root) {
+        VorbaIdFactory factory, Vobject root) {
       Unmarshaller unmarshaller = new Unmarshaller(root);
       unmarshaller.setIDResolver(new IDResolver() {
         public Object resolve(String id) {
@@ -185,7 +183,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
       Hashtable refbase = new Hashtable();
       Vector unrefed = new Vector();
       final Hashtable objrefs = refbase;
-      final IVorbaIdFactory vorbafactory = factory;
+      final VorbaIdFactory vorbafactory = factory;
       final Vector unrefedObj =  unrefed;
       unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs));
       // Call the unmarshaller.
@@ -195,6 +193,7 @@ public class VorbaXmlBinder implements UnmarshalListener {
           boolean sync=ensure_references(unrefed, objrefs);
           if (!(obj instanceof Vobject))
             return null;
+          vorbafactory.setNewIdHash(objrefs); // update the Document IO Handler's set of vorbaId<>Object bindings.
           return new Object[] { obj, objrefs, new Boolean(sync)};
           }
       } catch (MarshalException e) {