1
2
3
4
5
6
7
8 package org.astrogrid.workflow.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.workflow.beans.v1.execution.StepExecutionRecord;
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 * a step in the workflow - execute some script statements.
29 *
30 * @version $Revision: 1.13 $ $Date: 2007/01/04 16:26:27 $
31 */
32 public class Script extends org.astrogrid.workflow.beans.v1.AbstractActivity
33 implements java.io.Serializable
34 {
35
36
37
38
39
40
41 /***
42 * optional description of this step
43 */
44 private java.lang.String _description;
45
46 /***
47 * script statements to execute. By default, groovy language is
48 * expected
49 */
50 private java.lang.String _body;
51
52 /***
53 * records of execution of this script step
54 */
55 private java.util.ArrayList _stepExecutionRecordList;
56
57
58
59
60
61
62 public Script() {
63 super();
64 _stepExecutionRecordList = new ArrayList();
65 }
66
67
68
69
70
71
72 /***
73 * Method addStepExecutionRecord
74 *
75 * @param vStepExecutionRecord
76 */
77 public void addStepExecutionRecord(org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord vStepExecutionRecord)
78 throws java.lang.IndexOutOfBoundsException
79 {
80 _stepExecutionRecordList.add(vStepExecutionRecord);
81 }
82
83 /***
84 * Method addStepExecutionRecord
85 *
86 * @param index
87 * @param vStepExecutionRecord
88 */
89 public void addStepExecutionRecord(int index, org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord vStepExecutionRecord)
90 throws java.lang.IndexOutOfBoundsException
91 {
92 _stepExecutionRecordList.add(index, vStepExecutionRecord);
93 }
94
95 /***
96 * Method clearStepExecutionRecord
97 */
98 public void clearStepExecutionRecord()
99 {
100 _stepExecutionRecordList.clear();
101 }
102
103 /***
104 * Method enumerateStepExecutionRecord
105 */
106 public java.util.Enumeration enumerateStepExecutionRecord()
107 {
108 return new org.exolab.castor.util.IteratorEnumeration(_stepExecutionRecordList.iterator());
109 }
110
111 /***
112 * Note: hashCode() has not been overriden
113 *
114 * @param obj
115 */
116 public boolean equals(java.lang.Object obj)
117 {
118 if ( this == obj )
119 return true;
120
121 if (super.equals(obj)==false)
122 return false;
123
124 if (obj instanceof Script) {
125
126 Script temp = (Script)obj;
127 if (this._description != null) {
128 if (temp._description == null) return false;
129 else if (!(this._description.equals(temp._description)))
130 return false;
131 }
132 else if (temp._description != null)
133 return false;
134 if (this._body != null) {
135 if (temp._body == null) return false;
136 else if (!(this._body.equals(temp._body)))
137 return false;
138 }
139 else if (temp._body != null)
140 return false;
141 if (this._stepExecutionRecordList != null) {
142 if (temp._stepExecutionRecordList == null) return false;
143 else if (!(this._stepExecutionRecordList.equals(temp._stepExecutionRecordList)))
144 return false;
145 }
146 else if (temp._stepExecutionRecordList != null)
147 return false;
148 return true;
149 }
150 return false;
151 }
152
153 /***
154 * Returns the value of field 'body'. The field 'body' has the
155 * following description: script statements to execute. By
156 * default, groovy language is expected
157 *
158 * @return the value of field 'body'.
159 */
160 public java.lang.String getBody()
161 {
162 return this._body;
163 }
164
165 /***
166 * Returns the value of field 'description'. The field
167 * 'description' has the following description: optional
168 * description of this step
169 *
170 * @return the value of field 'description'.
171 */
172 public java.lang.String getDescription()
173 {
174 return this._description;
175 }
176
177 /***
178 * Method getStepExecutionRecord
179 *
180 * @param index
181 */
182 public org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord getStepExecutionRecord(int index)
183 throws java.lang.IndexOutOfBoundsException
184 {
185
186 if ((index < 0) || (index > _stepExecutionRecordList.size())) {
187 throw new IndexOutOfBoundsException();
188 }
189
190 return (org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord) _stepExecutionRecordList.get(index);
191 }
192
193 /***
194 * Method getStepExecutionRecord
195 */
196 public org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord[] getStepExecutionRecord()
197 {
198 int size = _stepExecutionRecordList.size();
199 org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord[] mArray = new org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord[size];
200 for (int index = 0; index < size; index++) {
201 mArray[index] = (org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord) _stepExecutionRecordList.get(index);
202 }
203 return mArray;
204 }
205
206 /***
207 * Method getStepExecutionRecordCount
208 */
209 public int getStepExecutionRecordCount()
210 {
211 return _stepExecutionRecordList.size();
212 }
213
214 /***
215 * Method isValid
216 */
217 public boolean isValid()
218 {
219 try {
220 validate();
221 }
222 catch (org.exolab.castor.xml.ValidationException vex) {
223 return false;
224 }
225 return true;
226 }
227
228 /***
229 * Method marshal
230 *
231 * @param out
232 */
233 public void marshal(java.io.Writer out)
234 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
235 {
236
237 Marshaller.marshal(this, out);
238 }
239
240 /***
241 * Method marshal
242 *
243 * @param handler
244 */
245 public void marshal(org.xml.sax.ContentHandler handler)
246 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
247 {
248
249 Marshaller.marshal(this, handler);
250 }
251
252 /***
253 * Method removeStepExecutionRecord
254 *
255 * @param vStepExecutionRecord
256 */
257 public boolean removeStepExecutionRecord(org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord vStepExecutionRecord)
258 {
259 boolean removed = _stepExecutionRecordList.remove(vStepExecutionRecord);
260 return removed;
261 }
262
263 /***
264 * Sets the value of field 'body'. The field 'body' has the
265 * following description: script statements to execute. By
266 * default, groovy language is expected
267 *
268 * @param body the value of field 'body'.
269 */
270 public void setBody(java.lang.String body)
271 {
272 this._body = body;
273 }
274
275 /***
276 * Sets the value of field 'description'. The field
277 * 'description' has the following description: optional
278 * description of this step
279 *
280 * @param description the value of field 'description'.
281 */
282 public void setDescription(java.lang.String description)
283 {
284 this._description = description;
285 }
286
287 /***
288 * Method setStepExecutionRecord
289 *
290 * @param index
291 * @param vStepExecutionRecord
292 */
293 public void setStepExecutionRecord(int index, org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord vStepExecutionRecord)
294 throws java.lang.IndexOutOfBoundsException
295 {
296
297 if ((index < 0) || (index > _stepExecutionRecordList.size())) {
298 throw new IndexOutOfBoundsException();
299 }
300 _stepExecutionRecordList.set(index, vStepExecutionRecord);
301 }
302
303 /***
304 * Method setStepExecutionRecord
305 *
306 * @param stepExecutionRecordArray
307 */
308 public void setStepExecutionRecord(org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord[] stepExecutionRecordArray)
309 {
310
311 _stepExecutionRecordList.clear();
312 for (int i = 0; i < stepExecutionRecordArray.length; i++) {
313 _stepExecutionRecordList.add(stepExecutionRecordArray[i]);
314 }
315 }
316
317 /***
318 * Method unmarshalScript
319 *
320 * @param reader
321 */
322 public static org.astrogrid.workflow.beans.v1.Script unmarshalScript(java.io.Reader reader)
323 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
324 {
325 return (org.astrogrid.workflow.beans.v1.Script) Unmarshaller.unmarshal(org.astrogrid.workflow.beans.v1.Script.class, reader);
326 }
327
328 /***
329 * Method validate
330 */
331 public void validate()
332 throws org.exolab.castor.xml.ValidationException
333 {
334 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
335 validator.validate(this);
336 }
337
338 }