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