refactored generally useful higher level document IO methods to base class.
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 21 Mar 2006 11:58:54 +0000 (11:58 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 21 Mar 2006 11:58:54 +0000 (11:58 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@194 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/client/simpleclient/SimpleDocBinding.java [new file with mode: 0644]
src/org/vamsas/client/simpleclient/SimpleDocument.java

diff --git a/src/org/vamsas/client/simpleclient/SimpleDocBinding.java b/src/org/vamsas/client/simpleclient/SimpleDocBinding.java
new file mode 100644 (file)
index 0000000..da453c2
--- /dev/null
@@ -0,0 +1,134 @@
+package org.vamsas.client.simpleclient;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Vector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.vamsas.client.Vobject;
+import org.vamsas.client.VorbaIdFactory;
+import org.vamsas.client.VorbaXmlBinder;
+import org.vamsas.objects.core.VAMSAS;
+import org.vamsas.objects.core.VamsasDocument;
+import org.vamsas.objects.utils.AppDataReference;
+import org.vamsas.objects.utils.DocumentStuff;
+import org.vamsas.objects.utils.ProvenanceStuff;
+import org.vamsas.objects.utils.document.VersionEntries;
+
+/**
+ * Base class for SimpleClient Vamsas Document Object Manipulation
+ * @author jimp
+ */
+  
+
+public class SimpleDocBinding {
+
+  protected VorbaIdFactory vorba;
+  protected static Log log = LogFactory.getLog(SimpleDocBinding.class);
+
+  /**
+   * @return Returns the vorba.
+   */
+  public VorbaIdFactory getVorba() {
+    return vorba;
+  }
+
+  /**
+   * @param vorba The vorba to set.
+   */
+  public void setVorba(VorbaIdFactory vorba) {
+    this.vorba = vorba;
+  }
+
+  /**
+   * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
+   */
+  public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
+    if (oReader!=null) {
+      // check the factory
+      if (vorba==null) {
+        log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
+        return null;
+      }
+  
+      if (oReader.isValid()) {
+        // Read vamsasDocument.xsd instance
+        InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
+        Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
+        if (unmarsh==null)
+          log.fatal("Couldn't unmarshall document!");
+        
+        Vobject vobjs = (Vobject) unmarsh[0];
+        if (vobjs!=null) { 
+          VamsasDocument doc=(VamsasDocument) vobjs;
+          if (doc!=null)
+            return doc;
+        }
+        log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
+      } else {        
+        // deprecated data handler (vamsas.xsd instance)
+        InputStream vxmlis = oReader.getVamsasXmlStream();
+        if (vxmlis!=null) { // Might be an old vamsas file.
+          BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
+          InputStreamReader vxml = new InputStreamReader(ixml);
+          Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
+          
+          if (unmarsh==null)
+            log.fatal("Couldn't unmarshall document!");
+          
+          VAMSAS root[]= new VAMSAS[] { null};
+          root[0] = (VAMSAS) unmarsh[0]; 
+          
+          if (root[0]==null) {
+            log.debug("Found no VAMSAS object in VamsasXML stream.");
+          } else {
+            log.debug("Making new VamsasDocument from VamsasXML stream.");
+            VamsasDocument doc = DocumentStuff.newVamsasDocument(root, 
+                ProvenanceStuff.newProvenance(
+                    vorba.getUserHandle().getFullName(), 
+                    "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
+            // VAMSAS: decide on 'system' operations provenance form
+            // LATER: implement classes for translating Vorba properties into provenance user fields.
+            // VAMSAS: decide on machine readable info embedding in provenance should be done
+            root[0]=null;
+            root=null;
+            return doc;
+          }
+        }
+      }
+    }
+    // otherwise - there was no valid original document to read.
+    return null;    
+  }
+
+  /**
+   * Extract all jarEntries in an archive referenced by the vamsas document
+   * LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
+   * @param doc
+   * @param oReader
+   * @return array of the subset of JarEntry names that are referenced in doc 
+   */
+  public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
+    if (oReader==null)
+     return null;
+    if (doc==null) {
+     try { doc = getVamsasDocument(oReader); } 
+     catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
+    }
+    Vector docrefs = AppDataReference.getAppDataReferences(doc);
+    Vector entries = oReader.getExtraEntries();
+    if (entries!=null && docrefs.size()>0) {
+      int i=0, j=entries.size();
+      do {
+        if (!docrefs.contains(entries.get(i))) {
+            entries.remove(i);
+            j--;
+        } else
+          i++;
+      } while (i<j);
+    }
+    return entries;
+  }
+}
index 7c7d060..4226458 100644 (file)
@@ -1,25 +1,8 @@
 package org.vamsas.client.simpleclient;
 
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Vector;
-import java.util.jar.JarEntry;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.vamsas.client.VorbaIdFactory;
-import org.vamsas.client.VorbaXmlBinder;
-import org.vamsas.client.Vobject;
-import org.vamsas.objects.core.ApplicationData;
-import org.vamsas.objects.core.User;
-import org.vamsas.objects.core.VAMSAS;
-import org.vamsas.objects.core.VamsasDocument;
-import org.vamsas.objects.utils.AppDataReference;
-import org.vamsas.objects.utils.DocumentStuff;
-import org.vamsas.objects.utils.ProvenanceStuff;
-import org.vamsas.objects.utils.document.VersionEntries;
 
 /**
  * holds static vamsasDocument from XML routines and
@@ -27,8 +10,7 @@ import org.vamsas.objects.utils.document.VersionEntries;
  * TODO Could be refactored ? only dependence is the IdFactory.getDummyFactory(String) method.
  * @author jimp
  */
-public class SimpleDocument {
-  VorbaIdFactory vorba;
+public class SimpleDocument extends SimpleDocBinding {
   private static Log log = LogFactory.getLog(SimpleDocument.class);
   
   private VorbaIdFactory makeDefaultFactory(String name) {
@@ -44,107 +26,4 @@ public class SimpleDocument {
     else
       log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
   }
-  /**
-   * @return Returns the vorba.
-   */
-  public VorbaIdFactory getVorba() {
-    return vorba;
-  }
-  /**
-   * @param vorba The vorba to set.
-   */
-  public void setVorba(VorbaIdFactory vorba) {
-    this.vorba = vorba;
-  }
-  
-  /**
-   * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
-   */
-  
-  public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException, 
-  org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
-    if (oReader!=null) {
-      // check the factory
-      if (vorba==null) {
-        log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
-        return null;
-      }
-
-      if (oReader.isValid()) {
-        // Read vamsasDocument.xsd instance
-        InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
-        Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
-        if (unmarsh==null)
-          log.fatal("Couldn't unmarshall document!");
-        
-        Vobject vobjs = (Vobject) unmarsh[0];
-        if (vobjs!=null) { 
-          VamsasDocument doc=(VamsasDocument) vobjs;
-          if (doc!=null)
-            return doc;
-        }
-        log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
-      } else {        
-        // deprecated data handler (vamsas.xsd instance)
-        InputStream vxmlis = oReader.getVamsasXmlStream();
-        if (vxmlis!=null) { // Might be an old vamsas file.
-          BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
-          InputStreamReader vxml = new InputStreamReader(ixml);
-          Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
-          
-          if (unmarsh==null)
-            log.fatal("Couldn't unmarshall document!");
-          
-          VAMSAS root[]= new VAMSAS[] { null};
-          root[0] = (VAMSAS) unmarsh[0]; 
-          
-          if (root[0]==null) {
-            log.debug("Found no VAMSAS object in VamsasXML stream.");
-          } else {
-            log.debug("Making new VamsasDocument from VamsasXML stream.");
-            VamsasDocument doc = DocumentStuff.newVamsasDocument(root, 
-                ProvenanceStuff.newProvenance(
-                    vorba.getUserHandle().getFullName(), 
-                    "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
-            // TODO: VAMSAS: decide on 'system' operations provenance form
-            // TODO: implement classes for translating Vorba properties into provenance user fields.
-            // TODO: VAMSAS: decide on machine readable info embedding in provenance should be done
-            root[0]=null;
-            root=null;
-            return doc;
-          }
-        }
-      }
-    }
-    // otherwise - there was no valid original document to read.
-    return null;    
-  }
-  /**
-   * Extract all jarEntries in an archive referenced by the vamsas document
-   * TODO: LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
-   * @param doc
-   * @param oReader
-   * @return array of the subset of JarEntry names that are referenced in doc 
-   */
-  public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
-    if (oReader==null)
-     return null;
-    if (doc==null) {
-     try { doc = getVamsasDocument(oReader); } 
-     catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
-    }
-    Vector docrefs = AppDataReference.getAppDataReferences(doc);
-    Vector entries = oReader.getExtraEntries();
-    if (entries!=null && docrefs.size()>0) {
-      int i=0, j=entries.size();
-      do {
-        if (!docrefs.contains(entries.get(i))) {
-            entries.remove(i);
-            j--;
-        } else
-          i++;
-      } while (i<j);
-    }
-    return entries;
-  }
 }