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