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