c5a5079904b5a04a4538fa0e9b7ed15123c67690
[vamsas.git] / src / uk / ac / vamsas / client / VorbaIdFactory.java
1 /*
2  * Created on 12-Sep-2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package uk.ac.vamsas.client;
8
9 import java.util.Hashtable;
10 import java.util.Vector;
11
12 /**
13  * A VorbaIdFactory is constructed by an IClient instance.
14  * It guarantees that any new VorbaId objects are unique 
15  * within the VAMSAS session.
16  * 
17  * @author jimp
18  */
19 public abstract class VorbaIdFactory implements IVorbaIdFactory {
20   /**
21    * hash of VorbaIds to Vobject.
22    */
23   protected Hashtable extantids=null;
24   /**
25    * hash of VorbaIds to persisted hash values
26    */
27   protected Hashtable extanthashv=null;
28   /**
29    * list of Vobjects added since last Document read.
30    */
31   protected Vector newobj=null;
32   
33   /**
34    * construct a new id appropriate for this client in the vamsas session.
35    * 
36    * @return valid VorbaId for session, or null if VorbaIdFactory not configured
37    *         correctly.
38    */
39   public abstract VorbaId makeVorbaId(Vobject vobject);
40   
41   /**
42    * internal method to access the protected VorbaId object constructor
43    * This shennanigan is to prevent casual generation of VorbaIds 
44    * (which may destroy the integrity of a Vamsas Document!)
45    * @param id
46    * @return new VorbaId object
47    */
48   protected VorbaId newId(String id) {
49     return VorbaId.newId(id);
50   }
51   /**
52    * Called by VorbaXmlBinder so the record of newly unmarshalled Vobject Ids
53    * is accessible to the Document's VorbaIdFactory instance. 
54    * @param idtable
55    */
56   protected void setNewIdHash(Hashtable idtable) {
57     extantids = idtable;
58   }
59   
60   /* (non-Javadoc)
61    * @see uk.ac.vamsas.client.IVorbaIdFactory#updateHashValue(uk.ac.vamsas.client.Vobject)
62    */
63   public void updateHashValue(Vobject vobject) {
64     if (vobject.isRegisterable())
65       extanthashv.put(vobject.getVorbaId(), new Vobjhash(vobject));
66   }
67
68   /**
69    * TODO: decide if these are needed.
70    * 
71    * @param sessionHandle
72    */
73   protected abstract void setSession(SessionHandle sessionhandle);
74
75   public abstract SessionHandle getSessionHandle();
76
77   protected abstract void setClient(ClientHandle appHandle);
78
79   public abstract ClientHandle getClientHandle();
80
81   protected abstract void setUser(UserHandle userHandle);
82
83   public abstract UserHandle getUserHandle();
84 }