2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.client.simpleclient;
\r
24 import java.io.BufferedInputStream;
\r
25 import java.io.IOException;
\r
26 import java.io.InputStream;
\r
27 import java.io.InputStreamReader;
\r
28 import java.util.Vector;
\r
29 import org.apache.commons.logging.Log;
\r
30 import org.apache.commons.logging.LogFactory;
\r
32 import uk.ac.vamsas.client.Vobject;
\r
33 import uk.ac.vamsas.client.VorbaIdFactory;
\r
34 import uk.ac.vamsas.client.VorbaXmlBinder;
\r
35 import uk.ac.vamsas.objects.core.VAMSAS;
\r
36 import uk.ac.vamsas.objects.core.VamsasDocument;
\r
37 import uk.ac.vamsas.objects.utils.AppDataReference;
\r
38 import uk.ac.vamsas.objects.utils.DocumentStuff;
\r
39 import uk.ac.vamsas.objects.utils.ProvenanceStuff;
\r
40 import uk.ac.vamsas.objects.utils.document.VersionEntries;
\r
43 * Base class for SimpleClient Vamsas Document Object Manipulation holds static
\r
44 * vamsasDocument from XML routines and state objects for a particular
\r
45 * unmarshalled Document instance.
\r
50 public class SimpleDocBinding {
\r
52 protected VorbaIdFactory vorba;
\r
54 protected static Log log = LogFactory.getLog(SimpleDocBinding.class);
\r
57 * @return Returns the vorba.
\r
59 public VorbaIdFactory getVorba() {
\r
67 public void setVorba(VorbaIdFactory vorba) {
\r
72 * Uses VorbaXmlBinder to retrieve the VamsasDocument from the given stream
\r
74 public VamsasDocument getVamsasDocument(VamsasArchiveReader oReader)
\r
75 throws IOException, org.exolab.castor.xml.MarshalException,
\r
76 org.exolab.castor.xml.ValidationException {
\r
77 if (oReader != null) {
\r
78 // check the factory
\r
79 if (vorba == null) {
\r
81 .error("Invalid SimpleDocument construction - no VorbaIdFactory defined!");
\r
85 if (oReader.isValid()) {
\r
86 // Read vamsasDocument.xsd instance
\r
87 InputStreamReader vdoc = new InputStreamReader(oReader
\r
88 .getVamsasDocumentStream());
\r
89 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vdoc, vorba,
\r
90 new VamsasDocument());
\r
91 if (unmarsh == null)
\r
92 log.fatal("Couldn't unmarshall document!");
\r
94 Vobject vobjs = (Vobject) unmarsh[0];
\r
95 if (vobjs != null) {
\r
96 VamsasDocument doc = (VamsasDocument) vobjs;
\r
101 .debug("Found no VamsasDocument object in properly formatted Vamsas Archive.");
\r
103 // deprecated data handler (vamsas.xsd instance)
\r
104 InputStream vxmlis = oReader.getVamsasXmlStream();
\r
105 if (vxmlis != null) { // Might be an old vamsas file.
\r
106 BufferedInputStream ixml = new BufferedInputStream(oReader
\r
107 .getVamsasXmlStream());
\r
108 InputStreamReader vxml = new InputStreamReader(ixml);
\r
109 Object unmarsh[] = VorbaXmlBinder.getVamsasObjects(vxml, vorba,
\r
112 if (unmarsh == null)
\r
113 log.fatal("Couldn't unmarshall document!");
\r
115 VAMSAS root[] = new VAMSAS[] { null };
\r
116 root[0] = (VAMSAS) unmarsh[0];
\r
118 if (root[0] == null) {
\r
119 log.debug("Found no VAMSAS object in VamsasXML stream.");
\r
121 log.debug("Making new VamsasDocument from VamsasXML stream.");
\r
122 VamsasDocument doc = DocumentStuff.newVamsasDocument(root,
\r
123 ProvenanceStuff.newProvenance(vorba.getUserHandle()
\r
125 "Vamsas Document constructed from vamsas.xml"),
\r
126 VersionEntries.ALPHA_VERSION);
\r
127 // VAMSAS: decide on 'system' operations provenance form
\r
128 // LATER: implement classes for translating Vorba properties into
\r
129 // provenance user fields.
\r
130 // VAMSAS: decide on machine readable info embedding in provenance
\r
139 // otherwise - there was no valid original document to read.
\r
144 * Extract all jarEntries in an archive referenced by the vamsas document
\r
145 * LATER: a family of methods for finding extraneous jarEntries , and invalid
\r
146 * appDataReferences
\r
150 * @return array of the subset of JarEntry names that are referenced in doc
\r
152 public Vector getReferencedEntries(VamsasDocument doc,
\r
153 VamsasArchiveReader oReader) {
\r
154 if (oReader == null)
\r
158 doc = getVamsasDocument(oReader);
\r
159 } catch (Exception e) {
\r
160 log.warn("Failed to get document from " + oReader.jfileName);
\r
164 Vector docrefs = AppDataReference.getAppDataReferences(doc);
\r
165 if (docrefs == null)
\r
167 Vector entries = oReader.getExtraEntries();
\r
168 if (entries != null && entries.size() > 0 && docrefs.size() > 0) {
\r
169 int i = 0, j = entries.size();
\r
171 if (!docrefs.contains(entries.get(i))) {
\r