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