KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.soto.state;
2
3 import org.apache.commons.lang.ClassUtils;
4
5
6 /**
7  * Models a state reference: refers to a previously configured state, with the
8  * latter's identifier.
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 StateRef implements Step {
18   private String JavaDoc _id;
19   private String JavaDoc _module;
20
21   public StateRef() {
22   }
23
24   /**
25    * @see org.sapia.soto.state.Step#getName()
26    */

27   public String JavaDoc getName() {
28     return ClassUtils.getShortClassName(getClass());
29   }
30
31   /**
32    * @param id the identifier of the flow to which this instance refers.
33    */

34   public void setId(String JavaDoc id) {
35     _id = id;
36   }
37
38   /**
39    * @see State#getId()
40    */

41   public String JavaDoc getId() {
42     return _id;
43   }
44
45   /**
46    * @param module the name of the module to which the state to execute belongs.
47    */

48   public void setModule(String JavaDoc module) {
49     _module = module;
50   }
51
52   /**
53    * @see org.sapia.soto.state.Executable#execute(Result)
54    */

55   public void execute(Result res) {
56     if (_id == null) {
57       throw new IllegalStateException JavaDoc("'id' not specified on stateRef");
58     }
59
60     String JavaDoc currentState = res.getCurrentStateId();
61
62     try {
63       res.exec(_id, _module);
64     } catch (StateExecException e) {
65       res.error(e);
66
67       return;
68     }
69
70     res.setCurrentStateId(currentState);
71   }
72 }
73
Popular Tags