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