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 java.util.jar.JarEntry;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.vamsas.client.VorbaIdFactory;
13 import org.vamsas.client.VorbaXmlBinder;
14 import org.vamsas.client.object;
15 import org.vamsas.objects.core.ApplicationData;
16 import org.vamsas.objects.core.User;
17 import org.vamsas.objects.core.VAMSAS;
18 import org.vamsas.objects.core.VamsasDocument;
19 import org.vamsas.objects.utils.AppDataReference;
20 import org.vamsas.objects.utils.DocumentStuff;
21 import org.vamsas.objects.utils.ProvenanceStuff;
22 import org.vamsas.objects.utils.document.VersionEntries;
25 * holds static vamsasDocument from XML routines and
26 * state objects for a particular unmarshalled Document instance.
27 * TODO Could be refactored ? only dependence is the IdFactory.getDummyFactory(String) method.
30 public class SimpleDocument {
32 private static Log log = LogFactory.getLog(SimpleDocument.class);
34 private VorbaIdFactory makeDefaultFactory(String name) {
35 return IdFactory.getDummyFactory(name);
38 public SimpleDocument(String name) {
39 vorba = makeDefaultFactory(name);
41 public SimpleDocument(VorbaIdFactory Vorba) {
45 log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
48 * @return Returns the vorba.
50 public VorbaIdFactory getVorba() {
54 * @param vorba The vorba to set.
56 public void setVorba(VorbaIdFactory vorba) {
61 * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
64 public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader) throws IOException,
65 org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
69 log.error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
73 if (oReader.isValid()) {
74 // Read vamsasDocument.xsd instance
75 InputStreamReader vdoc = new InputStreamReader(oReader.getVamsasDocumentStream());
76 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba, new VamsasDocument());
78 log.fatal("Couldn't unmarshall document!");
80 object vobjs = (object) unmarsh[0];
82 VamsasDocument doc=(VamsasDocument) vobjs;
86 log.debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
88 // deprecated data handler (vamsas.xsd instance)
89 InputStream vxmlis = oReader.getVamsasXmlStream();
90 if (vxmlis!=null) { // Might be an old vamsas file.
91 BufferedInputStream ixml = new BufferedInputStream(oReader.getVamsasXmlStream());
92 InputStreamReader vxml = new InputStreamReader(ixml);
93 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba, new VAMSAS());
96 log.fatal("Couldn't unmarshall document!");
98 VAMSAS root[]= new VAMSAS[] { null};
99 root[0] = (VAMSAS) unmarsh[0];
102 log.debug("Found no VAMSAS object in VamsasXML stream.");
104 log.debug("Making new VamsasDocument from VamsasXML stream.");
105 VamsasDocument doc = DocumentStuff.newVamsasDocument(root,
106 ProvenanceStuff.newProvenance(
107 vorba.getUserHandle().getFullName(),
108 "Vamsas Document constructed from vamsas.xml"), VersionEntries.ALPHA_VERSION);
109 // TODO: VAMSAS: decide on 'system' operations provenance form
110 // TODO: implement classes for translating Vorba properties into provenance user fields.
111 // TODO: VAMSAS: decide on machine readable info embedding in provenance should be done
119 // otherwise - there was no valid original document to read.
123 * Extract all jarEntries in an archive referenced by the vamsas document
124 * TODO: LATER: a family of methods for finding extraneous jarEntries , and invalid appDataReferences
127 * @return array of the subset of JarEntry names that are referenced in doc
129 public Vector getReferencedEntries(VamsasDocument doc, VamsasArchiveReader oReader) {
133 try { doc = getVamsasDocument(oReader); }
134 catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
136 Vector docrefs = AppDataReference.getAppDataReferences(doc);
137 Vector entries = oReader.getExtraEntries();
138 if (entries!=null && docrefs.size()>0) {
139 int i=0, j=entries.size();
141 if (!docrefs.contains(entries.get(i))) {