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=0; // 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 idstring = "vamsas:"+session.getSessionUrn()+":"+unique.getValue()+":"+client.getClientUrn()+"/";
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!");
68 newidstring=idstring+Integer.toString(sequence);
69 } while (extantids.containsKey(newidstring));
70 VorbaId id = newId(newidstring);
75 * @see org.vamsas.client.VorbaIdFactory#setSession(org.vamsas.client.SessionHandle)
77 protected void setSession(SessionHandle sessionhandle) {
78 if (sessionhandle!=null)
79 session=sessionhandle;
81 log.warn("setSession(null) called.");
85 * @see org.vamsas.client.VorbaIdFactory#getSessionHandle()
87 public SessionHandle getSessionHandle() {
92 * @see org.vamsas.client.VorbaIdFactory#setClient(org.vamsas.client.ClientHandle)
94 protected void setClient(ClientHandle appHandle) {
98 log.warn("setClient(null) called.");
102 * @see org.vamsas.client.VorbaIdFactory#getClientHandle()
104 public ClientHandle getClientHandle() {
109 * @see org.vamsas.client.VorbaIdFactory#setUser(org.vamsas.client.UserHandle)
111 protected void setUser(UserHandle userHandle) {
112 if (userHandle!=null)
115 log.warn("setUser(null) called.");
119 * @see org.vamsas.client.VorbaIdFactory#getUserHandle()
121 public UserHandle getUserHandle() {
125 * Convenience method used for default behaviour in testing
126 * and any anonymous internal vamsasDocument unmarshalling
130 protected static IdFactory getDummyFactory(String clientname) {
131 if (clientname==null)
132 clientname="org.vamsas.client.simpleclient.IdFactory";
133 return new IdFactory(new SessionHandle("dummy.session"),
134 new ClientHandle(clientname,VersionEntries.latestVersion()),
135 new UserHandle("arnoldUser", "none"));