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
26 public class SimpleDocBinding {
28 protected VorbaIdFactory vorba;
29 protected static Log log = LogFactory.getLog(SimpleDocBinding.class);
32 * @return Returns the vorba.
34 public VorbaIdFactory getVorba() {
39 * @param vorba The vorba to set.
41 public void setVorba(VorbaIdFactory vorba) {
46 * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
48 public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
52 log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
56 if (oReader.isValid()) {
57 // Read vamsasDocument.xsd instance
58 InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
59 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
61 log.fatal("Couldn't unmarshall document!");
63 Vobject vobjs = (Vobject) unmarsh[0];
65 VamsasDocument doc=(VamsasDocument) vobjs;
69 log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
71 // deprecated data handler (vamsas.xsd instance)
72 InputStream vxmlis = oReader.getVamsasXmlStream();
73 if (vxmlis!=null) { // Might be an old vamsas file.
74 BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
75 InputStreamReader vxml = new InputStreamReader(ixml);
76 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
79 log.fatal("Couldn't unmarshall document!");
81 VAMSAS root[]= new VAMSAS[] { null};
82 root[0] = (VAMSAS) unmarsh[0];
85 log.debug("Found no VAMSAS object in VamsasXML stream.");
87 log.debug("Making new VamsasDocument from VamsasXML stream.");
88 VamsasDocument doc = DocumentStuff.newVamsasDocument(root,
89 ProvenanceStuff.newProvenance(
90 vorba.getUserHandle().getFullName(),
91 "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
92 // VAMSAS: decide on 'system' operations provenance form
93 // LATER: implement classes for translating Vorba properties into provenance user fields.
94 // VAMSAS: decide on machine readable info embedding in provenance should be done
102 // otherwise - there was no valid original document to read.
107 * Extract all jarEntries in an archive referenced by the vamsas document
108 * LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
111 * @return array of the subset of JarEntry names that are referenced in doc
113 public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
117 try { doc = getVamsasDocument(oReader); }
118 catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
120 Vector docrefs = AppDataReference.getAppDataReferences(doc);
121 Vector entries = oReader.getExtraEntries();
122 if (entries!=null && docrefs.size()>0) {
123 int i=0, j=entries.size();
125 if (!docrefs.contains(entries.get(i))) {