4 package org.vamsas.client;
6 import java.util.Hashtable;
8 import org.vamsas.objects.core.VAMSAS;
9 import org.vamsas.objects.core.VamsasDocument;
12 * @author jimp Contains a collection of vamsas objects and reference to a
13 * specified ClientHandle's information.
15 public class ClientDocument implements IClientDocument {
16 protected IClient vorba;
17 protected org.vamsas.objects.core.VAMSAS[] roots;
18 protected byte[] appData;
21 * collection of org.vamsas.client.object references
23 protected Hashtable vamsasObjects;
28 * @see org.vamsas.client.IClientDocument#getApplicationData()
38 protected ClientDocument(byte[] data, VAMSAS[] roots, Hashtable objects, IClient vorba) {
39 // TODO Auto-generated constructor stub
42 vamsasObjects = objects;
46 public byte[] getApplicationData() {
47 // Look up client byte stash using client and user handle
54 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
56 public object getObject(VorbaId id) {
57 // TODO: look up id in document object
58 // retrieve object and return
65 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
67 public object[] getObjects(VorbaId[] ids) {
68 // TODO: getObject in bulk
75 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
77 public object[] getVamsasRoots() {
79 // Make a new one to return to client : TODO: Decide if this is correct
80 return new VAMSAS[] { new VAMSAS() };
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 object oldversion = getObject(newroots[i].getVorbaId());
100 if (oldversion instanceof VAMSAS) {
101 // TODO: appropriate merging behaviour when two clients have
102 // modified the same registered object independently
103 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
104 // client has modified this object since last retrieval.
105 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
106 // object has been modified by another client since this
108 // last access to document.
113 "SimpleClient error when using setVamsasRoots : The vorbaId for object "
115 + " does not refer to an object of type VAMSAS in the current document!");
118 if (!newroots[i].is__stored_in_document()) {
119 // check if object is modified
120 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
121 // it is - so we add newroots[i] as a new object, with updated
128 // just add newroots[i] as a new object in the document
129 // - with appropriate provenance.
139 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
141 public VorbaId registerObject(object unregistered) {
142 if (!unregistered.isRegistered())
143 unregistered.setVorbaId(unregistered.__vorba.makeVorbaId());
144 return unregistered.getVorbaId();
149 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[])
151 public VorbaId[] registerObjects(object[] unregistered) {
152 if (unregistered!=null) {
153 VorbaId ids[] = new VorbaId[unregistered.length];
154 for (int i=0,k=unregistered.length; i<k; i++)
155 ids[i]=registerObject(unregistered[i]);
164 * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
166 public void setApplicationData(byte[] newData) {