(JAL-1016) noted position where race condition occurs
[jalview.git] / src / org / biojava / dasobert / dasregistry / Das1Source.java
1 /*
2  *                    BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on 15.04.2004
21  * @author Andreas Prlic
22  *
23  */
24 package org.biojava.dasobert.dasregistry;
25
26 import java.util.*;
27
28 // import org.biojava.dasobert.das2.io.DasSourceWriter;
29 // import org.biojava.dasobert.das2.io.DasSourceWriterImpl;
30 // import org.biojava.utils.xml.PrettyXMLWriter;
31
32 /**
33  * a simple Bean class to be returned via SOAP
34  * 
35  * @author Andreas Prlic
36  */
37
38 public class Das1Source implements DasSource
39 {
40   String url;
41
42   protected String nickname;
43
44   String adminemail;
45
46   String description;
47
48   DasCoordinateSystem[] coordinateSystem;
49
50   String[] capabilities;
51
52   String[] labels;
53
54   String helperurl;
55
56   Date registerDate;
57
58   Date leaseDate;
59
60   String id;
61
62   boolean local;
63
64   Map properties;
65
66   boolean alertAdmin;
67
68   public static String EMPTY_ID = "UNK:-1";
69
70   public Das1Source()
71   {
72     id = EMPTY_ID;
73     url = "";
74     adminemail = "";
75     description = "";
76     // String empty = "" ;
77     nickname = "";
78     coordinateSystem = new DasCoordinateSystem[0];
79     // coordinateSystem[0] = new DasCoordinateSystem();
80     capabilities = new String[0];
81     labels = new String[0];
82     // capabilities[0] = empty ;
83     registerDate = new Date();
84     leaseDate = new Date();
85     helperurl = "";
86     local = true;
87   }
88
89   public boolean equals(DasSource other)
90   {
91     System.out.println("Das1Source equals, comparing with other DasSource");
92     if (!(other instanceof Das1Source))
93     {
94       return false;
95     }
96
97     Das1Source ods = (Das1Source) other;
98
99     if (ods.getUrl().equals(url))
100     {
101       return true;
102     }
103     if (ods.getNickname().equals(nickname))
104     {
105       return true;
106     }
107     return false;
108   }
109
110   public int hashCode()
111   {
112     int h = 7;
113
114     h = 31 * h + (null == nickname ? 0 : nickname.hashCode());
115     h = 31 * h + (null == url ? 0 : url.hashCode());
116
117     return h;
118   }
119
120   /**
121    * the DAS2 string representation of this DAS source
122    * 
123    * public String toString() {
124    * 
125    * StringWriter writer = new StringWriter();
126    * 
127    * PrintWriter pw = new PrintWriter(writer); PrettyXMLWriter xw = new
128    * PrettyXMLWriter(pw);
129    * 
130    * DasSourceWriter dswriter = new DasSourceWriterImpl(); try {
131    * dswriter.writeDasSource(xw,this); } catch (IOException e){
132    * e.printStackTrace(); }
133    * 
134    * return writer.toString();
135    *  }
136    */
137   public void setLocal(boolean flag)
138   {
139     local = flag;
140   }
141
142   public boolean isLocal()
143   {
144     return local;
145   }
146
147   public void setId(String i)
148   {
149     id = i;
150   }
151
152   /**
153    * get a the Id of the DasSource. The Id is a unique db identifier. The public
154    * DAS-Registry has Auto_Ids that look like DASSOURCE:12345; public look like
155    * XYZ:12345, where the XYZ prefix can be configured in the config file.
156    */
157   public String getId()
158   {
159     return id;
160   }
161
162   public void setNickname(String name)
163   {
164     nickname = name;
165   }
166
167   public String getNickname()
168   {
169     return nickname;
170   }
171
172   public void setUrl(String u)
173   {
174     char lastChar = u.charAt(u.length() - 1);
175     if (lastChar != '/')
176     {
177       u += "/";
178     }
179
180     url = u;
181   }
182
183   public void setAdminemail(String u)
184   {
185     adminemail = u;
186   }
187
188   public void setDescription(String u)
189   {
190     description = u;
191   }
192
193   public void setCoordinateSystem(DasCoordinateSystem[] u)
194   {
195     coordinateSystem = u;
196   }
197
198   public void setCapabilities(String[] u)
199   {
200     capabilities = u;
201   }
202
203   public String getUrl()
204   {
205     return url;
206   }
207
208   public String getAdminemail()
209   {
210     return adminemail;
211   }
212
213   public String getDescription()
214   {
215     return description;
216   }
217
218   public String[] getCapabilities()
219   {
220     return capabilities;
221   }
222
223   /**
224    * test if a this source has a particular capability
225    * 
226    * @param testCapability
227    * @return <code>true</code> if the server has this capability.
228    */
229   public boolean hasCapability(String testCapability)
230   {
231     for (int i = 0; i < capabilities.length; i++)
232     {
233       String cap = capabilities[i];
234       if (cap.equals(testCapability))
235         return true;
236     }
237     return false;
238   }
239
240   public DasCoordinateSystem[] getCoordinateSystem()
241   {
242     return coordinateSystem;
243   }
244
245   public void setRegisterDate(Date d)
246   {
247     registerDate = d;
248   }
249
250   public Date getRegisterDate()
251   {
252     return registerDate;
253   }
254
255   public void setLeaseDate(Date d)
256   {
257     leaseDate = d;
258   }
259
260   public Date getLeaseDate()
261   {
262     return leaseDate;
263   }
264
265   public void setLabels(String[] ls)
266   {
267     labels = ls;
268   }
269
270   public String[] getLabels()
271   {
272     return labels;
273   }
274
275   public void setHelperurl(String url)
276   {
277     helperurl = url;
278   }
279
280   public String getHelperurl()
281   {
282     return helperurl;
283   }
284
285   public void setAlertAdmin(boolean flag)
286   {
287     alertAdmin = flag;
288   }
289
290   public boolean getAlertAdmin()
291   {
292     return alertAdmin;
293   }
294
295   public Map getProperties()
296   {
297     return properties;
298   }
299
300   public void setProperties(Map properties)
301   {
302     this.properties = properties;
303   }
304
305 }