KickJava   Java API By Example, From Geeks To Geeks.

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


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 Export implements Step {
20   private String JavaDoc _from;
21   private String JavaDoc _to;
22   private String JavaDoc _key;
23   private String JavaDoc _expKey;
24
25   /**
26    * @see org.sapia.soto.state.Step#getName()
27    */

28   public String JavaDoc getName() {
29     return ClassUtils.getShortClassName(getClass());
30   }
31
32   public void setFrom(String JavaDoc from) {
33     _from = from;
34   }
35
36   public void setTo(String JavaDoc to) {
37     _to = to;
38   }
39
40   public void setKey(String JavaDoc key) {
41     _key = key;
42   }
43
44   public void setExportKey(String JavaDoc expKey) {
45     _expKey = expKey;
46   }
47
48   /**
49    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
50    */

51   public void execute(Result st) {
52     if (_from == null) {
53       throw new IllegalStateException JavaDoc("'from' not specified");
54     }
55
56     if (_to == null) {
57       throw new IllegalStateException JavaDoc("'to' not specified");
58     }
59
60     if (_key == null) {
61       throw new IllegalStateException JavaDoc("'key' not specified");
62     }
63
64     Object JavaDoc toExport = st.getContext().get(_key, _from);
65
66     if (toExport != null) {
67       Scope scope = (Scope) st.getContext().getScopes().get(_to);
68
69       if (scope != null) {
70         if (_expKey == null) {
71           scope.putVal(_key, toExport);
72         } else {
73           scope.putVal(_expKey, toExport);
74         }
75       }
76     }
77   }
78 }
79
Popular Tags