renamed base class for all vamsas document objects (now org.vamsas.client.Vobject)
[vamsas.git] / src / org / vamsas / client / ClientDocument.java
index 2a3ce45..005cb60 100644 (file)
@@ -5,67 +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;
+
 /**
- * @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 {
-  IClient vorba;
-       /* (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
-    return null;
-  }
-  /* (non-Javadoc)
-   * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
-   */
-  public VorbaId registerObject(object unregistered) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-  /* (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
-
+public abstract class ClientDocument implements IClientDocument {
+  static Log log = LogFactory.getLog(ClientDocument.class);
+  
+  /**
+   * collection of org.vamsas.client.Vobject references
+   */
+  protected Hashtable vamsasObjects;
+  protected IVorbaIdFactory vorbafactory;
+  
+  protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) {
+    vamsasObjects = objects;
+    vorbafactory = factory;
   }
+  
   /**
-   * collection of org.vamsas.client.objects
-   */
-  Hashtable VamsasObjects;
-  byte[] appData;
+   * @see IClientHandle.registerObject(Vobject unregistered)
+   */
+  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
+      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();
+  }
 }