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.client.object;
14 import org.vamsas.objects.utils.document.VersionEntries;
16 import java.util.Hashtable;
17 import java.util.zip.CRC32;
19 * Simplest VorbaId constructor
23 public class IdFactory extends VorbaIdFactory {
24 static Log log = LogFactory.getLog(IdFactory.class);
25 private SessionHandle session=null;
26 private ClientHandle client;
27 private UserHandle user;
28 private CRC32 unique=new CRC32(); // used to attempt a unique but predictable stream for IDs
29 private String idstring;
30 int sequence=1; // incrementing value for next new ID
36 // TODO Auto-generated constructor stub
44 protected IdFactory(SessionHandle session, ClientHandle client, UserHandle user) {
46 this.session = session;
50 unique.update(new Object[] { session, client, user}.toString().getBytes());
51 // TODO: Ensure format of URNs and use standard composition methods.
52 idstring = client.getClientUrn()+":"+unique.getValue()+"/";
53 extantids=new Hashtable();
56 * values for keys in this hash can be used to reference the org.vamsas.client.object instance for the VorbaId string.
57 * @return the hash of all VorbaIds
59 protected Hashtable getVorbaIdHash() {
64 * @see org.vamsas.client.VorbaIdFactory#makeVorbaId()
66 public VorbaId makeVorbaId(object vobject) {
68 throw new Error("makeVorbaId called on improperly initialised IdFactory object!");
77 newidstring=idstring+Integer.toString(sequence);
78 } while (extantids.containsKey(newidstring));
79 extantids.put(newidstring, vobject); // hash the object by its new Id
80 VorbaId id = newId(newidstring);
85 * @see org.vamsas.client.VorbaIdFactory#setSession(org.vamsas.client.SessionHandle)
87 protected void setSession(SessionHandle sessionhandle) {
88 if (sessionhandle!=null)
89 session=sessionhandle;
91 log.warn("setSession(null) called.");
95 * @see org.vamsas.client.VorbaIdFactory#getSessionHandle()
97 public SessionHandle getSessionHandle() {
102 * @see org.vamsas.client.VorbaIdFactory#setClient(org.vamsas.client.ClientHandle)
104 protected void setClient(ClientHandle appHandle) {
108 log.warn("setClient(null) called.");
112 * @see org.vamsas.client.VorbaIdFactory#getClientHandle()
114 public ClientHandle getClientHandle() {
119 * @see org.vamsas.client.VorbaIdFactory#setUser(org.vamsas.client.UserHandle)
121 protected void setUser(UserHandle userHandle) {
122 if (userHandle!=null)
125 log.warn("setUser(null) called.");
129 * @see org.vamsas.client.VorbaIdFactory#getUserHandle()
131 public UserHandle getUserHandle() {
135 * Convenience method used for default behaviour in testing
136 * and any anonymous internal vamsasDocument unmarshalling
140 protected static IdFactory getDummyFactory(String clientname) {
141 if (clientname==null)
142 clientname="org.vamsas.client.simpleclient.IdFactory";
143 return new IdFactory(new SessionHandle("dummy.session"),
144 new ClientHandle(clientname,VersionEntries.latestVersion()),
145 new UserHandle(clientname, "Arnold User's Inc."));