X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fvamsas%2Ftest%2Fsimpleclient%2FClientDoc.java;h=da05e0090027c26f51c20a4b59522a36ae1e1947;hb=7700d838b129db99edacb208b3153546795a33c7;hp=f15eec5ebd532def9751fa0baf881768a3696643;hpb=c48e7dc90f1cc593738404dcf83a8a36e1b9a3b0;p=vamsas.git diff --git a/src/org/vamsas/test/simpleclient/ClientDoc.java b/src/org/vamsas/test/simpleclient/ClientDoc.java index f15eec5..da05e00 100644 --- a/src/org/vamsas/test/simpleclient/ClientDoc.java +++ b/src/org/vamsas/test/simpleclient/ClientDoc.java @@ -5,6 +5,7 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.vamsas.client.IClientAppdata; import org.vamsas.client.Vobject; import org.vamsas.client.VorbaId; import org.vamsas.client.simpleclient.ClientDocument; @@ -16,7 +17,13 @@ import org.vamsas.objects.core.VamsasDocument; import org.vamsas.objects.utils.ProvenanceStuff; // simple holder to pass to client. -public class ClientDoc { +public class ClientDoc extends org.vamsas.client.ClientDocument { + /* (non-Javadoc) + * @see org.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; @@ -24,18 +31,21 @@ public class ClientDoc { 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 user, Hashtable objrefs) { - super(); + 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(); @@ -47,7 +57,7 @@ public class ClientDoc { */ 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(user, action); + Entry prov = ProvenanceStuff.newProvenanceEntry(app, user, action); return prov; } public VAMSAS[] getVamsasRoots() { @@ -206,14 +216,32 @@ public class ClientDoc { 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(); - //if (reader!=null) - // reader.close(); - //reader=null; -// if (iohandler!=null) { -// iohandler.cancelArchive(); // otherwise the original may be overwritten. -// } } private java.util.Hashtable objrefs=null; @@ -258,14 +286,13 @@ public class ClientDoc { } if (unregistered!=null) { - VorbaId id = iohandler.getVorba().makeVorbaId(unregistered); + 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) * @@ -276,8 +303,8 @@ public class ClientDoc { log.debug("getObject called on null objrefs list."); return null; } - if (objrefs.containsKey(id)) - return (Vobject) objrefs.get(id); + if (objrefs.containsKey(id.getId())) + return (Vobject) objrefs.get(id.getId()); log.debug("Returning null Vobject reference for id "+id.getId()); return null; } @@ -300,5 +327,29 @@ public class ClientDoc { 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