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.object;
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 IClient vorba;
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 vorba - the client instance
43 protected ClientDocument(VamsasDocument doc, VamsasArchive docHandler, IdFactory Factory, IClient vorba) {
44 super(Factory.getVorbaIdHash(), Factory);
47 * prepare Application-side dataset from the vamsas Document archive
55 * gets appropriate app data for the application, if it exists in this dataset
58 private void extractAppData() {
59 Vector apldataset = AppDataReference.getUserandApplicationsData(
60 doc, vorbafactory.getUserHandle(), vorbafactory.getClientHandle());
61 if (apldataset!=null) {
62 if (apldataset.size()>0) {
63 AppData clientdat = (AppData) apldataset.get(0);
64 if (clientdat instanceof ApplicationData) {
65 appsglobal = (ApplicationData) clientdat;
66 if (apldataset.size()>1) {
67 clientdat = (AppData) apldataset.get(1);
68 if (clientdat instanceof User)
69 usersdata = (User) clientdat;
70 if (apldataset.size()>2)
71 log.info("Ignoring additional ("+(apldataset.size()-2)+") AppDatas returned by document appdata query.");
74 log.warn("Unexpected entry in AppDataReference query: id="+clientdat.getVorbaId()+" type="+clientdat.getClass().getName());
83 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
85 public object getObject(VorbaId id) {
86 // TODO: look up id in document object
87 // retrieve object and return
94 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
96 public object[] getObjects(VorbaId[] ids) {
97 // TODO: getObject in bulk
104 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
106 public VAMSAS[] getVamsasRoots() {
107 if (doc.getVAMSAS() == null)
108 // Make a new one to return to client : TODO: Decide if this is correct
109 return new VAMSAS[] { new VAMSAS() };
110 return doc.getVAMSAS();
114 * update the document with new roots.
116 public void setVamsasRoots(VAMSAS[] newroots) {
117 // extract root objects
118 if (newroots != null) {
119 // check newroots for objects that were present in the old document
120 // check to see if the 'old' objects have been modified
121 // if they have ? we overwrite them with their new version, ensuring that
122 // provenance is updated.
123 // if they haven't ? do nothing ?
125 for (int i = 0, k = newroots.length; i < k; i++) {
126 if (newroots[i].isRegistered()) {
127 // easy - just check if anything has changed and do provenance
128 object oldversion = getObject(newroots[i].getVorbaId());
129 if (oldversion instanceof VAMSAS) {
130 // TODO: appropriate merging behaviour when two clients have
131 // modified the same registered object independently
132 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
133 // client has modified this object since last retrieval.
134 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
135 // object has been modified by another client since this
137 // last access to document.
142 "SimpleClient error when using setVamsasRoots : The vorbaId for object "
144 + " does not refer to an object of type VAMSAS in the current document!");
147 if (!newroots[i].is__stored_in_document()) {
148 // check if object is modified
149 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
150 // it is - so we add newroots[i] as a new object, with updated
157 // just add newroots[i] as a new object in the document
158 // - with appropriate provenance.
166 * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
168 public void addVamsasRoot(VAMSAS newroot) {
169 // TODO Auto-generated method stub
176 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[])
178 public VorbaId[] registerObjects(object[] unregistered) {
179 if (unregistered!=null) {
180 VorbaId ids[] = new VorbaId[unregistered.length];
181 for (int i=0,k=unregistered.length; i<k; i++)
182 ids[i]=registerObject(unregistered[i]);
189 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
191 public VorbaId registerObject(object unregistered) {
192 // TODO: add provenance stuff to newly registered object
193 return _registerObject(unregistered);
196 * @see org.vamsas.client.IClientDocument#getClientAppdata()
198 public IClientAppdata getClientAppdata() {
199 // TODO Auto-generated method stub