applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Property.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 Property.\r
33  * \r
34  * @version $Revision$ $Date$\r
35  */\r
36 public class Property 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    * Field _name.\r
50    */\r
51   private java.lang.String _name;\r
52 \r
53   /**\r
54    * The type specifies how the property will be parsed. Empty property strings\r
55    * are allowed, and can be used to prototype the input to a document. TODO:\r
56    * specify allowed types\r
57    */\r
58   private java.lang.String _type;\r
59 \r
60   // ----------------/\r
61   // - Constructors -/\r
62   // ----------------/\r
63 \r
64   public Property() {\r
65     super();\r
66     setContent("");\r
67   }\r
68 \r
69   // -----------/\r
70   // - Methods -/\r
71   // -----------/\r
72 \r
73   /**\r
74    * Overrides the java.lang.Object.equals method.\r
75    * \r
76    * @param obj\r
77    * @return true if the objects are equal.\r
78    */\r
79   public boolean equals(final java.lang.Object obj) {\r
80     if (this == obj)\r
81       return true;\r
82 \r
83     if (super.equals(obj) == false)\r
84       return false;\r
85 \r
86     if (obj instanceof Property) {\r
87 \r
88       Property temp = (Property) obj;\r
89       boolean thcycle;\r
90       boolean tmcycle;\r
91       if (this._content != null) {\r
92         if (temp._content == null)\r
93           return false;\r
94         if (this._content != temp._content) {\r
95           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._content);\r
96           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._content);\r
97           if (thcycle != tmcycle) {\r
98             if (!thcycle) {\r
99               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
100             }\r
101             ;\r
102             if (!tmcycle) {\r
103               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
104             }\r
105             ;\r
106             return false;\r
107           }\r
108           if (!thcycle) {\r
109             if (!this._content.equals(temp._content)) {\r
110               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
111               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
112               return false;\r
113             }\r
114             org.castor.util.CycleBreaker.releaseCycleHandle(this._content);\r
115             org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);\r
116           }\r
117         }\r
118       } else if (temp._content != null)\r
119         return false;\r
120       if (this._name != null) {\r
121         if (temp._name == null)\r
122           return false;\r
123         if (this._name != temp._name) {\r
124           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._name);\r
125           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._name);\r
126           if (thcycle != tmcycle) {\r
127             if (!thcycle) {\r
128               org.castor.util.CycleBreaker.releaseCycleHandle(this._name);\r
129             }\r
130             ;\r
131             if (!tmcycle) {\r
132               org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);\r
133             }\r
134             ;\r
135             return false;\r
136           }\r
137           if (!thcycle) {\r
138             if (!this._name.equals(temp._name)) {\r
139               org.castor.util.CycleBreaker.releaseCycleHandle(this._name);\r
140               org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);\r
141               return false;\r
142             }\r
143             org.castor.util.CycleBreaker.releaseCycleHandle(this._name);\r
144             org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);\r
145           }\r
146         }\r
147       } else if (temp._name != null)\r
148         return false;\r
149       if (this._type != null) {\r
150         if (temp._type == null)\r
151           return false;\r
152         if (this._type != temp._type) {\r
153           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._type);\r
154           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._type);\r
155           if (thcycle != tmcycle) {\r
156             if (!thcycle) {\r
157               org.castor.util.CycleBreaker.releaseCycleHandle(this._type);\r
158             }\r
159             ;\r
160             if (!tmcycle) {\r
161               org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);\r
162             }\r
163             ;\r
164             return false;\r
165           }\r
166           if (!thcycle) {\r
167             if (!this._type.equals(temp._type)) {\r
168               org.castor.util.CycleBreaker.releaseCycleHandle(this._type);\r
169               org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);\r
170               return false;\r
171             }\r
172             org.castor.util.CycleBreaker.releaseCycleHandle(this._type);\r
173             org.castor.util.CycleBreaker.releaseCycleHandle(temp._type);\r
174           }\r
175         }\r
176       } else if (temp._type != null)\r
177         return false;\r
178       return true;\r
179     }\r
180     return false;\r
181   }\r
182 \r
183   /**\r
184    * Returns the value of field 'content'. The field 'content' has the following\r
185    * description: internal content storage\r
186    * \r
187    * @return the value of field 'Content'.\r
188    */\r
189   public java.lang.String getContent() {\r
190     return this._content;\r
191   }\r
192 \r
193   /**\r
194    * Returns the value of field 'name'.\r
195    * \r
196    * @return the value of field 'Name'.\r
197    */\r
198   public java.lang.String getName() {\r
199     return this._name;\r
200   }\r
201 \r
202   /**\r
203    * Returns the value of field 'type'. The field 'type' has the following\r
204    * description: The type specifies how the property will be parsed. Empty\r
205    * property strings are allowed, and can be used to prototype the input to a\r
206    * document. TODO: specify allowed types\r
207    * \r
208    * @return the value of field 'Type'.\r
209    */\r
210   public java.lang.String getType() {\r
211     return this._type;\r
212   }\r
213 \r
214   /**\r
215    * Overrides the java.lang.Object.hashCode method.\r
216    * <p>\r
217    * The following steps came from <b>Effective Java Programming Language\r
218    * Guide</b> by Joshua Bloch, Chapter 3\r
219    * \r
220    * @return a hash code value for the object.\r
221    */\r
222   public int hashCode() {\r
223     int result = super.hashCode();\r
224 \r
225     long tmp;\r
226     if (_content != null\r
227         && !org.castor.util.CycleBreaker.startingToCycle(_content)) {\r
228       result = 37 * result + _content.hashCode();\r
229       org.castor.util.CycleBreaker.releaseCycleHandle(_content);\r
230     }\r
231     if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {\r
232       result = 37 * result + _name.hashCode();\r
233       org.castor.util.CycleBreaker.releaseCycleHandle(_name);\r
234     }\r
235     if (_type != null && !org.castor.util.CycleBreaker.startingToCycle(_type)) {\r
236       result = 37 * result + _type.hashCode();\r
237       org.castor.util.CycleBreaker.releaseCycleHandle(_type);\r
238     }\r
239 \r
240     return result;\r
241   }\r
242 \r
243   /**\r
244    * Method isValid.\r
245    * \r
246    * @return true if this object is valid according to the schema\r
247    */\r
248   public boolean isValid() {\r
249     try {\r
250       validate();\r
251     } catch (org.exolab.castor.xml.ValidationException vex) {\r
252       return false;\r
253     }\r
254     return true;\r
255   }\r
256 \r
257   /**\r
258    * \r
259    * \r
260    * @param out\r
261    * @throws org.exolab.castor.xml.MarshalException\r
262    *           if object is null or if any SAXException is thrown during\r
263    *           marshaling\r
264    * @throws org.exolab.castor.xml.ValidationException\r
265    *           if this object is an invalid instance according to the schema\r
266    */\r
267   public void marshal(final java.io.Writer out)\r
268       throws org.exolab.castor.xml.MarshalException,\r
269       org.exolab.castor.xml.ValidationException {\r
270     Marshaller.marshal(this, out);\r
271   }\r
272 \r
273   /**\r
274    * \r
275    * \r
276    * @param handler\r
277    * @throws java.io.IOException\r
278    *           if an IOException occurs during marshaling\r
279    * @throws org.exolab.castor.xml.ValidationException\r
280    *           if this object is an invalid instance according to the schema\r
281    * @throws org.exolab.castor.xml.MarshalException\r
282    *           if object is null or if any SAXException is thrown during\r
283    *           marshaling\r
284    */\r
285   public void marshal(final org.xml.sax.ContentHandler handler)\r
286       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
287       org.exolab.castor.xml.ValidationException {\r
288     Marshaller.marshal(this, handler);\r
289   }\r
290 \r
291   /**\r
292    * Sets the value of field 'content'. The field 'content' has the following\r
293    * description: internal content storage\r
294    * \r
295    * @param content\r
296    *          the value of field 'content'.\r
297    */\r
298   public void setContent(final java.lang.String content) {\r
299     this._content = content;\r
300   }\r
301 \r
302   /**\r
303    * Sets the value of field 'name'.\r
304    * \r
305    * @param name\r
306    *          the value of field 'name'.\r
307    */\r
308   public void setName(final java.lang.String name) {\r
309     this._name = name;\r
310   }\r
311 \r
312   /**\r
313    * Sets the value of field 'type'. The field 'type' has the following\r
314    * description: The type specifies how the property will be parsed. Empty\r
315    * property strings are allowed, and can be used to prototype the input to a\r
316    * document. TODO: specify allowed types\r
317    * \r
318    * @param type\r
319    *          the value of field 'type'.\r
320    */\r
321   public void setType(final java.lang.String type) {\r
322     this._type = type;\r
323   }\r
324 \r
325   /**\r
326    * Method unmarshal.\r
327    * \r
328    * @param reader\r
329    * @throws org.exolab.castor.xml.MarshalException\r
330    *           if object is null or if any SAXException is thrown during\r
331    *           marshaling\r
332    * @throws org.exolab.castor.xml.ValidationException\r
333    *           if this object is an invalid instance according to the schema\r
334    * @return the unmarshaled uk.ac.vamsas.objects.core.Property\r
335    */\r
336   public static uk.ac.vamsas.objects.core.Property unmarshal(\r
337       final java.io.Reader reader)\r
338       throws org.exolab.castor.xml.MarshalException,\r
339       org.exolab.castor.xml.ValidationException {\r
340     return (uk.ac.vamsas.objects.core.Property) Unmarshaller.unmarshal(\r
341         uk.ac.vamsas.objects.core.Property.class, reader);\r
342   }\r
343 \r
344   /**\r
345    * \r
346    * \r
347    * @throws org.exolab.castor.xml.ValidationException\r
348    *           if this object is an invalid instance according to the schema\r
349    */\r
350   public void validate() throws org.exolab.castor.xml.ValidationException {\r
351     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
352     validator.validate(this);\r
353   }\r
354 \r
355 }\r