-package uk.ac.vamsas.test.simpleclient;
-
-import java.util.Hashtable;
-import java.util.Vector;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import uk.ac.vamsas.client.IClientAppdata;
-import uk.ac.vamsas.client.Vobject;
-import uk.ac.vamsas.client.VorbaId;
-import uk.ac.vamsas.client.simpleclient.ClientDocument;
-import uk.ac.vamsas.client.simpleclient.VamsasArchive;
-import uk.ac.vamsas.client.simpleclient.VamsasArchiveReader;
-import uk.ac.vamsas.objects.core.Entry;
-import uk.ac.vamsas.objects.core.VAMSAS;
-import uk.ac.vamsas.objects.core.VamsasDocument;
-import uk.ac.vamsas.objects.utils.ProvenanceStuff;
-
-// simple holder to pass to client.
-public class ClientDoc extends uk.ac.vamsas.client.ClientDocument {
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.IClientDocument#getClientAppdata()
- */
- public IClientAppdata getClientAppdata() {
- throw new Error("Appdata access is not implemented in the test.simpleclient.ClientDoc instance."); // TODO Auto-generated method stub
- }
- protected boolean isModified=false;
- private Log log = LogFactory.getLog(ClientDoc.class);
- protected VamsasDocument doc;
- public uk.ac.vamsas.objects.core.VAMSAS[] _VamsasRoots;
- protected VamsasArchive iohandler=null;
- protected VamsasArchiveReader reader=null;
- private String user=null;
- private String app=null;
-
- /**
- * @param doc
- * @param iohandler
- * @param reader
- * @param app
- * @param user
- */
- public ClientDoc(VamsasDocument doc, VamsasArchive iohandler, VamsasArchiveReader reader, String app, String user, Hashtable objrefs) {
- super(objrefs, (iohandler!=null) ? iohandler.getVorba() : null);
- this.doc = doc;
- this.iohandler = iohandler;
- this.reader = reader;
- this.app = app;
- this.user = user;
- this.objrefs = objrefs;
- _VamsasRoots = doc.getVAMSAS();
- }
- // AppDataOutputStream appd;
- //AppDataOutputStream userd;
- /* (non-Javadoc)
- * @see java.lang.Object#finalize()
- */
- protected Entry getProvenanceEntry(String action) {
- // VAMSAS: modify schema to allow referencing of user field (plus other issues, ClientUrn field, machine readable action, input parameters, additional data generated notes
- Entry prov = ProvenanceStuff.newProvenanceEntry(app, user, action);
- return prov;
- }
- public VAMSAS[] getVamsasRoots() {
- if (doc==null) {
- log.debug("Null document for getVamsasRoots(), returning null");
- return null;
- }
- if (iohandler==null) {
- // LATER: decide on read-only status of ClientDocument object
- log.warn("getVamsasRoots() called on possibly read-only document.");
- }
- if (_VamsasRoots!=null)
- return _VamsasRoots;
- VAMSAS[] roots = doc.getVAMSAS();
- if (roots == null) {
- // Make a new one to return to client to get filled.
- _VamsasRoots = new VAMSAS[] { new VAMSAS() };
- // Do provenance now. just in case.
- doc.getProvenance().addEntry(getProvenanceEntry("Created new document root [id="+_VamsasRoots[0].getId()+"]"));
- doc.addVAMSAS(_VamsasRoots[0]);
- } else {
- _VamsasRoots = new VAMSAS[roots.length];
- for (int r=0;r<roots.length; r++)
- _VamsasRoots[r] = roots[r];
- }
- return _VamsasRoots;
- }
-
- private int _contains(VAMSAS root, VAMSAS[] docRoots) {
- if (root==null)
- return -1;
- if (docRoots==null || docRoots.length==0)
- return -1;
- VorbaId r_id = root.getVorbaId();
- for (int i=0,j=docRoots.length; i<j; i++) {
- VorbaId n_id=null;
- if (docRoots[i]==root || (docRoots[i]!=null && (n_id=docRoots[i].getVorbaId())!=null && n_id.equals(r_id)))
- return i;
- }
- return -1;
- }
-/**
- * verify that newr version is really an intact version of the
- * @param newVersion (may be modified)
- * @param oldVersion
- * @return true if newVersion is a valid root that preserves original references
- */
- private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion) {
- // ideal - this cascades down the two structures, ensuring that all ID'd objects in one are present in the other.
- if (oldVersion==newVersion) {
- // may be a virgin root element.
- if (!newVersion.isRegistered())
- iohandler.getVorba().makeVorbaId(newVersion);
- // Should retrieve original version and compare - unless local hashes can be used to determine if resultSet has been truncated.
- // just do internal validation for moment.
- if (newVersion.isValid())
- return true;
- return false;
- } else {
- // redundant ? if (oldVersion.is__stored_in_document())
- if (!newVersion.isRegistered())
- iohandler.getVorba().makeVorbaId(newVersion);
- if (newVersion.isValid())
- return true;
- }
- return false;
- }
- /**
- /**
- * merge old and new root vectors
- * @param newr This array may be written to
- * @param original
- * @param the client document (usually this) which this root set belongs to.
- * @return merged vector of vamsas roots
- */
- private VAMSAS[] _combineRoots(VAMSAS[] newr, final VAMSAS[] original, ClientDoc modflag) {
- Vector rts = new Vector();
- boolean modified=false;
- for (int i=0,j=original.length; i<j; i++) {
- int k = _contains(original[i], newr);
- if (k>-1) {
- if (isValidUpdate(newr[k], original[i])) {
- modified=true;
- rts.add(newr[k]);
- newr[k]=null;
- } else {
- // LATER: try harder to merge ducument roots.
- log.warn("Couldn't merge new VAMSAS root "+newr[k].getId());
- newr[k] = null; // LATER: this means we ignore mangled roots. NOT GOOD
- }
- } else {
- // add in order.
- rts.add(original[i]);
- }
- }
- // add remaining (new) roots
- for (int i=0,j=newr.length; i<j; i++) {
- if (newr[i]!=null) {
- rts.add(newr[i]);
- modified=true;
- }
- }
- newr = new VAMSAS[rts.size()];
- for (int i=0,j=rts.size(); i<j; i++)
- newr[i] = (VAMSAS) rts.get(i);
- if (modflag!=null)
- modflag.isModified = modified;
- return newr;
- }
-
- /**
- * update the document with new roots.
- * LATER: decide: this affects the next call to getVamsasRoots()
- * @see org.vamsas.IClientDocument.setVamsasRoots
- */
- public void setVamsasRoots(VAMSAS[] newroots) {
- if (doc==null) {
- log.debug("setVamsasRoots called on null document.");
- return;
- }
- VAMSAS[] newr;
- if (newroots==null) {
- log.debug("setVamsasRoots(null) - do nothing.");
- return;
- }
- // are we dealing with same array ?
- if (_VamsasRoots!=newroots) {
- // merge roots into local version.
- newr = new VAMSAS[newroots.length];
- for (int i=0;i<newr.length;i++)
- newr[i] = newroots[i];
- newr=_combineRoots(newr,_VamsasRoots,this);
- } else {
- newr = new VAMSAS[_VamsasRoots.length];
- for (int i=0;i<newr.length;i++)
- newr[i]=_VamsasRoots[i];
- }
- // actually compare with document root set for final combination (to ensure nothing is lost)
- _VamsasRoots = _combineRoots(newr, doc.getVAMSAS(), this);
- }
-
-
- /* (non-Javadoc)
- * LATER: decide: this affects the next call to getVamsasRoots()
- * @see uk.ac.vamsas.client.IClientDocument#addVamsasRoot(uk.ac.vamsas.objects.core.VAMSAS)
- */
- public void addVamsasRoot(VAMSAS newroot) {
- if (doc==null) {
- log.debug("addVamsasRoots called on null document.");
- return;
- }
- VAMSAS[] newroots = _combineRoots(new VAMSAS[] {newroot}, _VamsasRoots, this);
- _VamsasRoots = newroots;
- }
-
- public VamsasArchiveReader getReader() {
- return reader;
- }
- private void _finalize() {
- log.debug("finalizing clientDoc");
- if (doc!=null) {
- doc = null;
- }
- if (_VamsasRoots!=null) {
- for (int i=0; i<_VamsasRoots.length; i++)
- _VamsasRoots[i]=null;
- _VamsasRoots=null;
-
- }
-
- if (reader!=null) {
- log.debug("Closing and removing reader reference");
- reader.close();
- reader=null;
- }
- if (iohandler!=null) {
- log.debug("Removing ioHandler reference.");
- iohandler.cancelArchive();
- iohandler=null;
- }
- }
- protected void finalize() throws Throwable {
- _finalize();
- super.finalize();
- }
- private java.util.Hashtable objrefs=null;
-
- public VorbaId[] registerObjects(Vobject[] unregistered) {
- if (doc==null) {
- log.warn("registerObjects[] called on null document.");
- return null;
- }
- if (objrefs==null) {
- log.warn("registerObjects[] called for null objrefs hasharray.");
- return null;
- }
- if (unregistered!=null) {
- VorbaId ids[] = new VorbaId[unregistered.length];
- for (int i=0,k=unregistered.length; i<k; i++)
- if (unregistered[i]!=null) {
- log.warn("Null Vobject passed to registerObject[] at position "+i);
- return null;
- } else {
- ids[i]=registerObject(unregistered[i]);
- }
- log.debug("Registered "+unregistered.length+" objects - total of "+objrefs.size()+" ids.");
- return ids;
- }
- return null;
- }
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.IClientDocument#registerObject(uk.ac.vamsas.client.Vobject)
- */
- public VorbaId registerObject(Vobject unregistered) {
- if (doc==null) {
- log.warn("registerObjects called on null document.");
- return null;
- }
- if (objrefs==null) {
- log.warn("registerObjects called for null objrefs hasharray.");
- return null;
- }
- if (iohandler==null) {
- log.warn("registerObjects called for read only document.");
- return null;
- }
-
- if (unregistered!=null) {
- VorbaId id = this._registerObject(unregistered);
- log.debug("Registered object - total of "+objrefs.size()+" ids.");
- return id;
- }
- log.warn("Null Vobject passed to registerObject.");
- return null;
- }
- /*
- * (non-Javadoc)
- *
- * @see uk.ac.vamsas.client.IClientDocument#getObject(uk.ac.vamsas.client.VorbaId)
- */
- public Vobject getObject(VorbaId id) {
- if (objrefs==null) {
- log.debug("getObject called on null objrefs list.");
- return null;
- }
- if (objrefs.containsKey(id.getId()))
- return (Vobject) objrefs.get(id.getId());
- log.debug("Returning null Vobject reference for id "+id.getId());
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see uk.ac.vamsas.client.IClientDocument#getObjects(uk.ac.vamsas.client.VorbaId[])
- */
- public Vobject[] getObjects(VorbaId[] ids) {
- if (objrefs==null) {
- log.debug("getObject[] called on null objrefs list.");
- return null;
- }
- Vobject[] vo = new Vobject[ids.length];
- for (int i=0,j=ids.length; i<j;i++)
- if (objrefs.containsKey(ids[i]))
- vo[i] = (Vobject) objrefs.get(ids[i]);
- else
- log.debug("Returning null Vobject reference for id "+ids[i].getId());
- return vo;
- }
- protected void updateDocumentRoots() {
- if (doc==null) {
- log.error("updateDocumentRoots called on null document. Probably an implementation error.");
- return;
- }
- if (isModified) {
- if (_VamsasRoots!=null) {
- doc.setVAMSAS(_VamsasRoots);
- _VamsasRoots=null;
- }
- }
- }
- /**
- * tell vamsas client to close the document and reset the object. Once closed, nothing can be done with the object.
- *
- */
- public void closeDoc() {
- if (doc!=null) {
- log.debug("Closing open document.");
- _finalize();
- } else {
- log.warn("Ignoring closeDoc on invalid document.");
- }
- }
-
-}
\ No newline at end of file
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ * Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package uk.ac.vamsas.test.simpleclient;\r
+\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import uk.ac.vamsas.client.IClientAppdata;\r
+import uk.ac.vamsas.client.Vobject;\r
+import uk.ac.vamsas.client.VorbaId;\r
+import uk.ac.vamsas.client.simpleclient.ClientDocument;\r
+import uk.ac.vamsas.client.simpleclient.VamsasArchive;\r
+import uk.ac.vamsas.client.simpleclient.VamsasArchiveReader;\r
+import uk.ac.vamsas.objects.core.Entry;\r
+import uk.ac.vamsas.objects.core.VAMSAS;\r
+import uk.ac.vamsas.objects.core.VamsasDocument;\r
+import uk.ac.vamsas.objects.utils.ProvenanceStuff;\r
+\r
+// simple holder to pass to client.\r
+public class ClientDoc extends uk.ac.vamsas.client.ClientDocument {\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see uk.ac.vamsas.client.IClientDocument#getClientAppdata()\r
+ */\r
+ public IClientAppdata getClientAppdata() {\r
+ throw new Error(\r
+ "Appdata access is not implemented in the test.simpleclient.ClientDoc instance."); // TODO\r
+ // Auto-generated\r
+ // method\r
+ // stub\r
+ }\r
+\r
+ protected boolean isModified = false;\r
+\r
+ private Log log = LogFactory.getLog(ClientDoc.class);\r
+\r
+ protected VamsasDocument doc;\r
+\r
+ public uk.ac.vamsas.objects.core.VAMSAS[] _VamsasRoots;\r
+\r
+ protected VamsasArchive iohandler = null;\r
+\r
+ protected VamsasArchiveReader reader = null;\r
+\r
+ private String user = null;\r
+\r
+ private String app = null;\r
+\r
+ /**\r
+ * @param doc\r
+ * @param iohandler\r
+ * @param reader\r
+ * @param app\r
+ * @param user\r
+ */\r
+ public ClientDoc(VamsasDocument doc, VamsasArchive iohandler,\r
+ VamsasArchiveReader reader, String app, String user, Hashtable objrefs) {\r
+ super(objrefs, (iohandler != null) ? iohandler.getVorba() : null);\r
+ this.doc = doc;\r
+ this.iohandler = iohandler;\r
+ this.reader = reader;\r
+ this.app = app;\r
+ this.user = user;\r
+ this.objrefs = objrefs;\r
+ _VamsasRoots = doc.getVAMSAS();\r
+ }\r
+\r
+ // AppDataOutputStream appd;\r
+ // AppDataOutputStream userd;\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see java.lang.Object#finalize()\r
+ */\r
+ protected Entry getProvenanceEntry(String action) {\r
+ // VAMSAS: modify schema to allow referencing of user field (plus other\r
+ // issues, ClientUrn field, machine readable action, input parameters,\r
+ // additional data generated notes\r
+ Entry prov = ProvenanceStuff.newProvenanceEntry(app, user, action);\r
+ return prov;\r
+ }\r
+\r
+ public VAMSAS[] getVamsasRoots() {\r
+ if (doc == null) {\r
+ log.debug("Null document for getVamsasRoots(), returning null");\r
+ return null;\r
+ }\r
+ if (iohandler == null) {\r
+ // LATER: decide on read-only status of ClientDocument object\r
+ log.warn("getVamsasRoots() called on possibly read-only document.");\r
+ }\r
+ if (_VamsasRoots != null)\r
+ return _VamsasRoots;\r
+ VAMSAS[] roots = doc.getVAMSAS();\r
+ if (roots == null) {\r
+ // Make a new one to return to client to get filled.\r
+ _VamsasRoots = new VAMSAS[] { new VAMSAS() };\r
+ // Do provenance now. just in case.\r
+ doc.getProvenance().addEntry(\r
+ getProvenanceEntry("Created new document root [id="\r
+ + _VamsasRoots[0].getId() + "]"));\r
+ doc.addVAMSAS(_VamsasRoots[0]);\r
+ } else {\r
+ _VamsasRoots = new VAMSAS[roots.length];\r
+ for (int r = 0; r < roots.length; r++)\r
+ _VamsasRoots[r] = roots[r];\r
+ }\r
+ return _VamsasRoots;\r
+ }\r
+\r
+ private int _contains(VAMSAS root, VAMSAS[] docRoots) {\r
+ if (root == null)\r
+ return -1;\r
+ if (docRoots == null || docRoots.length == 0)\r
+ return -1;\r
+ VorbaId r_id = root.getVorbaId();\r
+ for (int i = 0, j = docRoots.length; i < j; i++) {\r
+ VorbaId n_id = null;\r
+ if (docRoots[i] == root\r
+ || (docRoots[i] != null && (n_id = docRoots[i].getVorbaId()) != null && n_id\r
+ .equals(r_id)))\r
+ return i;\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ /**\r
+ * verify that newr version is really an intact version of the\r
+ * \r
+ * @param newVersion\r
+ * (may be modified)\r
+ * @param oldVersion\r
+ * @return true if newVersion is a valid root that preserves original\r
+ * references\r
+ */\r
+ private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion) {\r
+ // ideal - this cascades down the two structures, ensuring that all ID'd\r
+ // objects in one are present in the other.\r
+ if (oldVersion == newVersion) {\r
+ // may be a virgin root element.\r
+ if (!newVersion.isRegistered())\r
+ iohandler.getVorba().makeVorbaId(newVersion);\r
+ // Should retrieve original version and compare - unless local hashes can\r
+ // be used to determine if resultSet has been truncated.\r
+ // just do internal validation for moment.\r
+ if (newVersion.isValid())\r
+ return true;\r
+ return false;\r
+ } else {\r
+ // redundant ? if (oldVersion.is__stored_in_document())\r
+ if (!newVersion.isRegistered())\r
+ iohandler.getVorba().makeVorbaId(newVersion);\r
+ if (newVersion.isValid())\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * /** merge old and new root vectors\r
+ * \r
+ * @param newr\r
+ * This array may be written to\r
+ * @param original\r
+ * @param the\r
+ * client document (usually this) which this root set belongs to.\r
+ * @return merged vector of vamsas roots\r
+ */\r
+ private VAMSAS[] _combineRoots(VAMSAS[] newr, final VAMSAS[] original,\r
+ ClientDoc modflag) {\r
+ Vector rts = new Vector();\r
+ boolean modified = false;\r
+ for (int i = 0, j = original.length; i < j; i++) {\r
+ int k = _contains(original[i], newr);\r
+ if (k > -1) {\r
+ if (isValidUpdate(newr[k], original[i])) {\r
+ modified = true;\r
+ rts.add(newr[k]);\r
+ newr[k] = null;\r
+ } else {\r
+ // LATER: try harder to merge ducument roots.\r
+ log.warn("Couldn't merge new VAMSAS root " + newr[k].getId());\r
+ newr[k] = null; // LATER: this means we ignore mangled roots. NOT GOOD\r
+ }\r
+ } else {\r
+ // add in order.\r
+ rts.add(original[i]);\r
+ }\r
+ }\r
+ // add remaining (new) roots\r
+ for (int i = 0, j = newr.length; i < j; i++) {\r
+ if (newr[i] != null) {\r
+ rts.add(newr[i]);\r
+ modified = true;\r
+ }\r
+ }\r
+ newr = new VAMSAS[rts.size()];\r
+ for (int i = 0, j = rts.size(); i < j; i++)\r
+ newr[i] = (VAMSAS) rts.get(i);\r
+ if (modflag != null)\r
+ modflag.isModified = modified;\r
+ return newr;\r
+ }\r
+\r
+ /**\r
+ * update the document with new roots. LATER: decide: this affects the next\r
+ * call to getVamsasRoots()\r
+ * \r
+ * @see org.vamsas.IClientDocument.setVamsasRoots\r
+ */\r
+ public void setVamsasRoots(VAMSAS[] newroots) {\r
+ if (doc == null) {\r
+ log.debug("setVamsasRoots called on null document.");\r
+ return;\r
+ }\r
+ VAMSAS[] newr;\r
+ if (newroots == null) {\r
+ log.debug("setVamsasRoots(null) - do nothing.");\r
+ return;\r
+ }\r
+ // are we dealing with same array ?\r
+ if (_VamsasRoots != newroots) {\r
+ // merge roots into local version.\r
+ newr = new VAMSAS[newroots.length];\r
+ for (int i = 0; i < newr.length; i++)\r
+ newr[i] = newroots[i];\r
+ newr = _combineRoots(newr, _VamsasRoots, this);\r
+ } else {\r
+ newr = new VAMSAS[_VamsasRoots.length];\r
+ for (int i = 0; i < newr.length; i++)\r
+ newr[i] = _VamsasRoots[i];\r
+ }\r
+ // actually compare with document root set for final combination (to ensure\r
+ // nothing is lost)\r
+ _VamsasRoots = _combineRoots(newr, doc.getVAMSAS(), this);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc) LATER: decide: this affects the next call to getVamsasRoots()\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.IClientDocument#addVamsasRoot(uk.ac.vamsas.objects.\r
+ * core.VAMSAS)\r
+ */\r
+ public void addVamsasRoot(VAMSAS newroot) {\r
+ if (doc == null) {\r
+ log.debug("addVamsasRoots called on null document.");\r
+ return;\r
+ }\r
+ VAMSAS[] newroots = _combineRoots(new VAMSAS[] { newroot }, _VamsasRoots,\r
+ this);\r
+ _VamsasRoots = newroots;\r
+ }\r
+\r
+ public VamsasArchiveReader getReader() {\r
+ return reader;\r
+ }\r
+\r
+ private void _finalize() {\r
+ log.debug("finalizing clientDoc");\r
+ if (doc != null) {\r
+ doc = null;\r
+ }\r
+ if (_VamsasRoots != null) {\r
+ for (int i = 0; i < _VamsasRoots.length; i++)\r
+ _VamsasRoots[i] = null;\r
+ _VamsasRoots = null;\r
+\r
+ }\r
+\r
+ if (reader != null) {\r
+ log.debug("Closing and removing reader reference");\r
+ reader.close();\r
+ reader = null;\r
+ }\r
+ if (iohandler != null) {\r
+ log.debug("Removing ioHandler reference.");\r
+ iohandler.cancelArchive();\r
+ iohandler = null;\r
+ }\r
+ }\r
+\r
+ protected void finalize() throws Throwable {\r
+ _finalize();\r
+ super.finalize();\r
+ }\r
+\r
+ private java.util.Hashtable objrefs = null;\r
+\r
+ public VorbaId[] registerObjects(Vobject[] unregistered) {\r
+ if (doc == null) {\r
+ log.warn("registerObjects[] called on null document.");\r
+ return null;\r
+ }\r
+ if (objrefs == null) {\r
+ log.warn("registerObjects[] called for null objrefs hasharray.");\r
+ return null;\r
+ }\r
+ if (unregistered != null) {\r
+ VorbaId ids[] = new VorbaId[unregistered.length];\r
+ for (int i = 0, k = unregistered.length; i < k; i++)\r
+ if (unregistered[i] != null) {\r
+ log.warn("Null Vobject passed to registerObject[] at position " + i);\r
+ return null;\r
+ } else {\r
+ ids[i] = registerObject(unregistered[i]);\r
+ }\r
+ log.debug("Registered " + unregistered.length + " objects - total of "\r
+ + objrefs.size() + " ids.");\r
+ return ids;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.IClientDocument#registerObject(uk.ac.vamsas.client.\r
+ * Vobject)\r
+ */\r
+ public VorbaId registerObject(Vobject unregistered) {\r
+ if (doc == null) {\r
+ log.warn("registerObjects called on null document.");\r
+ return null;\r
+ }\r
+ if (objrefs == null) {\r
+ log.warn("registerObjects called for null objrefs hasharray.");\r
+ return null;\r
+ }\r
+ if (iohandler == null) {\r
+ log.warn("registerObjects called for read only document.");\r
+ return null;\r
+ }\r
+\r
+ if (unregistered != null) {\r
+ VorbaId id = this._registerObject(unregistered);\r
+ log.debug("Registered object - total of " + objrefs.size() + " ids.");\r
+ return id;\r
+ }\r
+ log.warn("Null Vobject passed to registerObject.");\r
+ return null;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.IClientDocument#getObject(uk.ac.vamsas.client.VorbaId)\r
+ */\r
+ public Vobject getObject(VorbaId id) {\r
+ if (objrefs == null) {\r
+ log.debug("getObject called on null objrefs list.");\r
+ return null;\r
+ }\r
+ if (objrefs.containsKey(id.getId()))\r
+ return (Vobject) objrefs.get(id.getId());\r
+ log.debug("Returning null Vobject reference for id " + id.getId());\r
+ return null;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.IClientDocument#getObjects(uk.ac.vamsas.client.VorbaId\r
+ * [])\r
+ */\r
+ public Vobject[] getObjects(VorbaId[] ids) {\r
+ if (objrefs == null) {\r
+ log.debug("getObject[] called on null objrefs list.");\r
+ return null;\r
+ }\r
+ Vobject[] vo = new Vobject[ids.length];\r
+ for (int i = 0, j = ids.length; i < j; i++)\r
+ if (objrefs.containsKey(ids[i]))\r
+ vo[i] = (Vobject) objrefs.get(ids[i]);\r
+ else\r
+ log.debug("Returning null Vobject reference for id " + ids[i].getId());\r
+ return vo;\r
+ }\r
+\r
+ protected void updateDocumentRoots() {\r
+ if (doc == null) {\r
+ log\r
+ .error("updateDocumentRoots called on null document. Probably an implementation error.");\r
+ return;\r
+ }\r
+ if (isModified) {\r
+ if (_VamsasRoots != null) {\r
+ doc.setVAMSAS(_VamsasRoots);\r
+ _VamsasRoots = null;\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * tell vamsas client to close the document and reset the object. Once closed,\r
+ * nothing can be done with the object.\r
+ * \r
+ */\r
+ public void closeDoc() {\r
+ if (doc != null) {\r
+ log.debug("Closing open document.");\r
+ _finalize();\r
+ } else {\r
+ log.warn("Ignoring closeDoc on invalid document.");\r
+ }\r
+ }\r
+\r
+}\r