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 extends org.vamsas.client.ClientDocument implements IClientDocument {
20 protected IClient vorba;
21 protected org.vamsas.objects.core.VAMSAS[] roots;
22 protected byte[] appData;
23 protected VamsasArchive archive = null;
27 * @see org.vamsas.client.IClientDocument#getApplicationData()
32 protected ClientDocument(VamsasArchive document, IdFactory Factory, IClient vorba) {
33 super(Factory.getVorbaIdHash(), Factory);
39 public byte[] getApplicationData() {
40 // Look up client byte stash using client and user handle
47 * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
49 public object getObject(VorbaId id) {
50 // TODO: look up id in document object
51 // retrieve object and return
58 * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
60 public object[] getObjects(VorbaId[] ids) {
61 // TODO: getObject in bulk
68 * @see org.vamsas.client.IClientDocument#getVamsasRoots()
70 public VAMSAS[] getVamsasRoots() {
72 // Make a new one to return to client : TODO: Decide if this is correct
73 return new VAMSAS[] { new VAMSAS() };
78 * update the document with new roots.
80 public void setVamsasRoots(VAMSAS[] newroots) {
81 // extract root objects
82 if (newroots != null) {
83 // check newroots for objects that were present in the old document
84 // check to see if the 'old' objects have been modified
85 // if they have ? we overwrite them with their new version, ensuring that
86 // provenance is updated.
87 // if they haven't ? do nothing ?
89 for (int i = 0, k = newroots.length; i < k; i++) {
90 if (newroots[i].isRegistered()) {
91 // easy - just check if anything has changed and do provenance
92 object oldversion = getObject(newroots[i].getVorbaId());
93 if (oldversion instanceof VAMSAS) {
94 // TODO: appropriate merging behaviour when two clients have
95 // modified the same registered object independently
96 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
97 // client has modified this object since last retrieval.
98 if (newroots[i].get__last_hash() != oldversion.get__last_hash()) {
99 // object has been modified by another client since this
101 // last access to document.
106 "SimpleClient error when using setVamsasRoots : The vorbaId for object "
108 + " does not refer to an object of type VAMSAS in the current document!");
111 if (!newroots[i].is__stored_in_document()) {
112 // check if object is modified
113 if (newroots[i].get__last_hash() != newroots[i].hashCode()) {
114 // it is - so we add newroots[i] as a new object, with updated
121 // just add newroots[i] as a new object in the document
122 // - with appropriate provenance.
130 * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
132 public void addVamsasRoot(VAMSAS newroot) {
133 // TODO Auto-generated method stub
140 * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
142 public void setApplicationData(byte[] newData) {
148 * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[])
150 public VorbaId[] registerObjects(object[] unregistered) {
151 if (unregistered!=null) {
152 VorbaId ids[] = new VorbaId[unregistered.length];
153 for (int i=0,k=unregistered.length; i<k; i++)
154 ids[i]=registerObject(unregistered[i]);
161 * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
163 public VorbaId registerObject(object unregistered) {
164 // TODO: add provenance stuff to newly registered object
165 return _registerObject(unregistered);