4ba6c0bdc935a86b3388e96166943f83454b8878
[vamsas.git] / src / uk / ac / vamsas / client / VorbaId.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 /**
10  * The unique reference id for a Vamsas document Vobject,
11  * used by applications to refer to the vamsas Vobject
12  * within their own data space in the vamsas document.
13  * TODO: decide if VorbaId should contain a reference 
14  * to either the IVorbaIdFactory that made it or the 
15  * IClient that defines the session (it might be 
16  * convenient).
17  * @author jimp
18  */
19 public class VorbaId {
20   protected String id;
21   protected VorbaId() {
22     super();
23   }
24   private VorbaId(String Id) {
25     super();
26     id = Id;
27   }
28   /**
29    * 
30    * @param vorbaObject the source of vorba Ids
31    * @param vobject the Vobject to be registered with a new vorba id
32    * @return
33    */
34   protected static VorbaId newId(IVorbaIdFactory vorbaObject, Vobject vobject) {
35     // Make unique id from appSpace info in vorbaObject
36     synchronized (vorbaObject) {
37       vobject.vorbaId=vorbaObject.makeVorbaId(vobject);
38       return vobject.vorbaId;
39     }
40   }
41   /**
42    * protected VorbaId constructor used when turning XML ID strings into vorba IDs
43    * @param id
44    * @return VorbaId object or null if string was null.
45    */
46   protected static VorbaId newId(String id) {
47     return (id==null) ? null : new VorbaId(id);
48   }
49   /**
50    * @return Returns the id.
51    */
52   public String getId() {
53     return id;
54   }
55   /* (non-Javadoc)
56    * @see java.lang.Object#equals(java.lang.Object)
57    */
58   public boolean equals(Object obj) {
59     if (obj instanceof String)
60       return id.equals(obj);
61     else if (obj instanceof VorbaId)
62       return id.equals(((VorbaId)obj).id);
63     return false;
64   }
65   /* (non-Javadoc)
66    * @see java.lang.Object#hashCode()
67    */
68   public int hashCode() {
69     return id.hashCode();
70   }
71   /* (non-Javadoc)
72    * @see java.lang.Object#toString()
73    */
74   public String toString() {
75     return id;
76   }
77   
78 }