merge from 2_4_Release branch
[jalview.git] / src / jalview / binding / Pdbentry.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.binding;
20
21 // ---------------------------------/
22 // - Imported classes and packages -/
23 // ---------------------------------/
24
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
27
28 /**
29  * Class Pdbentry.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class Pdbentry implements java.io.Serializable
34 {
35
36   // --------------------------/
37   // - Class/Member Variables -/
38   // --------------------------/
39
40   /**
41    * Field _id.
42    */
43   private java.lang.String _id;
44
45   /**
46    * Field _type.
47    */
48   private java.lang.String _type;
49
50   /**
51    * Field _items.
52    */
53   private java.util.Vector _items;
54
55   // ----------------/
56   // - Constructors -/
57   // ----------------/
58
59   public Pdbentry()
60   {
61     super();
62     this._items = new java.util.Vector();
63   }
64
65   // -----------/
66   // - Methods -/
67   // -----------/
68
69   /**
70    * 
71    * 
72    * @param vPdbentryItem
73    * @throws java.lang.IndexOutOfBoundsException
74    *                 if the index given is outside the bounds of the collection
75    */
76   public void addPdbentryItem(
77           final jalview.binding.PdbentryItem vPdbentryItem)
78           throws java.lang.IndexOutOfBoundsException
79   {
80     this._items.addElement(vPdbentryItem);
81   }
82
83   /**
84    * 
85    * 
86    * @param index
87    * @param vPdbentryItem
88    * @throws java.lang.IndexOutOfBoundsException
89    *                 if the index given is outside the bounds of the collection
90    */
91   public void addPdbentryItem(final int index,
92           final jalview.binding.PdbentryItem vPdbentryItem)
93           throws java.lang.IndexOutOfBoundsException
94   {
95     this._items.add(index, vPdbentryItem);
96   }
97
98   /**
99    * Method enumeratePdbentryItem.
100    * 
101    * @return an Enumeration over all jalview.binding.PdbentryItem elements
102    */
103   public java.util.Enumeration enumeratePdbentryItem()
104   {
105     return this._items.elements();
106   }
107
108   /**
109    * Returns the value of field 'id'.
110    * 
111    * @return the value of field 'Id'.
112    */
113   public java.lang.String getId()
114   {
115     return this._id;
116   }
117
118   /**
119    * Method getPdbentryItem.
120    * 
121    * @param index
122    * @throws java.lang.IndexOutOfBoundsException
123    *                 if the index given is outside the bounds of the collection
124    * @return the value of the jalview.binding.PdbentryItem at the given index
125    */
126   public jalview.binding.PdbentryItem getPdbentryItem(final int index)
127           throws java.lang.IndexOutOfBoundsException
128   {
129     // check bounds for index
130     if (index < 0 || index >= this._items.size())
131     {
132       throw new IndexOutOfBoundsException("getPdbentryItem: Index value '"
133               + index + "' not in range [0.." + (this._items.size() - 1)
134               + "]");
135     }
136
137     return (jalview.binding.PdbentryItem) _items.get(index);
138   }
139
140   /**
141    * Method getPdbentryItem.Returns the contents of the collection in an Array.
142    * <p>
143    * Note: Just in case the collection contents are changing in another thread,
144    * we pass a 0-length Array of the correct type into the API call. This way we
145    * <i>know</i> that the Array returned is of exactly the correct length.
146    * 
147    * @return this collection as an Array
148    */
149   public jalview.binding.PdbentryItem[] getPdbentryItem()
150   {
151     jalview.binding.PdbentryItem[] array = new jalview.binding.PdbentryItem[0];
152     return (jalview.binding.PdbentryItem[]) this._items.toArray(array);
153   }
154
155   /**
156    * Method getPdbentryItemCount.
157    * 
158    * @return the size of this collection
159    */
160   public int getPdbentryItemCount()
161   {
162     return this._items.size();
163   }
164
165   /**
166    * Returns the value of field 'type'.
167    * 
168    * @return the value of field 'Type'.
169    */
170   public java.lang.String getType()
171   {
172     return this._type;
173   }
174
175   /**
176    * Method isValid.
177    * 
178    * @return true if this object is valid according to the schema
179    */
180   public boolean isValid()
181   {
182     try
183     {
184       validate();
185     } catch (org.exolab.castor.xml.ValidationException vex)
186     {
187       return false;
188     }
189     return true;
190   }
191
192   /**
193    * 
194    * 
195    * @param out
196    * @throws org.exolab.castor.xml.MarshalException
197    *                 if object is null or if any SAXException is thrown during
198    *                 marshaling
199    * @throws org.exolab.castor.xml.ValidationException
200    *                 if this object is an invalid instance according to the
201    *                 schema
202    */
203   public void marshal(final java.io.Writer out)
204           throws org.exolab.castor.xml.MarshalException,
205           org.exolab.castor.xml.ValidationException
206   {
207     Marshaller.marshal(this, out);
208   }
209
210   /**
211    * 
212    * 
213    * @param handler
214    * @throws java.io.IOException
215    *                 if an IOException occurs during marshaling
216    * @throws org.exolab.castor.xml.ValidationException
217    *                 if this object is an invalid instance according to the
218    *                 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
334    *                 schema
335    * @return the unmarshaled jalview.binding.Pdbentry
336    */
337   public static jalview.binding.Pdbentry unmarshal(
338           final java.io.Reader reader)
339           throws org.exolab.castor.xml.MarshalException,
340           org.exolab.castor.xml.ValidationException
341   {
342     return (jalview.binding.Pdbentry) Unmarshaller.unmarshal(
343             jalview.binding.Pdbentry.class, reader);
344   }
345
346   /**
347    * 
348    * 
349    * @throws org.exolab.castor.xml.ValidationException
350    *                 if this object is an invalid instance according to the
351    *                 schema
352    */
353   public void validate() throws org.exolab.castor.xml.ValidationException
354   {
355     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
356     validator.validate(this);
357   }
358
359 }