1 package uk.ac.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;
11 import uk.ac.vamsas.client.Vobject;
12 import uk.ac.vamsas.client.VorbaIdFactory;
13 import uk.ac.vamsas.client.VorbaXmlBinder;
14 import uk.ac.vamsas.objects.core.VAMSAS;
15 import uk.ac.vamsas.objects.core.VamsasDocument;
16 import uk.ac.vamsas.objects.utils.AppDataReference;
17 import uk.ac.vamsas.objects.utils.DocumentStuff;
18 import uk.ac.vamsas.objects.utils.ProvenanceStuff;
19 import uk.ac.vamsas.objects.utils.document.VersionEntries;
22 * Base class for SimpleClient Vamsas Document Object Manipulation
23 * holds static vamsasDocument from XML routines and
24 * state objects for a particular unmarshalled Document instance.
29 public class SimpleDocBinding {
31 protected VorbaIdFactory vorba;
32 protected static Log log = LogFactory.getLog(SimpleDocBinding.class);
35 * @return Returns the vorba.
37 public VorbaIdFactory getVorba() {
42 * @param vorba The vorba to set.
44 public void setVorba(VorbaIdFactory vorba) {
49 * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
51 public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
55 log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
59 if (oReader.isValid()) {
60 // Read vamsasDocument.xsd instance
61 InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
62 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
64 log.fatal("Couldn't unmarshall document!");
66 Vobject vobjs = (Vobject) unmarsh[0];
68 VamsasDocument doc=(VamsasDocument) vobjs;
72 log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
74 // deprecated data handler (vamsas.xsd instance)
75 InputStream vxmlis = oReader.getVamsasXmlStream();
76 if (vxmlis!=null) { // Might be an old vamsas file.
77 BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
78 InputStreamReader vxml = new InputStreamReader(ixml);
79 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
82 log.fatal("Couldn't unmarshall document!");
84 VAMSAS root[]= new VAMSAS[] { null};
85 root[0] = (VAMSAS) unmarsh[0];
88 log.debug("Found no VAMSAS object in VamsasXML stream.");
90 log.debug("Making new VamsasDocument from VamsasXML stream.");
91 VamsasDocument doc = DocumentStuff.newVamsasDocument(root,
92 ProvenanceStuff.newProvenance(
93 vorba.getUserHandle().getFullName(),
94 "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
95 // VAMSAS: decide on 'system' operations provenance form
96 // LATER: implement classes for translating Vorba properties into provenance user fields.
97 // VAMSAS: decide on machine readable info embedding in provenance should be done
105 // otherwise - there was no valid original document to read.
110 * Extract all jarEntries in an archive referenced by the vamsas document
111 * LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
114 * @return array of the subset of JarEntry names that are referenced in doc
116 public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
120 try { doc = getVamsasDocument(oReader); }
121 catch (Exception e) { log.warn("Failed to get document from "+oReader.jfileName); };
123 Vector docrefs = AppDataReference.getAppDataReferences(doc);
126 Vector entries = oReader.getExtraEntries();
127 if (entries!=null && entries.size()>0 && docrefs.size()>0) {
128 int i=0, j=entries.size();
130 if (!docrefs.contains(entries.get(i))) {