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