tidier file locks - lock file is removed on JVM exit.
[vamsas.git] / src / org / vamsas / client / simpleclient / IdFactory.java
index 36fd3bc..dafd08e 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;
@@ -48,16 +49,27 @@ public class IdFactory extends VorbaIdFactory {
     unique.reset();
     unique.update(new Object[] { session, client, user}.toString().getBytes());
     // TODO: Ensure format of URNs and use standard composition methods.
-    idstring = client.getClientUrn()+":"+unique.getValue()+"/";
+    idstring = client.getClientName()+":"+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!");
+    if (!vobject.isRegisterable())
+      throw new Error("makeVorbaId called on unregisterable object.");
+    if (vobject.isRegistered())
+      throw new Error("makeVorbaId called on already registered object.");
     String newidstring;
     do {
       if (sequence>0) {
@@ -68,7 +80,8 @@ public class IdFactory extends VorbaIdFactory {
       }
       newidstring=idstring+Integer.toString(sequence);
     } while (extantids.containsKey(newidstring));
-    VorbaId id = newId(newidstring);
+    extantids.put(newidstring, vobject); // hash the Vobject by its new Id
+    VorbaId id = newId(newidstring); // VorbaId.hash()==newidstring.hash() so we can still recover vobject
     return id;
   }