vorbaId generator constructs valid ID strings (NCNames)
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / IdFactory.java
index a5f3879..09a28e4 100644 (file)
@@ -5,7 +5,6 @@ package uk.ac.vamsas.client.simpleclient;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.vamsas.objects.utils.document.VersionEntries;
 
 import uk.ac.vamsas.client.ClientHandle;
 import uk.ac.vamsas.client.SessionHandle;
@@ -13,6 +12,7 @@ import uk.ac.vamsas.client.UserHandle;
 import uk.ac.vamsas.client.Vobject;
 import uk.ac.vamsas.client.VorbaId;
 import uk.ac.vamsas.client.VorbaIdFactory;
+import uk.ac.vamsas.objects.utils.document.VersionEntries;
 
 import java.util.Hashtable;
 import java.util.zip.CRC32;
@@ -50,11 +50,22 @@ 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.getClientName()+":"+unique.getValue()+".";
+    idstring = client.getClientNCname()+"_"+unique.getValue()+".";
     extantids=new Hashtable();
     this.extanthashv=new Hashtable();
   }
   /**
+   * Create IdFactory with existing object hashes and id set
+   * @param session
+   * @param client
+   * @param user
+   * @param extanthashv hash of existing VorbaIds from a previous read of same document
+   */
+  protected IdFactory(SessionHandle session, ClientHandle client, UserHandle user, Hashtable extanthashv) {
+    this(session, client, user);
+    this.extanthashv = extanthashv;
+  }
+  /**
    * values for keys in this hash can be used to reference the uk.ac.vamsas.client.Vobject instance for the VorbaId string.
    * @return the hash of all VorbaIds
    */
@@ -89,8 +100,8 @@ public class IdFactory extends VorbaIdFactory {
       }
       newidstring=idstring+Integer.toString(sequence);
     } while (extantids.containsKey(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
+    extantids.put(id, vobject); // hash the Vobject by its new Id
     return id;
   }