KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > ExecContainer


1 package org.sapia.soto.state;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6
7 /**
8  * This class is a utility that holds a list of <code>Executable</code>s.
9  *
10  * @author Yanick Duchesne
11  * <dl>
12  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
13  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
14  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
15  * </dl>
16  */

17 public class ExecContainer {
18   protected List JavaDoc _execs = new ArrayList JavaDoc();
19
20   public ExecContainer() {
21   }
22
23   /**
24    * Adds an executable to this instance.
25    *
26    * @param exec an <code>Executable</code>.
27    */

28   public void addExecutable(Executable exec) {
29     _execs.add(exec);
30   }
31
32   /**
33    * @param st a <code>State</code>.
34    */

35   public void execute(Result st) {
36     Step step;
37
38     for (int i = 0; i < _execs.size(); i++) {
39       step = (Step) _execs.get(i);
40       step.execute(st);
41
42       if (st.isError()) {
43         handleError(st);
44
45         return;
46       } else if (st.isAborted()) {
47         return;
48       } else if (st.getNextStateId() != null) {
49         return;
50       }
51     }
52
53     handleSuccess(st);
54   }
55
56   /**
57    * Template method (to be overridden) that is internally called when an
58    * error has been assigned to the given <code>State</code>.
59    *
60    * @param st a <code>State</code>.
61    */

62   protected void handleError(Result st) {
63   }
64
65   /**
66    * Template method (to be overridden) that is internally called when all
67    * <code>Executables</code> held with this instance have been successfully
68    * executed (i.e.: no error has been assigned to the given <code>State</code>).
69    *
70    * @param st a <code>State</code>.
71    */

72   protected void handleSuccess(Result st) {
73   }
74 }
75
Popular Tags