/* * */ package org.vamsas.client.simpleclient; import java.util.Hashtable; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.vamsas.client.IClient; import org.vamsas.client.IClientAppdata; import org.vamsas.client.IClientDocument; import org.vamsas.client.VorbaId; import org.vamsas.client.Vobject; import org.vamsas.objects.core.AppData; import org.vamsas.objects.core.ApplicationData; import org.vamsas.objects.core.User; import org.vamsas.objects.core.VAMSAS; import org.vamsas.objects.core.VamsasDocument; import org.vamsas.objects.utils.AppDataReference; /** * @author jimp Contains a collection of vamsas objects and reference to a * specified ClientHandle's information. */ public class ClientDocument extends org.vamsas.client.ClientDocument implements IClientDocument { private static Log log = LogFactory.getLog(ClientDocument.class); private VamsasDocument doc; protected SimpleClient sclient; protected VamsasArchive archive = null; /** * * prepare Application-side dataset from the vamsas Document archive * @param doc - the dataset * @param docHandler - the sessionFile IO handler * @param Factory - the source of current and new vorbaIds * @param sclient - the simpleclient instance */ protected ClientDocument(VamsasDocument doc, VamsasArchive docHandler, IdFactory Factory, SimpleClient vorba) { super(Factory.getVorbaIdHash(), Factory); /** * prepare Application-side dataset from the vamsas Document archive */ this.sclient = vorba; archive = docHandler; this.doc = doc; } /* * (non-Javadoc) * * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId) */ public Vobject getObject(VorbaId id) { // TODO: look up id in document Vobject // retrieve Vobject and return return null; } /* * (non-Javadoc) * * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[]) */ public Vobject[] getObjects(VorbaId[] ids) { // TODO: getObject in bulk return null; } /* * (non-Javadoc) * * @see org.vamsas.client.IClientDocument#getVamsasRoots() */ public VAMSAS[] getVamsasRoots() { if (doc.getVAMSAS() == null) // Make a new one to return to client : TODO: Decide if this is correct return new VAMSAS[] { new VAMSAS() }; return doc.getVAMSAS(); } /** * 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 Vobject oldversion = getObject(newroots[i].getVorbaId()); if (oldversion instanceof VAMSAS) { // LATER: appropriate merging behaviour when two clients have // modified the same registered Vobject independently if (newroots[i].get__last_hash() != newroots[i].hashCode()) { // client has modified this Vobject since last retrieval. if (newroots[i].get__last_hash() != oldversion.get__last_hash()) { // Vobject 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 Vobject " + i + " does not refer to an Vobject of type VAMSAS in the current document!"); } } else { if (!newroots[i].is__stored_in_document()) { // check if Vobject is modified if (newroots[i].get__last_hash() != newroots[i].hashCode()) { // it is - so we add newroots[i] as a new Vobject, with updated // provenance. } else { // do nothing newroots[i] = null; } } else { // just add newroots[i] as a new Vobject 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#registerObjects(org.vamsas.client.Vobject[]) */ public VorbaId[] registerObjects(Vobject[] unregistered) { if (unregistered!=null) { VorbaId ids[] = new VorbaId[unregistered.length]; for (int i=0,k=unregistered.length; i