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