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