vorbaId generator constructs valid ID strings (NCNames)
[vamsas.git] / src / uk / ac / vamsas / client / ClientHandle.java
1 /*
2  */
3 package uk.ac.vamsas.client;
4
5 import java.io.Serializable;
6
7 /**
8  * Uniquely describes a vamsas client application.
9  * @author jimp 
10  */
11 public class ClientHandle implements Serializable {
12   static final long serialVersionUID = 0;
13   
14   /**
15    * @param clientName
16    * @param version
17    */
18   public ClientHandle(String _clientName, String _version) {
19     super();
20     this.clientName = _clientName;
21     this.version = _version;
22     //this.setClientUrn("vamsas://"+clientName+":"+version+"/"); // TODO: decide on application handle ornthing (used to prefix new ids made by a particular application)
23     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
24   }
25   /**
26    * (non-unique) human readable vamsas client name
27    */
28   String clientName;
29
30   /**
31    * the unambiguous client identifier
32    * This may be rewritten by the Vorba object if
33    * other clients with the same name, version 
34    * and user are involved in a session.
35    * 
36    */
37   String clientUrn;
38
39   /**
40    * version modifier to tag application space
41    */
42   String version;
43
44   /**
45    * Generates the client Urn from the clientName and version
46    *  
47    * @param clientName (non-unique) human readable vamsas client name
48    * @param version version modifier
49    * @return a String corresponding to the clientUrn
50    */
51   private String  generateClientUrn(String _clientName, String  _version)
52     {
53       return ("vamsas://"+_clientName+":"+_version+"/").intern();
54     }
55   
56   /**
57    * @return Returns the clientUrn.
58    */
59   public String getClientUrn() {
60     return this.clientUrn;
61   }
62
63   /**
64    * May become protected - should only be set by a Vorba object.
65    * @param clientUrn
66    *          The clientUrn to set.
67    */
68   public void setClientUrn(String _clientUrn) {
69     this.clientUrn = _clientUrn;
70   }
71
72   /**
73    * @return Returns the version.
74    */
75   public String getVersion() {
76     return this.version;
77   }
78
79   /**
80    * @param version
81    *          The version to set.
82    */
83   public void setVersion(String _version) {
84     this.version = _version;
85     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
86   }
87
88
89   /**
90    * @return Returns the clientName.
91    */
92   public String getClientName() {
93     return this.clientName;
94   }
95
96   /**
97    * @param clientName
98    *          The clientName to set.
99    */
100   public void setClientName(String _clientName) {
101     this.clientName = _clientName;
102     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
103   }
104
105   public boolean equals(Object that) {
106     if (that instanceof ClientHandle)
107       return this.equals((ClientHandle) that); 
108     return false;
109   }
110   public boolean equals(ClientHandle that) {
111     return ( (this.clientName == null || this.clientName.equals(that.clientName)) 
112         && (this.version == null || this.version.equals(that.version)) 
113         && (this.clientUrn == null || this.clientUrn.equals(that.clientUrn)));
114   }
115
116   public String getClientNCname() {
117     
118     String ncname = clientName.replace(':', '_');
119     ncname = ncname.replace('@', '.');
120     return ncname;
121   }
122 }