X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Forg%2Fvamsas%2Fclient%2FClientDocument.java;h=005cb60d14f609390ab841aa32ea2a2212bb12a1;hb=f0307c09bb32271a55b287b06f9e4b9f71526c04;hp=d3a38866b7fd196282c3e8e2a6c6361e37ef7689;hpb=4e2e8ec4215ad0f0864048e3eb44fdb7ec494e15;p=vamsas.git diff --git a/src/org/vamsas/client/ClientDocument.java b/src/org/vamsas/client/ClientDocument.java index d3a3886..005cb60 100644 --- a/src/org/vamsas/client/ClientDocument.java +++ b/src/org/vamsas/client/ClientDocument.java @@ -5,153 +5,46 @@ package org.vamsas.client; import java.util.Hashtable; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; 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. + * skeleton abstract class to allow client implementations + * access to vamsas.client.Vobject registry mechanism. */ -public class ClientDocument implements IClientDocument { - protected IClient vorba; - - protected VamsasDocument doc; - - protected byte[] appData; - +public abstract class ClientDocument implements IClientDocument { + static Log log = LogFactory.getLog(ClientDocument.class); + /** - * collection of org.vamsas.client.object references + * collection of org.vamsas.client.Vobject references */ protected Hashtable vamsasObjects; - - /* - * (non-Javadoc) - * - * @see org.vamsas.client.IClientDocument#getApplicationData() - */ - - public byte[] getApplicationData() { - // Look up client byte stash using client and user handle - - return null; - } - - /* - * (non-Javadoc) - * - * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId) - */ - public object getObject(VorbaId id) { - // 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) { - // getObject in bulk - return null; - } - - /* - * (non-Javadoc) - * - * @see org.vamsas.client.IClientDocument#getVamsasRoots() - */ - public object[] getVamsasRoots() { - // extract root objects - VAMSAS[] roots = doc.getVAMSAS(); - if (roots == null) - return new VAMSAS[] { new VAMSAS() }; - return roots; + protected IVorbaIdFactory vorbafactory; + + protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) { + vamsasObjects = objects; + vorbafactory = factory; } - + /** - * update the document with new roots. - */ - public void setVamsasRoots(VAMSAS[] newroots) { - // extract root objects - VAMSAS[] roots = doc.getVAMSAS(); - 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( - "Client 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#registerObject(org.vamsas.client.object) + * @see IClientHandle.registerObject(Vobject unregistered) */ -public VorbaId registerObject(object unregistered) { - VorbaId rtn; - if (!unregistered.isRegistered()) - unregistered.VorbaId.(rtn=unregistered.__vorba.makeVorbaId()); + protected VorbaId _registerObject(Vobject unregistered) { + // be ultra safe here because the user may be trying to mix different factories + if (unregistered.__vorba==null) + unregistered.__vorba = vorbafactory; else - return unregistered.getVorbaId(); - } - /* - * (non-Javadoc) - * - * @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.object[]) - */ - public VorbaId[] registerObjects(object[] unregistered) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.vamsas.client.IClientDocument#setApplicationData(byte[]) - */ - public void setApplicationData(byte[] newData) { - // TODO Auto-generated method stub - + if (unregistered.__vorba!=vorbafactory) { + // LATER: decide if this is allowed - it isn't for the moment. + log.error("Attempt to overwrite info in a registered vorba Vobject (under a different IVorgaIdFactory) ! - Implementation fix needed."); + return null; + } else { + // probably didn't need to call registerObject. + log.debug("Redundant call to registerObject"); + } + // TODO: add default provenance. + unregistered.__ensure_instance_ids(); // call cascade method here : TODO: decide if we need to do this. + return unregistered.getVorbaId(); } }