applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / VorbaIdFactory.java
1 /*
2  * This file is part of the Vamsas Client version 0.1. 
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, 
4  *  Andrew Waterhouse and Dominik Lindner.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
9  * The Vamsas Client is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *  
14  * The Vamsas Client is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 package uk.ac.vamsas.client;
23
24 import java.util.Hashtable;
25 import java.util.Vector;
26
27 /**
28  * A VorbaIdFactory is constructed by an IClient instance. It guarantees that
29  * any new VorbaId objects are unique within the VAMSAS session.
30  * 
31  * @author jimp
32  */
33 public abstract class VorbaIdFactory implements IVorbaIdFactory {
34   /**
35    * hash of VorbaIds to Vobject.
36    */
37   protected Hashtable extantids = null;
38
39   /**
40    * hash of VorbaIds to persisted hash values
41    */
42   protected Hashtable extanthashv = null;
43
44   /**
45    * list of Vobjects added since last Document read.
46    */
47   protected Vector newobj = null;
48
49   /**
50    * construct a new id appropriate for this client in the vamsas session.
51    * 
52    * @return valid VorbaId for session, or null if VorbaIdFactory not configured
53    *         correctly.
54    */
55   public abstract VorbaId makeVorbaId(Vobject vobject);
56
57   /**
58    * internal method to access the protected VorbaId object constructor This
59    * shennanigan is to prevent casual generation of VorbaIds (which may destroy
60    * the integrity of a Vamsas Document!)
61    * 
62    * @param id
63    * @return new VorbaId object
64    */
65   protected VorbaId newId(String id) {
66     return VorbaId.newId(id);
67   }
68
69   /**
70    * Called by VorbaXmlBinder so the record of newly unmarshalled Vobject Ids is
71    * accessible to the Document's VorbaIdFactory instance.
72    * 
73    * @param idtable
74    */
75   protected void setNewIdHash(Hashtable idtable) {
76     extantids = idtable;
77   }
78
79   /*
80    * (non-Javadoc)
81    * 
82    * @see
83    * uk.ac.vamsas.client.IVorbaIdFactory#updateHashValue(uk.ac.vamsas.client
84    * .Vobject)
85    */
86   public void updateHashValue(Vobject vobject) {
87     if (vobject.isRegisterable())
88       extanthashv.put(vobject.getVorbaId(), new Vobjhash(vobject));
89   }
90
91   /**
92    * TODO: decide if these are needed.
93    * 
94    * @param sessionHandle
95    */
96   protected abstract void setSession(SessionHandle sessionhandle);
97
98   public abstract SessionHandle getSessionHandle();
99
100   protected abstract void setClient(ClientHandle appHandle);
101
102   public abstract ClientHandle getClientHandle();
103
104   protected abstract void setUser(UserHandle userHandle);
105
106   public abstract UserHandle getUserHandle();
107 }