4 package org.vamsas.client.simpleclient;
6 import java.util.Hashtable;
7 import java.util.Vector;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.vamsas.client.IClient;
12 import org.vamsas.client.IClientAppdata;
13 import org.vamsas.client.IClientDocument;
14 import org.vamsas.client.VorbaId;
15 import org.vamsas.client.Vobject;
16 import org.vamsas.objects.core.AppData;
17 import org.vamsas.objects.core.ApplicationData;
18 import org.vamsas.objects.core.User;
19 import org.vamsas.objects.core.VAMSAS;
20 import org.vamsas.objects.core.VamsasDocument;
21 import org.vamsas.objects.utils.AppDataReference;
24 * @author jimp Contains a collection of vamsas objects and reference to a
25 * specified ClientHandle's information.
27 public class ClientDocument extends org.vamsas.client.ClientDocument implements IClientDocument {
28 private static Log log = LogFactory.getLog(ClientDocument.class);
29 private VamsasDocument doc;
30 protected SimpleClient sclient;
31 protected ApplicationData appsglobal=null;
32 protected User usersdata=null;
33 protected byte[] appData=null;
34 protected VamsasArchive archive = null;
37 * prepare Application-side dataset from the vamsas Document archive
38 * @param doc - the dataset
39 * @param docHandler - the sessionFile IO handler
40 * @param Factory - the source of current and new vorbaIds
41 * @param sclient - the simpleclient instance
43 protected ClientDocument(VamsasDocument doc, VamsasArchive docHandler, IdFactory Factory, SimpleClient vorba) {
44 super(Factory.getVorbaIdHash(), Factory);
47 * prepare Application-side dataset from the vamsas Document archive
57 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
59 public Vobject getObject(VorbaId id) {
60 // TODO: look up id in document Vobject
61 // retrieve Vobject and return
68 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
70 public Vobject[] getObjects(VorbaId[] ids) {
71 // TODO: getObject in bulk
78 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
80 public VAMSAS[] getVamsasRoots() {
81 if (doc.getVAMSAS() == null)
82 // Make a new one to return to client : TODO: Decide if this is correct
83 return new VAMSAS[] { new VAMSAS() };
84 return doc.getVAMSAS();
88 * update the document with new roots.
90 public void setVamsasRoots(VAMSAS[] newroots) {
91 // extract root objects
92 if (newroots != null) {
93 // check newroots for objects that were present in the old document
94 // check to see if the 'old' objects have been modified
95 // if they have ? we overwrite them with their new version, ensuring that
96 // provenance is updated.
97 // if they haven't ? do nothing ?
99 for (int i = 0, k = newroots.length; i < k; i++) {
100 if (newroots[i].isRegistered()) {
101 // easy - just check if anything has changed and do provenance
102 Vobject oldversion = getObject(newroots[i].getVorbaId());
103 if (oldversion instanceof VAMSAS) {
104 // LATER: appropriate merging behaviour when two clients have
105 // modified the same registered Vobject independently
106 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
107 // client has modified this Vobject since last retrieval.
108 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
109 // Vobject has been modified by another client since this
111 // last access to document.
116 "SimpleClient error when using setVamsasRoots : The vorbaId for Vobject "
118 + " does not refer to an Vobject of type VAMSAS in the current document!");
121 if (!newroots[i].is__stored_in_document()) {
122 // check if Vobject is modified
123 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
124 // it is - so we add newroots[i] as a new Vobject, with updated
131 // just add newroots[i] as a new Vobject in the document
132 // - with appropriate provenance.
140 * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
142 public void addVamsasRoot(VAMSAS newroot) {
143 // TODO Auto-generated method stub
150 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.Vobject[])
152 public VorbaId[] registerObjects(Vobject[] unregistered) {
153 if (unregistered!=null) {
154 VorbaId ids[] = new VorbaId[unregistered.length];
155 for (int i=0,k=unregistered.length; i<k; i++)
156 ids[i]=registerObject(unregistered[i]);
163 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.Vobject)
165 public VorbaId registerObject(Vobject unregistered) {
166 // TODO: add provenance stuff to newly registered Vobject
167 return _registerObject(unregistered);
169 SimpleClientAppdata scappd = null;
171 * @see org.vamsas.client.IClientDocument#getClientAppdata()
173 public IClientAppdata getClientAppdata() {
175 log.debug("Creating new SimpleClientAppdata instance for "+sclient.getSessionHandle());
176 scappd = new SimpleClientAppdata(this);
178 // LATER: may not need this as a warning message.
179 log.warn("Null appdata object for "+sclient.getSessionHandle());
181 log.debug("Created SimpleClientAppdata successfully.");
184 log.debug("Returning existing SimpleClientAppdata reference.");
189 * @see java.lang.Object#finalize()
191 protected void finalize() throws Throwable {
192 log.debug("Garbage collecting on ClientDocument instance.");
201 * access the vamsas document
202 * @return the session's vamsas document
204 protected VamsasDocument getVamsasDocument() {
209 * returns the read-only IO interface for the vamsas document Jar file
212 protected VamsasArchiveReader getVamsasArchiveReader() {
213 // TODO: IMPLEMENT getVamsasArchiveReader