e507af9d37131647000ad0f4ba943f311dd47934
[jalview.git] / src / jalview / schemabinding / version2 / FeatureSettings.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.schemabinding.version2;
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 FeatureSettings.
29  * 
30  * @version $Revision$ $Date$
31  */
32 public class FeatureSettings implements java.io.Serializable
33 {
34
35   // --------------------------/
36   // - Class/Member Variables -/
37   // --------------------------/
38
39   /**
40    * Field _settingList.
41    */
42   private java.util.Vector _settingList;
43
44   /**
45    * Field _groupList.
46    */
47   private java.util.Vector _groupList;
48
49   // ----------------/
50   // - Constructors -/
51   // ----------------/
52
53   public FeatureSettings()
54   {
55     super();
56     this._settingList = new java.util.Vector();
57     this._groupList = new java.util.Vector();
58   }
59
60   // -----------/
61   // - Methods -/
62   // -----------/
63
64   /**
65    * 
66    * 
67    * @param vGroup
68    * @throws java.lang.IndexOutOfBoundsException
69    *           if the index given is outside the bounds of the collection
70    */
71   public void addGroup(final jalview.schemabinding.version2.Group vGroup)
72           throws java.lang.IndexOutOfBoundsException
73   {
74     this._groupList.addElement(vGroup);
75   }
76
77   /**
78    * 
79    * 
80    * @param index
81    * @param vGroup
82    * @throws java.lang.IndexOutOfBoundsException
83    *           if the index given is outside the bounds of the collection
84    */
85   public void addGroup(final int index,
86           final jalview.schemabinding.version2.Group vGroup)
87           throws java.lang.IndexOutOfBoundsException
88   {
89     this._groupList.add(index, vGroup);
90   }
91
92   /**
93    * 
94    * 
95    * @param vSetting
96    * @throws java.lang.IndexOutOfBoundsException
97    *           if the index given is outside the bounds of the collection
98    */
99   public void addSetting(
100           final jalview.schemabinding.version2.Setting vSetting)
101           throws java.lang.IndexOutOfBoundsException
102   {
103     this._settingList.addElement(vSetting);
104   }
105
106   /**
107    * 
108    * 
109    * @param index
110    * @param vSetting
111    * @throws java.lang.IndexOutOfBoundsException
112    *           if the index given is outside the bounds of the collection
113    */
114   public void addSetting(final int index,
115           final jalview.schemabinding.version2.Setting vSetting)
116           throws java.lang.IndexOutOfBoundsException
117   {
118     this._settingList.add(index, vSetting);
119   }
120
121   /**
122    * Method enumerateGroup.
123    * 
124    * @return an Enumeration over all jalview.schemabinding.version2.Group
125    *         elements
126    */
127   public java.util.Enumeration enumerateGroup()
128   {
129     return this._groupList.elements();
130   }
131
132   /**
133    * Method enumerateSetting.
134    * 
135    * @return an Enumeration over all jalview.schemabinding.version2.Setting
136    *         elements
137    */
138   public java.util.Enumeration enumerateSetting()
139   {
140     return this._settingList.elements();
141   }
142
143   /**
144    * Method getGroup.
145    * 
146    * @param index
147    * @throws java.lang.IndexOutOfBoundsException
148    *           if the index given is outside the bounds of the collection
149    * @return the value of the jalview.schemabinding.version2.Group at the given
150    *         index
151    */
152   public jalview.schemabinding.version2.Group getGroup(final int index)
153           throws java.lang.IndexOutOfBoundsException
154   {
155     // check bounds for index
156     if (index < 0 || index >= this._groupList.size())
157     {
158       throw new IndexOutOfBoundsException("getGroup: Index value '" + index
159               + "' not in range [0.." + (this._groupList.size() - 1) + "]");
160     }
161
162     return (jalview.schemabinding.version2.Group) _groupList.get(index);
163   }
164
165   /**
166    * Method getGroup.Returns the contents of the collection in an Array.
167    * <p>
168    * Note: Just in case the collection contents are changing in another thread,
169    * we pass a 0-length Array of the correct type into the API call. This way we
170    * <i>know</i> that the Array returned is of exactly the correct length.
171    * 
172    * @return this collection as an Array
173    */
174   public jalview.schemabinding.version2.Group[] getGroup()
175   {
176     jalview.schemabinding.version2.Group[] array = new jalview.schemabinding.version2.Group[0];
177     return (jalview.schemabinding.version2.Group[]) this._groupList
178             .toArray(array);
179   }
180
181   /**
182    * Method getGroupCount.
183    * 
184    * @return the size of this collection
185    */
186   public int getGroupCount()
187   {
188     return this._groupList.size();
189   }
190
191   /**
192    * Method getSetting.
193    * 
194    * @param index
195    * @throws java.lang.IndexOutOfBoundsException
196    *           if the index given is outside the bounds of the collection
197    * @return the value of the jalview.schemabinding.version2.Setting at the
198    *         given index
199    */
200   public jalview.schemabinding.version2.Setting getSetting(final int index)
201           throws java.lang.IndexOutOfBoundsException
202   {
203     // check bounds for index
204     if (index < 0 || index >= this._settingList.size())
205     {
206       throw new IndexOutOfBoundsException("getSetting: Index value '"
207               + index + "' not in range [0.."
208               + (this._settingList.size() - 1) + "]");
209     }
210
211     return (jalview.schemabinding.version2.Setting) _settingList.get(index);
212   }
213
214   /**
215    * Method getSetting.Returns the contents of the collection in an Array.
216    * <p>
217    * Note: Just in case the collection contents are changing in another thread,
218    * we pass a 0-length Array of the correct type into the API call. This way we
219    * <i>know</i> that the Array returned is of exactly the correct length.
220    * 
221    * @return this collection as an Array
222    */
223   public jalview.schemabinding.version2.Setting[] getSetting()
224   {
225     jalview.schemabinding.version2.Setting[] array = new jalview.schemabinding.version2.Setting[0];
226     return (jalview.schemabinding.version2.Setting[]) this._settingList
227             .toArray(array);
228   }
229
230   /**
231    * Method getSettingCount.
232    * 
233    * @return the size of this collection
234    */
235   public int getSettingCount()
236   {
237     return this._settingList.size();
238   }
239
240   /**
241    * Method isValid.
242    * 
243    * @return true if this object is valid according to the schema
244    */
245   public boolean isValid()
246   {
247     try
248     {
249       validate();
250     } catch (org.exolab.castor.xml.ValidationException vex)
251     {
252       return false;
253     }
254     return true;
255   }
256
257   /**
258    * 
259    * 
260    * @param out
261    * @throws org.exolab.castor.xml.MarshalException
262    *           if object is null or if any SAXException is thrown during
263    *           marshaling
264    * @throws org.exolab.castor.xml.ValidationException
265    *           if this object is an invalid instance according to the schema
266    */
267   public void marshal(final java.io.Writer out)
268           throws org.exolab.castor.xml.MarshalException,
269           org.exolab.castor.xml.ValidationException
270   {
271     Marshaller.marshal(this, out);
272   }
273
274   /**
275    * 
276    * 
277    * @param handler
278    * @throws java.io.IOException
279    *           if an IOException occurs during marshaling
280    * @throws org.exolab.castor.xml.ValidationException
281    *           if this object is an invalid instance according to the schema
282    * @throws org.exolab.castor.xml.MarshalException
283    *           if object is null or if any SAXException is thrown during
284    *           marshaling
285    */
286   public void marshal(final org.xml.sax.ContentHandler handler)
287           throws java.io.IOException,
288           org.exolab.castor.xml.MarshalException,
289           org.exolab.castor.xml.ValidationException
290   {
291     Marshaller.marshal(this, handler);
292   }
293
294   /**
295      */
296   public void removeAllGroup()
297   {
298     this._groupList.clear();
299   }
300
301   /**
302      */
303   public void removeAllSetting()
304   {
305     this._settingList.clear();
306   }
307
308   /**
309    * Method removeGroup.
310    * 
311    * @param vGroup
312    * @return true if the object was removed from the collection.
313    */
314   public boolean removeGroup(
315           final jalview.schemabinding.version2.Group vGroup)
316   {
317     boolean removed = _groupList.remove(vGroup);
318     return removed;
319   }
320
321   /**
322    * Method removeGroupAt.
323    * 
324    * @param index
325    * @return the element removed from the collection
326    */
327   public jalview.schemabinding.version2.Group removeGroupAt(final int index)
328   {
329     java.lang.Object obj = this._groupList.remove(index);
330     return (jalview.schemabinding.version2.Group) obj;
331   }
332
333   /**
334    * Method removeSetting.
335    * 
336    * @param vSetting
337    * @return true if the object was removed from the collection.
338    */
339   public boolean removeSetting(
340           final jalview.schemabinding.version2.Setting vSetting)
341   {
342     boolean removed = _settingList.remove(vSetting);
343     return removed;
344   }
345
346   /**
347    * Method removeSettingAt.
348    * 
349    * @param index
350    * @return the element removed from the collection
351    */
352   public jalview.schemabinding.version2.Setting removeSettingAt(
353           final int index)
354   {
355     java.lang.Object obj = this._settingList.remove(index);
356     return (jalview.schemabinding.version2.Setting) obj;
357   }
358
359   /**
360    * 
361    * 
362    * @param index
363    * @param vGroup
364    * @throws java.lang.IndexOutOfBoundsException
365    *           if the index given is outside the bounds of the collection
366    */
367   public void setGroup(final int index,
368           final jalview.schemabinding.version2.Group vGroup)
369           throws java.lang.IndexOutOfBoundsException
370   {
371     // check bounds for index
372     if (index < 0 || index >= this._groupList.size())
373     {
374       throw new IndexOutOfBoundsException("setGroup: Index value '" + index
375               + "' not in range [0.." + (this._groupList.size() - 1) + "]");
376     }
377
378     this._groupList.set(index, vGroup);
379   }
380
381   /**
382    * 
383    * 
384    * @param vGroupArray
385    */
386   public void setGroup(
387           final jalview.schemabinding.version2.Group[] vGroupArray)
388   {
389     // -- copy array
390     _groupList.clear();
391
392     for (int i = 0; i < vGroupArray.length; i++)
393     {
394       this._groupList.add(vGroupArray[i]);
395     }
396   }
397
398   /**
399    * 
400    * 
401    * @param index
402    * @param vSetting
403    * @throws java.lang.IndexOutOfBoundsException
404    *           if the index given is outside the bounds of the collection
405    */
406   public void setSetting(final int index,
407           final jalview.schemabinding.version2.Setting vSetting)
408           throws java.lang.IndexOutOfBoundsException
409   {
410     // check bounds for index
411     if (index < 0 || index >= this._settingList.size())
412     {
413       throw new IndexOutOfBoundsException("setSetting: Index value '"
414               + index + "' not in range [0.."
415               + (this._settingList.size() - 1) + "]");
416     }
417
418     this._settingList.set(index, vSetting);
419   }
420
421   /**
422    * 
423    * 
424    * @param vSettingArray
425    */
426   public void setSetting(
427           final jalview.schemabinding.version2.Setting[] vSettingArray)
428   {
429     // -- copy array
430     _settingList.clear();
431
432     for (int i = 0; i < vSettingArray.length; i++)
433     {
434       this._settingList.add(vSettingArray[i]);
435     }
436   }
437
438   /**
439    * Method unmarshal.
440    * 
441    * @param reader
442    * @throws org.exolab.castor.xml.MarshalException
443    *           if object is null or if any SAXException is thrown during
444    *           marshaling
445    * @throws org.exolab.castor.xml.ValidationException
446    *           if this object is an invalid instance according to the schema
447    * @return the unmarshaled jalview.schemabinding.version2.FeatureSettings
448    */
449   public static jalview.schemabinding.version2.FeatureSettings unmarshal(
450           final java.io.Reader reader)
451           throws org.exolab.castor.xml.MarshalException,
452           org.exolab.castor.xml.ValidationException
453   {
454     return (jalview.schemabinding.version2.FeatureSettings) Unmarshaller
455             .unmarshal(
456                     jalview.schemabinding.version2.FeatureSettings.class,
457                     reader);
458   }
459
460   /**
461    * 
462    * 
463    * @throws org.exolab.castor.xml.ValidationException
464    *           if this object is an invalid instance according to the schema
465    */
466   public void validate() throws org.exolab.castor.xml.ValidationException
467   {
468     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
469     validator.validate(this);
470   }
471
472 }