applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / ClientHandle.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.io.Serializable;
25
26 /**
27  * Uniquely describes a vamsas client application.
28  * 
29  * @author jimp
30  */
31 public class ClientHandle implements Serializable {
32   static final long serialVersionUID = 0;
33
34   /**
35    * @param clientName
36    * @param version
37    */
38   public ClientHandle(String _clientName, String _version) {
39     super();
40     this.clientName = _clientName;
41     this.version = _version;
42     // this.setClientUrn("vamsas://"+clientName+":"+version+"/"); // TODO:
43     // decide on application handle ornthing (used to prefix new ids made by a
44     // particular application)
45     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
46   }
47
48   /**
49    * (non-unique) human readable vamsas client name
50    */
51   String clientName;
52
53   /**
54    * the unambiguous client identifier This may be rewritten by the Vorba object
55    * if other clients with the same name, version and user are involved in a
56    * session.
57    * 
58    */
59   String clientUrn;
60
61   /**
62    * version modifier to tag application space
63    */
64   String version;
65
66   /**
67    * Generates the client Urn from the clientName and version
68    * 
69    * @param clientName
70    *          (non-unique) human readable vamsas client name
71    * @param version
72    *          version modifier
73    * @return a String corresponding to the clientUrn
74    */
75   private String generateClientUrn(String _clientName, String _version) {
76     return ("vamsas://" + _clientName + ":" + _version + "/").intern();
77   }
78
79   /**
80    * @return Returns the clientUrn.
81    */
82   public String getClientUrn() {
83     return this.clientUrn;
84   }
85
86   /**
87    * May become protected - should only be set by a Vorba object.
88    * 
89    * @param clientUrn
90    *          The clientUrn to set.
91    */
92   public void setClientUrn(String _clientUrn) {
93     this.clientUrn = _clientUrn;
94   }
95
96   /**
97    * @return Returns the version.
98    */
99   public String getVersion() {
100     return this.version;
101   }
102
103   /**
104    * @param version
105    *          The version to set.
106    */
107   public void setVersion(String _version) {
108     this.version = _version;
109     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
110   }
111
112   /**
113    * @return Returns the clientName.
114    */
115   public String getClientName() {
116     return this.clientName;
117   }
118
119   /**
120    * @param clientName
121    *          The clientName to set.
122    */
123   public void setClientName(String _clientName) {
124     this.clientName = _clientName;
125     this.setClientUrn(this.generateClientUrn(this.clientName, this.version));
126   }
127
128   public boolean equals(Object that) {
129     if (that instanceof ClientHandle)
130       return this.equals((ClientHandle) that);
131     return false;
132   }
133
134   public boolean equals(ClientHandle that) {
135     return ((this.clientName == null || this.clientName.equals(that.clientName))
136         && (this.version == null || this.version.equals(that.version)) && (this.clientUrn == null || this.clientUrn
137         .equals(that.clientUrn)));
138   }
139
140   public String getClientNCname() {
141
142     String ncname = clientName.replace(':', '_');
143     ncname = ncname.replace('@', '.');
144     return ncname;
145   }
146 }