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