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 VamsasArchive archive = null;
34 * prepare Application-side dataset from the vamsas Document archive
35 * @param doc - the dataset
36 * @param docHandler - the sessionFile IO handler
37 * @param Factory - the source of current and new vorbaIds
38 * @param sclient - the simpleclient instance
40 protected ClientDocument(VamsasDocument doc, VamsasArchive docHandler, IdFactory Factory, SimpleClient vorba) {
41 super(Factory.getVorbaIdHash(), Factory);
44 * prepare Application-side dataset from the vamsas Document archive
54 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
56 public Vobject getObject(VorbaId id) {
57 // TODO: look up id in document Vobject
58 // retrieve Vobject and return
65 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
67 public Vobject[] getObjects(VorbaId[] ids) {
68 // TODO: getObject in bulk
75 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
77 public VAMSAS[] getVamsasRoots() {
78 if (doc.getVAMSAS() == null)
79 // Make a new one to return to client : TODO: Decide if this is correct
80 return new VAMSAS[] { new VAMSAS() };
81 return doc.getVAMSAS();
85 * update the document with new roots.
87 public void setVamsasRoots(VAMSAS[] newroots) {
88 // extract root objects
89 if (newroots != null) {
90 // check newroots for objects that were present in the old document
91 // check to see if the 'old' objects have been modified
92 // if they have ? we overwrite them with their new version, ensuring that
93 // provenance is updated.
94 // if they haven't ? do nothing ?
96 for (int i = 0, k = newroots.length; i < k; i++) {
97 if (newroots[i].isRegistered()) {
98 // easy - just check if anything has changed and do provenance
99 Vobject oldversion = getObject(newroots[i].getVorbaId());
100 if (oldversion instanceof VAMSAS) {
101 // LATER: appropriate merging behaviour when two clients have
102 // modified the same registered Vobject independently
103 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
104 // client has modified this Vobject since last retrieval.
105 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
106 // Vobject has been modified by another client since this
108 // last access to document.
113 "SimpleClient error when using setVamsasRoots : The vorbaId for Vobject "
115 + " does not refer to an Vobject of type VAMSAS in the current document!");
118 if (!newroots[i].is__stored_in_document()) {
119 // check if Vobject is modified
120 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
121 // it is - so we add newroots[i] as a new Vobject, with updated
128 // just add newroots[i] as a new Vobject in the document
129 // - with appropriate provenance.
137 * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
139 public void addVamsasRoot(VAMSAS newroot) {
140 // TODO Auto-generated method stub
147 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.Vobject[])
149 public VorbaId[] registerObjects(Vobject[] unregistered) {
150 if (unregistered!=null) {
151 VorbaId ids[] = new VorbaId[unregistered.length];
152 for (int i=0,k=unregistered.length; i<k; i++)
153 ids[i]=registerObject(unregistered[i]);
160 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.Vobject)
162 public VorbaId registerObject(Vobject unregistered) {
163 // TODO: add provenance stuff to newly registered Vobject
164 return _registerObject(unregistered);
167 * IClientAppdata instance - if it exists.
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