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