updated test cases for spring 2006 schema, and major debug of locking system
[vamsas.git] / src / org / vamsas / test / simpleclient / ClientDoc.java
index a560c38..cc56e8c 100644 (file)
@@ -209,14 +209,32 @@ public class ClientDoc {
   public VamsasArchiveReader getReader() {
     return reader;
   }
+  private void _finalize() {
+    log.debug("finalizing clientDoc");
+    if (doc!=null) {
+      doc = null;
+    }
+    if (_VamsasRoots!=null) {
+      for (int i=0; i<_VamsasRoots.length; i++)
+        _VamsasRoots[i]=null;
+      _VamsasRoots=null;
+       
+    }
+      
+    if (reader!=null) {
+      log.debug("Closing and removing reader reference");
+      reader.close();
+      reader=null;
+    }
+    if (iohandler!=null) {
+      log.debug("Removing ioHandler reference.");
+      iohandler.cancelArchive();
+      iohandler=null;
+    }
+  }
   protected void finalize() throws Throwable {
+    _finalize();
     super.finalize();
-    //if (reader!=null)
-    //  reader.close();
-    //reader=null;
-//    if (iohandler!=null) {
-//      iohandler.cancelArchive(); // otherwise the original may be overwritten.
-//    }
   }
   private java.util.Hashtable objrefs=null;
   
@@ -303,5 +321,29 @@ public class ClientDoc {
         log.debug("Returning null Vobject reference for id "+ids[i].getId());
     return vo;
   }
+  protected void updateDocumentRoots() {
+    if (doc==null) {
+      log.error("updateDocumentRoots called on null document. Probably an implementation error.");
+      return;
+    }
+    if (isModified) {
+      if (_VamsasRoots!=null) {
+        doc.setVAMSAS(_VamsasRoots);
+        _VamsasRoots=null;
+      }
+    }
+  }
+  /**
+   * tell vamsas client to close the document and reset the object. Once closed, nothing can be done with the object.
+   *
+   */
+  public void closeDoc() {
+    if (doc!=null) {
+      log.debug("Closing open document.");
+      _finalize();
+    } else {
+      log.warn("Ignoring closeDoc on invalid document.");
+    }
+  }
   
 }
\ No newline at end of file