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