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