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();
56 * @see org.vamsas.client.VorbaIdFactory#makeVorbaId()
58 public VorbaId makeVorbaId() {
60 throw new Error("makeVorbaId called on improperly initialised IdFactory object!");
69 newidstring=idstring+Integer.toString(sequence);
70 } while (extantids.containsKey(newidstring));
71 VorbaId id = newId(newidstring);
76 * @see org.vamsas.client.VorbaIdFactory#setSession(org.vamsas.client.SessionHandle)
78 protected void setSession(SessionHandle sessionhandle) {
79 if (sessionhandle!=null)
80 session=sessionhandle;
82 log.warn("setSession(null) called.");
86 * @see org.vamsas.client.VorbaIdFactory#getSessionHandle()
88 public SessionHandle getSessionHandle() {
93 * @see org.vamsas.client.VorbaIdFactory#setClient(org.vamsas.client.ClientHandle)
95 protected void setClient(ClientHandle appHandle) {
99 log.warn("setClient(null) called.");
103 * @see org.vamsas.client.VorbaIdFactory#getClientHandle()
105 public ClientHandle getClientHandle() {
110 * @see org.vamsas.client.VorbaIdFactory#setUser(org.vamsas.client.UserHandle)
112 protected void setUser(UserHandle userHandle) {
113 if (userHandle!=null)
116 log.warn("setUser(null) called.");
120 * @see org.vamsas.client.VorbaIdFactory#getUserHandle()
122 public UserHandle getUserHandle() {
126 * Convenience method used for default behaviour in testing
127 * and any anonymous internal vamsasDocument unmarshalling
131 protected static IdFactory getDummyFactory(String clientname) {
132 if (clientname==null)
133 clientname="org.vamsas.client.simpleclient.IdFactory";
134 return new IdFactory(new SessionHandle("dummy.session"),
135 new ClientHandle(clientname,VersionEntries.latestVersion()),
136 new UserHandle("arnoldUser", "none"));