736077291fc68a2ff50117d593b938054c11283c
[jalview.git] / src / jalview / schemabinding / version2 / Sequence.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  * \r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  * \r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  * \r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.schemabinding.version2;\r
20 \r
21 // ---------------------------------/\r
22 // - Imported classes and packages -/\r
23 // ---------------------------------/\r
24 \r
25 import org.exolab.castor.xml.Marshaller;\r
26 import org.exolab.castor.xml.Unmarshaller;\r
27 \r
28 /**\r
29  * Class Sequence.\r
30  * \r
31  * @version $Revision$ $Date$\r
32  */\r
33 public class Sequence extends jalview.schemabinding.version2.SequenceType\r
34         implements java.io.Serializable\r
35 {\r
36 \r
37   // --------------------------/\r
38   // - Class/Member Variables -/\r
39   // --------------------------/\r
40 \r
41   /**\r
42    * dataset sequence id for this sequence. Will be created as union of\r
43    * sequences.\r
44    * \r
45    */\r
46   private java.lang.String _dsseqid;\r
47 \r
48   /**\r
49    * Field _DBRefList.\r
50    */\r
51   private java.util.Vector _DBRefList;\r
52 \r
53   // ----------------/\r
54   // - Constructors -/\r
55   // ----------------/\r
56 \r
57   public Sequence()\r
58   {\r
59     super();\r
60     this._DBRefList = new java.util.Vector();\r
61   }\r
62 \r
63   // -----------/\r
64   // - Methods -/\r
65   // -----------/\r
66 \r
67   /**\r
68    * \r
69    * \r
70    * @param vDBRef\r
71    * @throws java.lang.IndexOutOfBoundsException\r
72    *                 if the index given is outside the bounds of the collection\r
73    */\r
74   public void addDBRef(final jalview.schemabinding.version2.DBRef vDBRef)\r
75           throws java.lang.IndexOutOfBoundsException\r
76   {\r
77     this._DBRefList.addElement(vDBRef);\r
78   }\r
79 \r
80   /**\r
81    * \r
82    * \r
83    * @param index\r
84    * @param vDBRef\r
85    * @throws java.lang.IndexOutOfBoundsException\r
86    *                 if the index given is outside the bounds of the collection\r
87    */\r
88   public void addDBRef(final int index,\r
89           final jalview.schemabinding.version2.DBRef vDBRef)\r
90           throws java.lang.IndexOutOfBoundsException\r
91   {\r
92     this._DBRefList.add(index, vDBRef);\r
93   }\r
94 \r
95   /**\r
96    * Method enumerateDBRef.\r
97    * \r
98    * @return an Enumeration over all jalview.schemabinding.version2.DBRef\r
99    *         elements\r
100    */\r
101   public java.util.Enumeration enumerateDBRef()\r
102   {\r
103     return this._DBRefList.elements();\r
104   }\r
105 \r
106   /**\r
107    * Method getDBRef.\r
108    * \r
109    * @param index\r
110    * @throws java.lang.IndexOutOfBoundsException\r
111    *                 if the index given is outside the bounds of the collection\r
112    * @return the value of the jalview.schemabinding.version2.DBRef at the given\r
113    *         index\r
114    */\r
115   public jalview.schemabinding.version2.DBRef getDBRef(final int index)\r
116           throws java.lang.IndexOutOfBoundsException\r
117   {\r
118     // check bounds for index\r
119     if (index < 0 || index >= this._DBRefList.size())\r
120     {\r
121       throw new IndexOutOfBoundsException("getDBRef: Index value '" + index\r
122               + "' not in range [0.." + (this._DBRefList.size() - 1) + "]");\r
123     }\r
124 \r
125     return (jalview.schemabinding.version2.DBRef) _DBRefList.get(index);\r
126   }\r
127 \r
128   /**\r
129    * Method getDBRef.Returns the contents of the collection in an Array.\r
130    * <p>\r
131    * Note: Just in case the collection contents are changing in another thread,\r
132    * we pass a 0-length Array of the correct type into the API call. This way we\r
133    * <i>know</i> that the Array returned is of exactly the correct length.\r
134    * \r
135    * @return this collection as an Array\r
136    */\r
137   public jalview.schemabinding.version2.DBRef[] getDBRef()\r
138   {\r
139     jalview.schemabinding.version2.DBRef[] array = new jalview.schemabinding.version2.DBRef[0];\r
140     return (jalview.schemabinding.version2.DBRef[]) this._DBRefList\r
141             .toArray(array);\r
142   }\r
143 \r
144   /**\r
145    * Method getDBRefCount.\r
146    * \r
147    * @return the size of this collection\r
148    */\r
149   public int getDBRefCount()\r
150   {\r
151     return this._DBRefList.size();\r
152   }\r
153 \r
154   /**\r
155    * Returns the value of field 'dsseqid'. The field 'dsseqid' has the following\r
156    * description: dataset sequence id for this sequence. Will be created as\r
157    * union of sequences.\r
158    * \r
159    * \r
160    * @return the value of field 'Dsseqid'.\r
161    */\r
162   public java.lang.String getDsseqid()\r
163   {\r
164     return this._dsseqid;\r
165   }\r
166 \r
167   /**\r
168    * Method isValid.\r
169    * \r
170    * @return true if this object is valid according to the schema\r
171    */\r
172   public boolean isValid()\r
173   {\r
174     try\r
175     {\r
176       validate();\r
177     } catch (org.exolab.castor.xml.ValidationException vex)\r
178     {\r
179       return false;\r
180     }\r
181     return true;\r
182   }\r
183 \r
184   /**\r
185    * \r
186    * \r
187    * @param out\r
188    * @throws org.exolab.castor.xml.MarshalException\r
189    *                 if object is null or if any SAXException is thrown during\r
190    *                 marshaling\r
191    * @throws org.exolab.castor.xml.ValidationException\r
192    *                 if this object is an invalid instance according to the\r
193    *                 schema\r
194    */\r
195   public void marshal(final java.io.Writer out)\r
196           throws org.exolab.castor.xml.MarshalException,\r
197           org.exolab.castor.xml.ValidationException\r
198   {\r
199     Marshaller.marshal(this, out);\r
200   }\r
201 \r
202   /**\r
203    * \r
204    * \r
205    * @param handler\r
206    * @throws java.io.IOException\r
207    *                 if an IOException occurs during marshaling\r
208    * @throws org.exolab.castor.xml.ValidationException\r
209    *                 if this object is an invalid instance according to the\r
210    *                 schema\r
211    * @throws org.exolab.castor.xml.MarshalException\r
212    *                 if object is null or if any SAXException is thrown during\r
213    *                 marshaling\r
214    */\r
215   public void marshal(final org.xml.sax.ContentHandler handler)\r
216           throws java.io.IOException,\r
217           org.exolab.castor.xml.MarshalException,\r
218           org.exolab.castor.xml.ValidationException\r
219   {\r
220     Marshaller.marshal(this, handler);\r
221   }\r
222 \r
223   /**\r
224    */\r
225   public void removeAllDBRef()\r
226   {\r
227     this._DBRefList.clear();\r
228   }\r
229 \r
230   /**\r
231    * Method removeDBRef.\r
232    * \r
233    * @param vDBRef\r
234    * @return true if the object was removed from the collection.\r
235    */\r
236   public boolean removeDBRef(\r
237           final jalview.schemabinding.version2.DBRef vDBRef)\r
238   {\r
239     boolean removed = _DBRefList.remove(vDBRef);\r
240     return removed;\r
241   }\r
242 \r
243   /**\r
244    * Method removeDBRefAt.\r
245    * \r
246    * @param index\r
247    * @return the element removed from the collection\r
248    */\r
249   public jalview.schemabinding.version2.DBRef removeDBRefAt(final int index)\r
250   {\r
251     java.lang.Object obj = this._DBRefList.remove(index);\r
252     return (jalview.schemabinding.version2.DBRef) obj;\r
253   }\r
254 \r
255   /**\r
256    * \r
257    * \r
258    * @param index\r
259    * @param vDBRef\r
260    * @throws java.lang.IndexOutOfBoundsException\r
261    *                 if the index given is outside the bounds of the collection\r
262    */\r
263   public void setDBRef(final int index,\r
264           final jalview.schemabinding.version2.DBRef vDBRef)\r
265           throws java.lang.IndexOutOfBoundsException\r
266   {\r
267     // check bounds for index\r
268     if (index < 0 || index >= this._DBRefList.size())\r
269     {\r
270       throw new IndexOutOfBoundsException("setDBRef: Index value '" + index\r
271               + "' not in range [0.." + (this._DBRefList.size() - 1) + "]");\r
272     }\r
273 \r
274     this._DBRefList.set(index, vDBRef);\r
275   }\r
276 \r
277   /**\r
278    * \r
279    * \r
280    * @param vDBRefArray\r
281    */\r
282   public void setDBRef(\r
283           final jalview.schemabinding.version2.DBRef[] vDBRefArray)\r
284   {\r
285     // -- copy array\r
286     _DBRefList.clear();\r
287 \r
288     for (int i = 0; i < vDBRefArray.length; i++)\r
289     {\r
290       this._DBRefList.add(vDBRefArray[i]);\r
291     }\r
292   }\r
293 \r
294   /**\r
295    * Sets the value of field 'dsseqid'. The field 'dsseqid' has the following\r
296    * description: dataset sequence id for this sequence. Will be created as\r
297    * union of sequences.\r
298    * \r
299    * \r
300    * @param dsseqid\r
301    *                the value of field 'dsseqid'.\r
302    */\r
303   public void setDsseqid(final java.lang.String dsseqid)\r
304   {\r
305     this._dsseqid = dsseqid;\r
306   }\r
307 \r
308   /**\r
309    * Method unmarshal.\r
310    * \r
311    * @param reader\r
312    * @throws org.exolab.castor.xml.MarshalException\r
313    *                 if object is null or if any SAXException is thrown during\r
314    *                 marshaling\r
315    * @throws org.exolab.castor.xml.ValidationException\r
316    *                 if this object is an invalid instance according to the\r
317    *                 schema\r
318    * @return the unmarshaled jalview.schemabinding.version2.SequenceType\r
319    */\r
320   public static jalview.schemabinding.version2.SequenceType unmarshal(\r
321           final java.io.Reader reader)\r
322           throws org.exolab.castor.xml.MarshalException,\r
323           org.exolab.castor.xml.ValidationException\r
324   {\r
325     return (jalview.schemabinding.version2.SequenceType) Unmarshaller\r
326             .unmarshal(jalview.schemabinding.version2.Sequence.class,\r
327                     reader);\r
328   }\r
329 \r
330   /**\r
331    * \r
332    * \r
333    * @throws org.exolab.castor.xml.ValidationException\r
334    *                 if this object is an invalid instance according to the\r
335    *                 schema\r
336    */\r
337   public void validate() throws org.exolab.castor.xml.ValidationException\r
338   {\r
339     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
340     validator.validate(this);\r
341   }\r
342 \r
343 }\r