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.object registry mechanism.
*/
-public class ClientDocument implements IClientDocument {
- protected IClient vorba;
- protected org.vamsas.objects.core.VAMSAS[] roots;
- protected byte[] appData;
-
+public abstract class ClientDocument implements IClientDocument {
+ static Log log = LogFactory.getLog(ClientDocument.class);
+
/**
* collection of org.vamsas.client.object references
*/
protected Hashtable vamsasObjects;
+ protected IVorbaIdFactory vorbafactory;
- /*
- * (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;
+ protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) {
vamsasObjects = objects;
- this.vorba = vorba;
- }
-
- public byte[] getApplicationData() {
- // Look up client byte stash using client and user handle
- return appData;
+ vorbafactory = factory;
}
-
- /*
- * (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 object[] 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.
- }
- }
+ * @see IClientHandle.registerObject(object unregistered)
+ */
+ protected VorbaId _registerObject(object unregistered) {
+ // be ultra safe here because the user may be trying to mix different factories
+ if (unregistered.__vorba==null)
+ unregistered.__vorba = vorbafactory;
+ else
+ if (unregistered.__vorba!=vorbafactory) {
+ // TODO: LATER: decide if this is allowed - it isn't for the moment.
+ log.error("Attempt to overwrite info in a registered vorba object! - Implementation fix needed.");
+ return null;
+ } else {
+ // probably didn't need to call registerObject.
+ log.debug("Redundant call to registerObject");
}
- }
- }
-
- /*
- * (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());
+ // TODO: add default provenance.
+ unregistered.__ensure_instance_ids(); // call cascade method here : TODO: decide if we need to do this.
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<k; i++)
- ids[i]=registerObject(unregistered[i]);
- return ids;
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
- */
- public void setApplicationData(byte[] newData) {
- appData = newData;
- }
}
* These are guaranteed to be unique amongst existing
* objects in the document, all other references created
* by this object's instance and all other references
- * constructed by any other vamsas agents in the session.
- * TODO: Since a clientDocument is created for a particular
+ * constructed by any other vamsas agents in the session.
+ * TODO: NOW! make AppData interface instance for getting/setting 'global' appData and the current users' appData entry.
+ * TODO: LATER: finegrained access control for public/private user access
+ * Finegrained access control: Since a clientDocument is created for a particular
* UserHandle, there is scope for fine grain data access
* control based on user identity.
* A user may also want to make private notes, not
* its own dataspace.
*
* Note: An object with valid VorbaId will not be reregistered.
+ * Advice: Calling this method for a high-level object
+ * (such as org.vamsas.objects.core.VAMSAS) will
+ * register all its component objects too.
+ *
* @param unregistered unregistered vamsas object
* @return VorbaId registered for vamsas object
*/