00975c1ca9059b8f93852f922807697a3b47d5ab
[jalview.git] / src / jalview / binding / Pdbentry.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.binding;
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 Pdbentry.
29  * 
30  * @version $Revision$ $Date$
31  */
32 public class Pdbentry implements java.io.Serializable
33 {
34
35   // --------------------------/
36   // - Class/Member Variables -/
37   // --------------------------/
38
39   /**
40    * Field _id.
41    */
42   private java.lang.String _id;
43
44   /**
45    * Field _type.
46    */
47   private java.lang.String _type;
48
49   /**
50    * Field _items.
51    */
52   private java.util.Vector _items;
53
54   // ----------------/
55   // - Constructors -/
56   // ----------------/
57
58   public Pdbentry()
59   {
60     super();
61     this._items = new java.util.Vector();
62   }
63
64   // -----------/
65   // - Methods -/
66   // -----------/
67
68   /**
69    * 
70    * 
71    * @param vPdbentryItem
72    * @throws java.lang.IndexOutOfBoundsException
73    *           if the index given is outside the bounds of the collection
74    */
75   public void addPdbentryItem(
76           final jalview.binding.PdbentryItem vPdbentryItem)
77           throws java.lang.IndexOutOfBoundsException
78   {
79     this._items.addElement(vPdbentryItem);
80   }
81
82   /**
83    * 
84    * 
85    * @param index
86    * @param vPdbentryItem
87    * @throws java.lang.IndexOutOfBoundsException
88    *           if the index given is outside the bounds of the collection
89    */
90   public void addPdbentryItem(final int index,
91           final jalview.binding.PdbentryItem vPdbentryItem)
92           throws java.lang.IndexOutOfBoundsException
93   {
94     this._items.add(index, vPdbentryItem);
95   }
96
97   /**
98    * Method enumeratePdbentryItem.
99    * 
100    * @return an Enumeration over all jalview.binding.PdbentryItem elements
101    */
102   public java.util.Enumeration enumeratePdbentryItem()
103   {
104     return this._items.elements();
105   }
106
107   /**
108    * Returns the value of field 'id'.
109    * 
110    * @return the value of field 'Id'.
111    */
112   public java.lang.String getId()
113   {
114     return this._id;
115   }
116
117   /**
118    * Method getPdbentryItem.
119    * 
120    * @param index
121    * @throws java.lang.IndexOutOfBoundsException
122    *           if the index given is outside the bounds of the collection
123    * @return the value of the jalview.binding.PdbentryItem at the given index
124    */
125   public jalview.binding.PdbentryItem getPdbentryItem(final int index)
126           throws java.lang.IndexOutOfBoundsException
127   {
128     // check bounds for index
129     if (index < 0 || index >= this._items.size())
130     {
131       throw new IndexOutOfBoundsException("getPdbentryItem: Index value '"
132               + index + "' not in range [0.." + (this._items.size() - 1)
133               + "]");
134     }
135
136     return (jalview.binding.PdbentryItem) _items.get(index);
137   }
138
139   /**
140    * Method getPdbentryItem.Returns the contents of the collection in an Array.
141    * <p>
142    * Note: Just in case the collection contents are changing in another thread,
143    * we pass a 0-length Array of the correct type into the API call. This way we
144    * <i>know</i> that the Array returned is of exactly the correct length.
145    * 
146    * @return this collection as an Array
147    */
148   public jalview.binding.PdbentryItem[] getPdbentryItem()
149   {
150     jalview.binding.PdbentryItem[] array = new jalview.binding.PdbentryItem[0];
151     return (jalview.binding.PdbentryItem[]) this._items.toArray(array);
152   }
153
154   /**
155    * Method getPdbentryItemCount.
156    * 
157    * @return the size of this collection
158    */
159   public int getPdbentryItemCount()
160   {
161     return this._items.size();
162   }
163
164   /**
165    * Returns the value of field 'type'.
166    * 
167    * @return the value of field 'Type'.
168    */
169   public java.lang.String getType()
170   {
171     return this._type;
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 removeAllPdbentryItem()
231   {
232     this._items.clear();
233   }
234
235   /**
236    * Method removePdbentryItem.
237    * 
238    * @param vPdbentryItem
239    * @return true if the object was removed from the collection.
240    */
241   public boolean removePdbentryItem(
242           final jalview.binding.PdbentryItem vPdbentryItem)
243   {
244     boolean removed = _items.remove(vPdbentryItem);
245     return removed;
246   }
247
248   /**
249    * Method removePdbentryItemAt.
250    * 
251    * @param index
252    * @return the element removed from the collection
253    */
254   public jalview.binding.PdbentryItem removePdbentryItemAt(final int index)
255   {
256     java.lang.Object obj = this._items.remove(index);
257     return (jalview.binding.PdbentryItem) obj;
258   }
259
260   /**
261    * Sets the value of field 'id'.
262    * 
263    * @param id
264    *          the value of field 'id'.
265    */
266   public void setId(final java.lang.String id)
267   {
268     this._id = id;
269   }
270
271   /**
272    * 
273    * 
274    * @param index
275    * @param vPdbentryItem
276    * @throws java.lang.IndexOutOfBoundsException
277    *           if the index given is outside the bounds of the collection
278    */
279   public void setPdbentryItem(final int index,
280           final jalview.binding.PdbentryItem vPdbentryItem)
281           throws java.lang.IndexOutOfBoundsException
282   {
283     // check bounds for index
284     if (index < 0 || index >= this._items.size())
285     {
286       throw new IndexOutOfBoundsException("setPdbentryItem: Index value '"
287               + index + "' not in range [0.." + (this._items.size() - 1)
288               + "]");
289     }
290
291     this._items.set(index, vPdbentryItem);
292   }
293
294   /**
295    * 
296    * 
297    * @param vPdbentryItemArray
298    */
299   public void setPdbentryItem(
300           final jalview.binding.PdbentryItem[] vPdbentryItemArray)
301   {
302     // -- copy array
303     _items.clear();
304
305     for (int i = 0; i < vPdbentryItemArray.length; i++)
306     {
307       this._items.add(vPdbentryItemArray[i]);
308     }
309   }
310
311   /**
312    * Sets the value of field 'type'.
313    * 
314    * @param type
315    *          the value of field 'type'.
316    */
317   public void setType(final java.lang.String type)
318   {
319     this._type = type;
320   }
321
322   /**
323    * Method unmarshal.
324    * 
325    * @param reader
326    * @throws org.exolab.castor.xml.MarshalException
327    *           if object is null or if any SAXException is thrown during
328    *           marshaling
329    * @throws org.exolab.castor.xml.ValidationException
330    *           if this object is an invalid instance according to the schema
331    * @return the unmarshaled jalview.binding.Pdbentry
332    */
333   public static jalview.binding.Pdbentry unmarshal(
334           final java.io.Reader reader)
335           throws org.exolab.castor.xml.MarshalException,
336           org.exolab.castor.xml.ValidationException
337   {
338     return (jalview.binding.Pdbentry) Unmarshaller.unmarshal(
339             jalview.binding.Pdbentry.class, reader);
340   }
341
342   /**
343    * 
344    * 
345    * @throws org.exolab.castor.xml.ValidationException
346    *           if this object is an invalid instance according to the schema
347    */
348   public void validate() throws org.exolab.castor.xml.ValidationException
349   {
350     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
351     validator.validate(this);
352   }
353
354 }