e7541b417e8c8a2d21d5e0611cb86834484d30e2
[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  * @author Andreas Prlic
35  */
36
37 public class Das1Source
38     implements DasSource
39 {
40   String url;
41   protected String nickname;
42   String adminemail;
43   String description;
44   DasCoordinateSystem[] coordinateSystem;
45   String[] capabilities;
46   String[] labels;
47   String helperurl;
48   Date registerDate;
49   Date leaseDate;
50   String id;
51   boolean local;
52   Map properties;
53   boolean alertAdmin;
54
55   public static String EMPTY_ID = "UNK:-1";
56
57   public Das1Source()
58   {
59     id = EMPTY_ID;
60     url = "";
61     adminemail = "";
62     description = "";
63     //String empty     = "" ;
64     nickname = "";
65     coordinateSystem = new DasCoordinateSystem[0];
66     //coordinateSystem[0] = new DasCoordinateSystem();
67     capabilities = new String[0];
68     labels = new String[0];
69     //capabilities[0]  = empty ;
70     registerDate = new Date();
71     leaseDate = new Date();
72     helperurl = "";
73     local = true;
74   }
75
76   public boolean equals(DasSource other)
77   {
78     System.out.println("Das1Source equals, comparing with other DasSource");
79     if (! (other instanceof Das1Source))
80     {
81       return false;
82     }
83
84     Das1Source ods = (Das1Source) other;
85
86     if (ods.getUrl().equals(url))
87     {
88       return true;
89     }
90     if (ods.getNickname().equals(nickname))
91     {
92       return true;
93     }
94     return false;
95   }
96
97   public int hashCode()
98   {
99     int h = 7;
100
101     h = 31 * h + (null == nickname ? 0 : nickname.hashCode());
102     h = 31 * h + (null == url ? 0 : url.hashCode());
103
104     return h;
105   }
106
107   /** the DAS2 string representation of this DAS source
108    *
109        public String toString() {
110
111       StringWriter writer = new StringWriter();
112
113       PrintWriter pw = new PrintWriter(writer);
114       PrettyXMLWriter xw = new PrettyXMLWriter(pw);
115
116       DasSourceWriter dswriter = new DasSourceWriterImpl();
117       try {
118           dswriter.writeDasSource(xw,this);
119       } catch (IOException e){
120           e.printStackTrace();
121       }
122
123       return writer.toString();
124
125        }
126    */
127   public void setLocal(boolean flag)
128   {
129     local = flag;
130   }
131
132   public boolean isLocal()
133   {
134     return local;
135   }
136
137   public void setId(String i)
138   {
139     id = i;
140   }
141
142   /** get a the Id of the DasSource. The Id is a unique db
143    * identifier. The public DAS-Registry has Auto_Ids that look like
144    * DASSOURCE:12345; public look like XYZ:12345, where the XYZ
145    * prefix can be configured in the config file.
146    */
147   public String getId()
148   {
149     return id;
150   }
151
152   public void setNickname(String name)
153   {
154     nickname = name;
155   }
156
157   public String getNickname()
158   {
159     return nickname;
160   }
161
162   public void setUrl(String u)
163   {
164     char lastChar = u.charAt(u.length() - 1);
165     if (lastChar != '/')
166     {
167       u += "/";
168     }
169
170     url = u;
171   }
172
173   public void setAdminemail(String u)
174   {
175     adminemail = u;
176   }
177
178   public void setDescription(String u)
179   {
180     description = u;
181   }
182
183   public void setCoordinateSystem(DasCoordinateSystem[] u)
184   {
185     coordinateSystem = u;
186   }
187
188   public void setCapabilities(String[] u)
189   {
190     capabilities = u;
191   }
192
193   public String getUrl()
194   {
195     return url;
196   }
197
198   public String getAdminemail()
199   {
200     return adminemail;
201   }
202
203   public String getDescription()
204   {
205     return description;
206   }
207
208   public String[] getCapabilities()
209   {
210     return capabilities;
211   }
212     /** test if a this source has a particular capability
213      * 
214      * @param testCapability
215      * @return <code>true</code> if the server has this capability.
216      */
217     public boolean hasCapability(String testCapability){
218         for (int i=0 ; i< capabilities.length;i++){
219             String cap = capabilities[i];
220             if ( cap.equals(testCapability))
221                 return true;
222         }
223         return false;
224     }
225
226   public DasCoordinateSystem[] getCoordinateSystem()
227   {
228     return coordinateSystem;
229   }
230
231   public void setRegisterDate(Date d)
232   {
233     registerDate = d;
234   }
235
236   public Date getRegisterDate()
237   {
238     return registerDate;
239   }
240
241   public void setLeaseDate(Date d)
242   {
243     leaseDate = d;
244   }
245
246   public Date getLeaseDate()
247   {
248     return leaseDate;
249   }
250
251   public void setLabels(String[] ls)
252   {
253     labels = ls;
254   }
255
256   public String[] getLabels()
257   {
258     return labels;
259   }
260
261   public void setHelperurl(String url)
262   {
263     helperurl = url;
264   }
265
266   public String getHelperurl()
267   {
268     return helperurl;
269   }
270
271   public void setAlertAdmin(boolean flag)
272   {
273     alertAdmin = flag;
274   }
275
276   public boolean getAlertAdmin()
277   {
278     return alertAdmin;
279     }
280         public Map getProperties() {
281                 return properties;
282         }
283         public void setProperties(Map properties) {
284                 this.properties = properties;
285         }
286
287 }