renamed base class for all vamsas document objects (now org.vamsas.client.Vobject)
[vamsas.git] / src / org / vamsas / client / simpleclient / IdFactory.java
index c046af5..0f3cc36 100644 (file)
@@ -10,6 +10,7 @@ import org.vamsas.client.SessionHandle;
 import org.vamsas.client.UserHandle;
 import org.vamsas.client.VorbaId;
 import org.vamsas.client.VorbaIdFactory;
+import org.vamsas.client.Vobject;
 import org.vamsas.objects.utils.document.VersionEntries;
 
 import java.util.Hashtable;
@@ -26,7 +27,7 @@ public class IdFactory extends VorbaIdFactory {
   private UserHandle user;
   private CRC32 unique=new CRC32(); // used to attempt a unique but predictable stream for IDs
   private String idstring;
-  int sequence=0; // incrementing value for next new ID
+  int sequence=1; // incrementing value for next new ID
   /**
    * 
    */
@@ -47,26 +48,35 @@ public class IdFactory extends VorbaIdFactory {
     this.user = user;
     unique.reset();
     unique.update(new Object[] { session, client, user}.toString().getBytes());
-    idstring = "vamsas:"+session.getSessionUrn()+":"+unique.getValue()+":"+client.getClientUrn()+"/";
-    sequence=0;
+    // TODO: Ensure format of URNs and use standard composition methods.
+    idstring = client.getClientUrn()+":"+unique.getValue()+"/";
     extantids=new Hashtable();
   }
-
+  /**
+   * values for keys in this hash can be used to reference the org.vamsas.client.Vobject instance for the VorbaId string.
+   * @return the hash of all VorbaIds
+   */
+  protected Hashtable getVorbaIdHash() {
+    return extantids;
+  }
+  
   /* (non-Javadoc)
    * @see org.vamsas.client.VorbaIdFactory#makeVorbaId()
    */
-  public VorbaId makeVorbaId() {
+  public VorbaId makeVorbaId(Vobject vobject) {
     if (session==null)
-      throw new Error("makeVorbaId called on improperly initialised IdFactory object!");
+      throw new Error("makeVorbaId called on improperly initialised IdFactory Vobject!");
     String newidstring;
     do {
-      if (sequence!=0) {
+      if (sequence>0) {
         sequence++;
       } else {
         idstring+="1/";
+        sequence=1;
       }
       newidstring=idstring+Integer.toString(sequence);
     } while (extantids.containsKey(newidstring));
+    extantids.put(newidstring, vobject); // hash the Vobject by its new Id
     VorbaId id = newId(newidstring);
     return id;
   }
@@ -132,6 +142,6 @@ public class IdFactory extends VorbaIdFactory {
       clientname="org.vamsas.client.simpleclient.IdFactory";
     return new IdFactory(new SessionHandle("dummy.session"), 
         new ClientHandle(clientname,VersionEntries.latestVersion()), 
-        new UserHandle("arnoldUser", "none"));
+        new UserHandle(clientname, "Arnold User's Inc."));
   }
 }