1 package org.vamsas.client.simpleclient;
3 import java.io.BufferedInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.util.Vector;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.vamsas.client.Vobject;
11 import org.vamsas.client.VorbaIdFactory;
12 import org.vamsas.client.VorbaXmlBinder;
13 import org.vamsas.objects.core.VAMSAS;
14 import org.vamsas.objects.core.VamsasDocument;
15 import org.vamsas.objects.utils.AppDataReference;
16 import org.vamsas.objects.utils.DocumentStuff;
17 import org.vamsas.objects.utils.ProvenanceStuff;
18 import org.vamsas.objects.utils.document.VersionEntries;
21 * Base class for SimpleClient Vamsas Document Object Manipulation
22 * holds static vamsasDocument from XML routines and
23 * state objects for a particular unmarshalled Document instance.
28 public class SimpleDocBinding {
30 protected VorbaIdFactory vorba;
31 protected static Log log = LogFactory.getLog(SimpleDocBinding.class);
34 * @return Returns the vorba.
36 public VorbaIdFactory getVorba() {
41 * @param vorba The vorba to set.
43 public void setVorba(VorbaIdFactory vorba) {
48 * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
50 public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
54 log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
58 if (oReader.isValid()) {
59 // Read vamsasDocument.xsd instance
60 InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
61 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
63 log.fatal("Couldn't unmarshall document!");
65 Vobject vobjs = (Vobject) unmarsh[0];
67 VamsasDocument doc=(VamsasDocument) vobjs;
71 log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
73 // deprecated data handler (vamsas.xsd instance)
74 InputStream vxmlis = oReader.getVamsasXmlStream();
75 if (vxmlis!=null) { // Might be an old vamsas file.
76 BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
77 InputStreamReader vxml = new InputStreamReader(ixml);
78 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
81 log.fatal("Couldn't unmarshall document!");
83 VAMSAS root[]= new VAMSAS[] { null};
84 root[0] = (VAMSAS) unmarsh[0];
87 log.debug("Found no VAMSAS object in VamsasXML stream.");
89 log.debug("Making new VamsasDocument from VamsasXML stream.");
90 VamsasDocument doc = DocumentStuff.newVamsasDocument(root,
91 ProvenanceStuff.newProvenance(
92 vorba.getUserHandle().getFullName(),
93 "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
94 // VAMSAS: decide on 'system' operations provenance form
95 // LATER: implement classes for translating Vorba properties into provenance user fields.
96 // VAMSAS: decide on machine readable info embedding in provenance should be done
104 // otherwise - there was no valid original document to read.
109 * Extract all jarEntries in an archive referenced by the vamsas document
110 * LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
113 * @return array of the subset of JarEntry names that are referenced in doc
115 public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
119 try { doc = getVamsasDocument(oReader); }
120 catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
122 Vector docrefs = AppDataReference.getAppDataReferences(doc);
123 Vector entries = oReader.getExtraEntries();
124 if (entries!=null && docrefs.size()>0) {
125 int i=0, j=entries.size();
127 if (!docrefs.contains(entries.get(i))) {