applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Link.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.objects.core;\r
23 \r
24 //---------------------------------/\r
25 //- Imported classes and packages -/\r
26 //---------------------------------/\r
27 \r
28 import org.exolab.castor.xml.Marshaller;\r
29 import org.exolab.castor.xml.Unmarshaller;\r
30 \r
31 /**\r
32  * Class Link.\r
33  * \r
34  * @version $Revision$ $Date$\r
35  */\r
36 public class Link extends uk.ac.vamsas.client.Vobject implements\r
37     java.io.Serializable {\r
38 \r
39   // --------------------------/\r
40   // - Class/Member Variables -/\r
41   // --------------------------/\r
42 \r
43   /**\r
44    * internal content storage\r
45    */\r
46   private java.lang.String _content = "";\r
47 \r
48   /**\r
49    * The URI\r
50    */\r
51   private java.lang.String _href;\r
52 \r
53   // ----------------/\r
54   // - Constructors -/\r
55   // ----------------/\r
56 \r
57   public Link() {\r
58     super();\r
59     setContent("");\r
60   }\r
61 \r
62   // -----------/\r
63   // - Methods -/\r
64   // -----------/\r
65 \r
66   /**\r
67    * Overrides the java.lang.Object.equals method.\r
68    * \r
69    * @param obj\r
70    * @return true if the objects are equal.\r
71    */\r
72   public boolean equals(final java.lang.Object obj) {\r
73     if (this == obj)\r
74       return true;\r
75 \r
76     if (super.equals(obj) == false)\r
77       return false;\r
78 \r
79     if (obj instanceof Link) {\r
80 \r
81       Link temp = (Link) obj;\r
82       boolean thcycle;\r
83       boolean tmcycle;\r
84       if (this._content != null) {\r
85         if (temp._content == null)\r
86           return false;\r
87         if (this._content != temp._content) {\r
88           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._content);\r
89           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._content);\r
90           if (thcycle != tmcycle) {\r
91             if (!thcycle) {\r
92               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
93             }\r
94             ;\r
95             if (!tmcycle) {\r
96               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
97             }\r
98             ;\r
99             return false;\r
100           }\r
101           if (!thcycle) {\r
102             if (!this._content.equals(temp._content)) {\r
103               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
104               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
105               return false;\r
106             }\r
107             org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
108             org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
109           }\r
110         }\r
111       } else if (temp._content != null)\r
112         return false;\r
113       if (this._href != null) {\r
114         if (temp._href == null)\r
115           return false;\r
116         if (this._href != temp._href) {\r
117           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._href);\r
118           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._href);\r
119           if (thcycle != tmcycle) {\r
120             if (!thcycle) {\r
121               org.castor.util.CycleBreaker.releaseCycleHandle(this._href);\r
122             }\r
123             ;\r
124             if (!tmcycle) {\r
125               org.castor.util.CycleBreaker.releaseCycleHandle(temp._href);\r
126             }\r
127             ;\r
128             return false;\r
129           }\r
130           if (!thcycle) {\r
131             if (!this._href.equals(temp._href)) {\r
132               org.castor.util.CycleBreaker.releaseCycleHandle(this._href);\r
133               org.castor.util.CycleBreaker.releaseCycleHandle(temp._href);\r
134               return false;\r
135             }\r
136             org.castor.util.CycleBreaker.releaseCycleHandle(this._href);\r
137             org.castor.util.CycleBreaker.releaseCycleHandle(temp._href);\r
138           }\r
139         }\r
140       } else if (temp._href != null)\r
141         return false;\r
142       return true;\r
143     }\r
144     return false;\r
145   }\r
146 \r
147   /**\r
148    * Returns the value of field 'content'. The field 'content' has the following\r
149    * description: internal content storage\r
150    * \r
151    * @return the value of field 'Content'.\r
152    */\r
153   public java.lang.String getContent() {\r
154     return this._content;\r
155   }\r
156 \r
157   /**\r
158    * Returns the value of field 'href'. The field 'href' has the following\r
159    * description: The URI\r
160    * \r
161    * @return the value of field 'Href'.\r
162    */\r
163   public java.lang.String getHref() {\r
164     return this._href;\r
165   }\r
166 \r
167   /**\r
168    * Overrides the java.lang.Object.hashCode method.\r
169    * <p>\r
170    * The following steps came from <b>Effective Java Programming Language\r
171    * Guide</b> by Joshua Bloch, Chapter 3\r
172    * \r
173    * @return a hash code value for the object.\r
174    */\r
175   public int hashCode() {\r
176     int result = super.hashCode();\r
177 \r
178     long tmp;\r
179     if (_content != null\r
180         && !org.castor.util.CycleBreaker.startingToCycle(_content)) {\r
181       result = 37 * result + _content.hashCode();\r
182       org.castor.util.CycleBreaker.releaseCycleHandle(_content);\r
183     }\r
184     if (_href != null && !org.castor.util.CycleBreaker.startingToCycle(_href)) {\r
185       result = 37 * result + _href.hashCode();\r
186       org.castor.util.CycleBreaker.releaseCycleHandle(_href);\r
187     }\r
188 \r
189     return result;\r
190   }\r
191 \r
192   /**\r
193    * Method isValid.\r
194    * \r
195    * @return true if this object is valid according to the schema\r
196    */\r
197   public boolean isValid() {\r
198     try {\r
199       validate();\r
200     } catch (org.exolab.castor.xml.ValidationException vex) {\r
201       return false;\r
202     }\r
203     return true;\r
204   }\r
205 \r
206   /**\r
207    * \r
208    * \r
209    * @param out\r
210    * @throws org.exolab.castor.xml.MarshalException\r
211    *           if object is null or if any SAXException is thrown during\r
212    *           marshaling\r
213    * @throws org.exolab.castor.xml.ValidationException\r
214    *           if this object is an invalid instance according to the schema\r
215    */\r
216   public void marshal(final java.io.Writer out)\r
217       throws org.exolab.castor.xml.MarshalException,\r
218       org.exolab.castor.xml.ValidationException {\r
219     Marshaller.marshal(this, out);\r
220   }\r
221 \r
222   /**\r
223    * \r
224    * \r
225    * @param handler\r
226    * @throws java.io.IOException\r
227    *           if an IOException occurs during marshaling\r
228    * @throws org.exolab.castor.xml.ValidationException\r
229    *           if this object is an invalid instance according to the schema\r
230    * @throws org.exolab.castor.xml.MarshalException\r
231    *           if object is null or if any SAXException is thrown during\r
232    *           marshaling\r
233    */\r
234   public void marshal(final org.xml.sax.ContentHandler handler)\r
235       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
236       org.exolab.castor.xml.ValidationException {\r
237     Marshaller.marshal(this, handler);\r
238   }\r
239 \r
240   /**\r
241    * Sets the value of field 'content'. The field 'content' has the following\r
242    * description: internal content storage\r
243    * \r
244    * @param content\r
245    *          the value of field 'content'.\r
246    */\r
247   public void setContent(final java.lang.String content) {\r
248     this._content = content;\r
249   }\r
250 \r
251   /**\r
252    * Sets the value of field 'href'. The field 'href' has the following\r
253    * description: The URI\r
254    * \r
255    * @param href\r
256    *          the value of field 'href'.\r
257    */\r
258   public void setHref(final java.lang.String href) {\r
259     this._href = href;\r
260   }\r
261 \r
262   /**\r
263    * Method unmarshal.\r
264    * \r
265    * @param reader\r
266    * @throws org.exolab.castor.xml.MarshalException\r
267    *           if object is null or if any SAXException is thrown during\r
268    *           marshaling\r
269    * @throws org.exolab.castor.xml.ValidationException\r
270    *           if this object is an invalid instance according to the schema\r
271    * @return the unmarshaled uk.ac.vamsas.objects.core.Link\r
272    */\r
273   public static uk.ac.vamsas.objects.core.Link unmarshal(\r
274       final java.io.Reader reader)\r
275       throws org.exolab.castor.xml.MarshalException,\r
276       org.exolab.castor.xml.ValidationException {\r
277     return (uk.ac.vamsas.objects.core.Link) Unmarshaller.unmarshal(\r
278         uk.ac.vamsas.objects.core.Link.class, reader);\r
279   }\r
280 \r
281   /**\r
282    * \r
283    * \r
284    * @throws org.exolab.castor.xml.ValidationException\r
285    *           if this object is an invalid instance according to the schema\r
286    */\r
287   public void validate() throws org.exolab.castor.xml.ValidationException {\r
288     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
289     validator.validate(this);\r
290   }\r
291 \r
292 }\r