KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.soto.state;
2
3 import org.sapia.util.xml.confix.ConfigurationException;
4 import org.sapia.util.xml.confix.ObjectHandlerIF;
5
6
7 /**
8  * Implements the <code>State</code> interface over the <code>ExecContainer</code>
9  * class. An instance of this class holds execution <code>Step</code>s that are executed
10  * sequentially when the instance's executed() method is called.
11  *
12  * @see org.sapia.soto.state.Step
13  *
14  * @author Yanick Duchesne
15  * <dl>
16  * <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>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class StepState extends ExecContainer implements State, ObjectHandlerIF {
22   private String JavaDoc _errState;
23   private String JavaDoc _successState;
24   private String JavaDoc _id;
25
26   public StepState() {
27     super();
28   }
29
30   /**
31    * Sets the identifier of this instance.
32    *
33    * @see org.sapia.soto.state.State#getId()
34    */

35   public void setId(String JavaDoc id) {
36     _id = id;
37   }
38
39   /**
40    * @see org.sapia.soto.state.State#getId()
41    */

42   public String JavaDoc getId() {
43     return _id;
44   }
45
46   /**
47    * @param errState the identifier of the state to execute if an error is signaled
48    * by one of the steps held by this instance.
49    */

50   public void setError(String JavaDoc errState) {
51     _errState = errState;
52   }
53
54   /**
55    * @param success the identifier of the state to execute if no step held within
56    * this instance signals an error in the context of the execution.
57    */

58   public void setSuccess(String JavaDoc successState) {
59     _successState = successState;
60   }
61
62   /**
63    * @see org.sapia.util.xml.confix.ObjectHandlerIF#handleObject(java.lang.String, java.lang.Object)
64    */

65   public void handleObject(String JavaDoc name, Object JavaDoc obj)
66     throws ConfigurationException {
67     if (obj instanceof Step) {
68       _execs.add(obj);
69     }
70   }
71
72   /**
73    * @see org.sapia.soto.state.ExecContainer#handleError(Result)
74    */

75   protected void handleError(Result res) {
76     if (_errState != null) {
77       try {
78         res.exec(_errState, null);
79       } catch (StateExecException e) {
80         res.error(e);
81
82         return;
83       }
84     }
85   }
86
87   /**
88    * @see org.sapia.soto.state.ExecContainer#handleSuccess(Result)
89    */

90   protected void handleSuccess(Result st) {
91     st.setNextStateId(_successState);
92   }
93 }
94
Popular Tags