KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > util > VarStep


1 package org.sapia.soto.state.util;
2
3 import org.apache.commons.lang.ClassUtils;
4
5 import org.sapia.soto.state.Result;
6 import org.sapia.soto.state.Scope;
7 import org.sapia.soto.state.Step;
8
9
10 /**
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class VarStep implements Step {
20   private String JavaDoc _key;
21   private String JavaDoc _value;
22   private String JavaDoc _scope;
23
24   public void setKey(String JavaDoc key) {
25     _key = key;
26   }
27
28   public void setValue(String JavaDoc value) {
29     _value = value;
30   }
31
32   public void setScope(String JavaDoc scope) {
33     _scope = scope;
34   }
35
36   /**
37    * @see org.sapia.soto.state.Step#getName()
38    */

39   public String JavaDoc getName() {
40     return ClassUtils.getShortClassName(getClass());
41   }
42
43   /**
44    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
45    */

46   public void execute(Result st) {
47     if (_key == null) {
48       throw new IllegalStateException JavaDoc("Variable key not specified");
49     }
50
51     if (_scope == null) {
52       throw new IllegalStateException JavaDoc("Variable scope not specified");
53     }
54
55     if (_value == null) {
56       throw new IllegalStateException JavaDoc("Variable value not specified");
57     }
58
59     Scope scope = (Scope) st.getContext().getScopes().get(_scope);
60
61     if (scope == null) {
62       throw new IllegalArgumentException JavaDoc("Scope not found: " + _scope);
63     }
64
65     scope.putVal(_key, _value);
66   }
67 }
68
Popular Tags