4 package org.vamsas.client.simpleclient;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.vamsas.client.ClientHandle;
9 import org.vamsas.client.SessionHandle;
10 import org.vamsas.client.UserHandle;
11 import org.vamsas.client.VorbaId;
12 import org.vamsas.client.VorbaIdFactory;
13 import org.vamsas.objects.utils.document.VersionEntries;
15 import java.util.Hashtable;
16 import java.util.zip.CRC32;
18 * Simplest VorbaId constructor
22 public class IdFactory extends VorbaIdFactory {
23 static Log log = LogFactory.getLog(IdFactory.class);
24 private SessionHandle session=null;
25 private ClientHandle client;
26 private UserHandle user;
27 private CRC32 unique=new CRC32(); // used to attempt a unique but predictable stream for IDs
28 private String idstring;
29 int sequence=1; // incrementing value for next new ID
35 // TODO Auto-generated constructor stub
43 protected IdFactory(SessionHandle session, ClientHandle client, UserHandle user) {
45 this.session = session;
49 unique.update(new Object[] { session, client, user}.toString().getBytes());
50 // TODO: Ensure format of URNs and use standard composition methods.
51 idstring = client.getClientUrn()+":"+unique.getValue()+"/";
52 extantids=new Hashtable();
55 * values for keys in this hash can be used to reference the org.vamsas.client.object instance for the VorbaId string.
56 * @return the hash of all VorbaIds
58 protected Hashtable getVorbaIdHash() {
63 * @see org.vamsas.client.VorbaIdFactory#makeVorbaId()
65 public VorbaId makeVorbaId() {
67 throw new Error("makeVorbaId called on improperly initialised IdFactory object!");
76 newidstring=idstring+Integer.toString(sequence);
77 } while (extantids.containsKey(newidstring));
78 VorbaId id = newId(newidstring);
83 * @see org.vamsas.client.VorbaIdFactory#setSession(org.vamsas.client.SessionHandle)
85 protected void setSession(SessionHandle sessionhandle) {
86 if (sessionhandle!=null)
87 session=sessionhandle;
89 log.warn("setSession(null) called.");
93 * @see org.vamsas.client.VorbaIdFactory#getSessionHandle()
95 public SessionHandle getSessionHandle() {
100 * @see org.vamsas.client.VorbaIdFactory#setClient(org.vamsas.client.ClientHandle)
102 protected void setClient(ClientHandle appHandle) {
106 log.warn("setClient(null) called.");
110 * @see org.vamsas.client.VorbaIdFactory#getClientHandle()
112 public ClientHandle getClientHandle() {
117 * @see org.vamsas.client.VorbaIdFactory#setUser(org.vamsas.client.UserHandle)
119 protected void setUser(UserHandle userHandle) {
120 if (userHandle!=null)
123 log.warn("setUser(null) called.");
127 * @see org.vamsas.client.VorbaIdFactory#getUserHandle()
129 public UserHandle getUserHandle() {
133 * Convenience method used for default behaviour in testing
134 * and any anonymous internal vamsasDocument unmarshalling
138 protected static IdFactory getDummyFactory(String clientname) {
139 if (clientname==null)
140 clientname="org.vamsas.client.simpleclient.IdFactory";
141 return new IdFactory(new SessionHandle("dummy.session"),
142 new ClientHandle(clientname,VersionEntries.latestVersion()),
143 new UserHandle(clientname, "Arnold User's Inc."));