From: jprocter Date: Thu, 19 Jan 2006 12:12:42 +0000 (+0000) Subject: moved IClientDocument implementation into the simpleclient package. X-Git-Tag: Release_0.2~374 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f3af117d920c6f83236cbfece1bd59a59a46fc45;p=vamsas.git moved IClientDocument implementation into the simpleclient package. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@146 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/ClientDocument.java b/src/org/vamsas/client/simpleclient/ClientDocument.java new file mode 100644 index 0000000..05fe494 --- /dev/null +++ b/src/org/vamsas/client/simpleclient/ClientDocument.java @@ -0,0 +1,181 @@ +/* + * + */ +package org.vamsas.client.simpleclient; + +import java.util.Hashtable; + +import org.vamsas.client.IClient; +import org.vamsas.client.IClientDocument; +import org.vamsas.client.VorbaId; +import org.vamsas.client.object; +import org.vamsas.objects.core.VAMSAS; +import org.vamsas.objects.core.VamsasDocument; + +/** + * @author jimp Contains a collection of vamsas objects and reference to a + * specified ClientHandle's information. + */ +public class ClientDocument implements IClientDocument { + protected IClient vorba; + protected org.vamsas.objects.core.VAMSAS[] roots; + protected byte[] appData; + + /** + * collection of org.vamsas.client.object references + */ + protected Hashtable vamsasObjects; + + /* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#getApplicationData() + */ + + /** + * + * @param data + * @param doc + * @param objects + * @param vorba + */ + protected ClientDocument(byte[] data, VAMSAS[] roots, Hashtable objects, IClient vorba) { + // TODO Auto-generated constructor stub + appData = data; + this.roots =roots; + vamsasObjects = objects; + this.vorba = vorba; + } + + public byte[] getApplicationData() { + // Look up client byte stash using client and user handle + return appData; + } + + /* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId) + */ + public object getObject(VorbaId id) { + // TODO: look up id in document object + // retrieve object and return + return null; + } + + /* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[]) + */ + public object[] getObjects(VorbaId[] ids) { + // TODO: getObject in bulk + return null; + } + + /* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#getVamsasRoots() + */ + public VAMSAS[] getVamsasRoots() { + if (roots == null) + // Make a new one to return to client : TODO: Decide if this is correct + return new VAMSAS[] { new VAMSAS() }; + return roots; + } + + /** + * update the document with new roots. + */ + public void setVamsasRoots(VAMSAS[] newroots) { + // extract root objects + if (newroots != null) { + // check newroots for objects that were present in the old document + // check to see if the 'old' objects have been modified + // if they have ? we overwrite them with their new version, ensuring that + // provenance is updated. + // if they haven't ? do nothing ? + + for (int i = 0, k = newroots.length; i < k; i++) { + if (newroots[i].isRegistered()) { + // easy - just check if anything has changed and do provenance + object oldversion = getObject(newroots[i].getVorbaId()); + if (oldversion instanceof VAMSAS) { + // TODO: appropriate merging behaviour when two clients have + // modified the same registered object independently + if (newroots[i].get__last_hash() != newroots[i].hashCode()) { + // client has modified this object since last retrieval. + if (newroots[i].get__last_hash() != oldversion.get__last_hash()) { + // object has been modified by another client since this + // client's + // last access to document. + } + } + } else { + throw new Error( + "SimpleClient error when using setVamsasRoots : The vorbaId for object " + + i + + " does not refer to an object of type VAMSAS in the current document!"); + } + } else { + if (!newroots[i].is__stored_in_document()) { + // check if object is modified + if (newroots[i].get__last_hash() != newroots[i].hashCode()) { + // it is - so we add newroots[i] as a new object, with updated + // provenance. + } else { + // do nothing + newroots[i] = null; + } + } else { + // just add newroots[i] as a new object in the document + // - with appropriate provenance. + } + } + } + } + } + + /* (non-Javadoc) + * @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS) + */ + public void addVamsasRoot(VAMSAS newroot) { + // TODO Auto-generated method stub + + } + +/* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object) + */ +public VorbaId registerObject(object unregistered) { + if (!unregistered.isRegistered()) + unregistered.setVorbaId(unregistered.__vorba.makeVorbaId()); + return unregistered.getVorbaId(); + } + /* + * (non-Javadoc) + * + * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[]) + */ + public VorbaId[] registerObjects(object[] unregistered) { + if (unregistered!=null) { + VorbaId ids[] = new VorbaId[unregistered.length]; + for (int i=0,k=unregistered.length; i