4 package org.vamsas.client.simpleclient;
6 import java.util.Hashtable;
8 import org.vamsas.client.IClient;
9 import org.vamsas.client.IClientDocument;
10 import org.vamsas.client.VorbaId;
11 import org.vamsas.client.object;
12 import org.vamsas.objects.core.VAMSAS;
13 import org.vamsas.objects.core.VamsasDocument;
16 * @author jimp Contains a collection of vamsas objects and reference to a
17 * specified ClientHandle's information.
19 public class ClientDocument implements IClientDocument {
20 protected IClient vorba;
21 protected org.vamsas.objects.core.VAMSAS[] roots;
22 protected byte[] appData;
25 * collection of org.vamsas.client.object references
27 protected Hashtable vamsasObjects;
32 * @see org.vamsas.client.IClientDocument#getApplicationData()
42 protected ClientDocument(byte[] data, VAMSAS[] roots, Hashtable objects, IClient vorba) {
43 // TODO Auto-generated constructor stub
46 vamsasObjects = objects;
50 public byte[] getApplicationData() {
51 // Look up client byte stash using client and user handle
58 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
60 public object getObject(VorbaId id) {
61 // TODO: look up id in document object
62 // retrieve object and return
69 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
71 public object[] getObjects(VorbaId[] ids) {
72 // TODO: getObject in bulk
79 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
81 public VAMSAS[] getVamsasRoots() {
83 // Make a new one to return to client : TODO: Decide if this is correct
84 return new VAMSAS[] { new VAMSAS() };
89 * update the document with new roots.
91 public void setVamsasRoots(VAMSAS[] newroots) {
92 // extract root objects
93 if (newroots != null) {
94 // check newroots for objects that were present in the old document
95 // check to see if the 'old' objects have been modified
96 // if they have ? we overwrite them with their new version, ensuring that
97 // provenance is updated.
98 // if they haven't ? do nothing ?
100 for (int i = 0, k = newroots.length; i < k; i++) {
101 if (newroots[i].isRegistered()) {
102 // easy - just check if anything has changed and do provenance
103 object oldversion = getObject(newroots[i].getVorbaId());
104 if (oldversion instanceof VAMSAS) {
105 // TODO: appropriate merging behaviour when two clients have
106 // modified the same registered object independently
107 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
108 // client has modified this object since last retrieval.
109 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
110 // object has been modified by another client since this
112 // last access to document.
117 "SimpleClient error when using setVamsasRoots : The vorbaId for object "
119 + " does not refer to an object of type VAMSAS in the current document!");
122 if (!newroots[i].is__stored_in_document()) {
123 // check if object is modified
124 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
125 // it is - so we add newroots[i] as a new object, with updated
132 // just add newroots[i] as a new object in the document
133 // - with appropriate provenance.
141 * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
143 public void addVamsasRoot(VAMSAS newroot) {
144 // TODO Auto-generated method stub
151 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
153 public VorbaId registerObject(object unregistered) {
154 if (!unregistered.isRegistered())
155 unregistered.setVorbaId(unregistered.__vorba.makeVorbaId());
156 return unregistered.getVorbaId();
161 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[])
163 public VorbaId[] registerObjects(object[] unregistered) {
164 if (unregistered!=null) {
165 VorbaId ids[] = new VorbaId[unregistered.length];
166 for (int i=0,k=unregistered.length; i<k; i++)
167 ids[i]=registerObject(unregistered[i]);
176 * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
178 public void setApplicationData(byte[] newData) {