applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Instance.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 Instance.\r
33  * \r
34  * @version $Revision$ $Date$\r
35  */\r
36 public class Instance extends uk.ac.vamsas.objects.core.AppData implements\r
37     java.io.Serializable {\r
38 \r
39   // --------------------------/\r
40   // - Class/Member Variables -/\r
41   // --------------------------/\r
42 \r
43   /**\r
44    * Field _urn.\r
45    */\r
46   private java.lang.String _urn;\r
47 \r
48   // ----------------/\r
49   // - Constructors -/\r
50   // ----------------/\r
51 \r
52   public Instance() {\r
53     super();\r
54   }\r
55 \r
56   // -----------/\r
57   // - Methods -/\r
58   // -----------/\r
59 \r
60   /**\r
61    * Overrides the java.lang.Object.equals method.\r
62    * \r
63    * @param obj\r
64    * @return true if the objects are equal.\r
65    */\r
66   public boolean equals(final java.lang.Object obj) {\r
67     if (this == obj)\r
68       return true;\r
69 \r
70     if (super.equals(obj) == false)\r
71       return false;\r
72 \r
73     if (obj instanceof Instance) {\r
74 \r
75       Instance temp = (Instance) obj;\r
76       boolean thcycle;\r
77       boolean tmcycle;\r
78       if (this._urn != null) {\r
79         if (temp._urn == null)\r
80           return false;\r
81         if (this._urn != temp._urn) {\r
82           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._urn);\r
83           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._urn);\r
84           if (thcycle != tmcycle) {\r
85             if (!thcycle) {\r
86               org.castor.util.CycleBreaker.releaseCycleHandle(this._urn);\r
87             }\r
88             ;\r
89             if (!tmcycle) {\r
90               org.castor.util.CycleBreaker.releaseCycleHandle(temp._urn);\r
91             }\r
92             ;\r
93             return false;\r
94           }\r
95           if (!thcycle) {\r
96             if (!this._urn.equals(temp._urn)) {\r
97               org.castor.util.CycleBreaker.releaseCycleHandle(this._urn);\r
98               org.castor.util.CycleBreaker.releaseCycleHandle(temp._urn);\r
99               return false;\r
100             }\r
101             org.castor.util.CycleBreaker.releaseCycleHandle(this._urn);\r
102             org.castor.util.CycleBreaker.releaseCycleHandle(temp._urn);\r
103           }\r
104         }\r
105       } else if (temp._urn != null)\r
106         return false;\r
107       return true;\r
108     }\r
109     return false;\r
110   }\r
111 \r
112   /**\r
113    * Returns the value of field 'urn'.\r
114    * \r
115    * @return the value of field 'Urn'.\r
116    */\r
117   public java.lang.String getUrn() {\r
118     return this._urn;\r
119   }\r
120 \r
121   /**\r
122    * Overrides the java.lang.Object.hashCode method.\r
123    * <p>\r
124    * The following steps came from <b>Effective Java Programming Language\r
125    * Guide</b> by Joshua Bloch, Chapter 3\r
126    * \r
127    * @return a hash code value for the object.\r
128    */\r
129   public int hashCode() {\r
130     int result = super.hashCode();\r
131 \r
132     long tmp;\r
133     if (_urn != null && !org.castor.util.CycleBreaker.startingToCycle(_urn)) {\r
134       result = 37 * result + _urn.hashCode();\r
135       org.castor.util.CycleBreaker.releaseCycleHandle(_urn);\r
136     }\r
137 \r
138     return result;\r
139   }\r
140 \r
141   /**\r
142    * Method isValid.\r
143    * \r
144    * @return true if this object is valid according to the schema\r
145    */\r
146   public boolean isValid() {\r
147     try {\r
148       validate();\r
149     } catch (org.exolab.castor.xml.ValidationException vex) {\r
150       return false;\r
151     }\r
152     return true;\r
153   }\r
154 \r
155   /**\r
156    * \r
157    * \r
158    * @param out\r
159    * @throws org.exolab.castor.xml.MarshalException\r
160    *           if object is null or if any SAXException is thrown during\r
161    *           marshaling\r
162    * @throws org.exolab.castor.xml.ValidationException\r
163    *           if this object is an invalid instance according to the schema\r
164    */\r
165   public void marshal(final java.io.Writer out)\r
166       throws org.exolab.castor.xml.MarshalException,\r
167       org.exolab.castor.xml.ValidationException {\r
168     Marshaller.marshal(this, out);\r
169   }\r
170 \r
171   /**\r
172    * \r
173    * \r
174    * @param handler\r
175    * @throws java.io.IOException\r
176    *           if an IOException occurs during marshaling\r
177    * @throws org.exolab.castor.xml.ValidationException\r
178    *           if this object is an invalid instance according to the schema\r
179    * @throws org.exolab.castor.xml.MarshalException\r
180    *           if object is null or if any SAXException is thrown during\r
181    *           marshaling\r
182    */\r
183   public void marshal(final org.xml.sax.ContentHandler handler)\r
184       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
185       org.exolab.castor.xml.ValidationException {\r
186     Marshaller.marshal(this, handler);\r
187   }\r
188 \r
189   /**\r
190    * Sets the value of field 'urn'.\r
191    * \r
192    * @param urn\r
193    *          the value of field 'urn'.\r
194    */\r
195   public void setUrn(final java.lang.String urn) {\r
196     this._urn = urn;\r
197   }\r
198 \r
199   /**\r
200    * Method unmarshal.\r
201    * \r
202    * @param reader\r
203    * @throws org.exolab.castor.xml.MarshalException\r
204    *           if object is null or if any SAXException is thrown during\r
205    *           marshaling\r
206    * @throws org.exolab.castor.xml.ValidationException\r
207    *           if this object is an invalid instance according to the schema\r
208    * @return the unmarshaled uk.ac.vamsas.objects.core.AppData\r
209    */\r
210   public static uk.ac.vamsas.objects.core.AppData unmarshal(\r
211       final java.io.Reader reader)\r
212       throws org.exolab.castor.xml.MarshalException,\r
213       org.exolab.castor.xml.ValidationException {\r
214     return (uk.ac.vamsas.objects.core.AppData) Unmarshaller.unmarshal(\r
215         uk.ac.vamsas.objects.core.Instance.class, reader);\r
216   }\r
217 \r
218   /**\r
219    * \r
220    * \r
221    * @throws org.exolab.castor.xml.ValidationException\r
222    *           if this object is an invalid instance according to the schema\r
223    */\r
224   public void validate() throws org.exolab.castor.xml.ValidationException {\r
225     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
226     validator.validate(this);\r
227   }\r
228 \r
229 }\r