1
2
3
4
5
6
7
8 package org.astrogrid.applications.beans.v1;
9
10
11
12
13
14 import java.io.IOException;
15 import java.io.Reader;
16 import java.io.Serializable;
17 import java.io.Writer;
18 import java.util.ArrayList;
19 import java.util.Enumeration;
20 import org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition;
21 import org.exolab.castor.xml.MarshalException;
22 import org.exolab.castor.xml.Marshaller;
23 import org.exolab.castor.xml.Unmarshaller;
24 import org.exolab.castor.xml.ValidationException;
25 import org.xml.sax.ContentHandler;
26
27 /***
28 * The complete list of parameters that might occur in any of the
29 * apllication interfaces
30 *
31 * @version $Revision: 1.36 $ $Date: 2007/01/04 16:26:34 $
32 */
33 public class Parameters extends org.astrogrid.common.bean.BaseBean
34 implements java.io.Serializable
35 {
36
37
38
39
40
41
42 /***
43 * A generalised parameter - this is a substitution point
44 */
45 private java.util.ArrayList _parameterList;
46
47
48
49
50
51
52 public Parameters() {
53 super();
54 _parameterList = new ArrayList();
55 }
56
57
58
59
60
61
62 /***
63 * Method addParameter
64 *
65 * @param vParameter
66 */
67 public void addParameter(org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition vParameter)
68 throws java.lang.IndexOutOfBoundsException
69 {
70 _parameterList.add(vParameter);
71 }
72
73 /***
74 * Method addParameter
75 *
76 * @param index
77 * @param vParameter
78 */
79 public void addParameter(int index, org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition vParameter)
80 throws java.lang.IndexOutOfBoundsException
81 {
82 _parameterList.add(index, vParameter);
83 }
84
85 /***
86 * Method clearParameter
87 */
88 public void clearParameter()
89 {
90 _parameterList.clear();
91 }
92
93 /***
94 * Method enumerateParameter
95 */
96 public java.util.Enumeration enumerateParameter()
97 {
98 return new org.exolab.castor.util.IteratorEnumeration(_parameterList.iterator());
99 }
100
101 /***
102 * Note: hashCode() has not been overriden
103 *
104 * @param obj
105 */
106 public boolean equals(java.lang.Object obj)
107 {
108 if ( this == obj )
109 return true;
110
111 if (super.equals(obj)==false)
112 return false;
113
114 if (obj instanceof Parameters) {
115
116 Parameters temp = (Parameters)obj;
117 if (this._parameterList != null) {
118 if (temp._parameterList == null) return false;
119 else if (!(this._parameterList.equals(temp._parameterList)))
120 return false;
121 }
122 else if (temp._parameterList != null)
123 return false;
124 return true;
125 }
126 return false;
127 }
128
129 /***
130 * Method getParameter
131 *
132 * @param index
133 */
134 public org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition getParameter(int index)
135 throws java.lang.IndexOutOfBoundsException
136 {
137
138 if ((index < 0) || (index > _parameterList.size())) {
139 throw new IndexOutOfBoundsException();
140 }
141
142 return (org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition) _parameterList.get(index);
143 }
144
145 /***
146 * Method getParameter
147 */
148 public org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition[] getParameter()
149 {
150 int size = _parameterList.size();
151 org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition[] mArray = new org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition[size];
152 for (int index = 0; index < size; index++) {
153 mArray[index] = (org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition) _parameterList.get(index);
154 }
155 return mArray;
156 }
157
158 /***
159 * Method getParameterCount
160 */
161 public int getParameterCount()
162 {
163 return _parameterList.size();
164 }
165
166 /***
167 * Method isValid
168 */
169 public boolean isValid()
170 {
171 try {
172 validate();
173 }
174 catch (org.exolab.castor.xml.ValidationException vex) {
175 return false;
176 }
177 return true;
178 }
179
180 /***
181 * Method marshal
182 *
183 * @param out
184 */
185 public void marshal(java.io.Writer out)
186 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
187 {
188
189 Marshaller.marshal(this, out);
190 }
191
192 /***
193 * Method marshal
194 *
195 * @param handler
196 */
197 public void marshal(org.xml.sax.ContentHandler handler)
198 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
199 {
200
201 Marshaller.marshal(this, handler);
202 }
203
204 /***
205 * Method removeParameter
206 *
207 * @param vParameter
208 */
209 public boolean removeParameter(org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition vParameter)
210 {
211 boolean removed = _parameterList.remove(vParameter);
212 return removed;
213 }
214
215 /***
216 * Method setParameter
217 *
218 * @param index
219 * @param vParameter
220 */
221 public void setParameter(int index, org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition vParameter)
222 throws java.lang.IndexOutOfBoundsException
223 {
224
225 if ((index < 0) || (index > _parameterList.size())) {
226 throw new IndexOutOfBoundsException();
227 }
228 _parameterList.set(index, vParameter);
229 }
230
231 /***
232 * Method setParameter
233 *
234 * @param parameterArray
235 */
236 public void setParameter(org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition[] parameterArray)
237 {
238
239 _parameterList.clear();
240 for (int i = 0; i < parameterArray.length; i++) {
241 _parameterList.add(parameterArray[i]);
242 }
243 }
244
245 /***
246 * Method unmarshalParameters
247 *
248 * @param reader
249 */
250 public static org.astrogrid.applications.beans.v1.Parameters unmarshalParameters(java.io.Reader reader)
251 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
252 {
253 return (org.astrogrid.applications.beans.v1.Parameters) Unmarshaller.unmarshal(org.astrogrid.applications.beans.v1.Parameters.class, reader);
254 }
255
256 /***
257 * Method validate
258 */
259 public void validate()
260 throws org.exolab.castor.xml.ValidationException
261 {
262 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
263 validator.validate(this);
264 }
265
266 }