KickJava   Java API By Example, From Geeks To Geeks.

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


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.Step;
7
8
9 /**
10  * @author Yanick Duchesne
11  *
12  * <dl>
13  * <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>
14  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
15  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
16  * </dl>
17  */

18 public class Push implements Step {
19   private String JavaDoc _from;
20   private String JavaDoc _key;
21
22   /**
23    * @see org.sapia.soto.state.Step#getName()
24    */

25   public String JavaDoc getName() {
26     return ClassUtils.getShortClassName(getClass());
27   }
28
29   public void setFrom(String JavaDoc from) {
30     _from = from;
31   }
32
33   public void setKey(String JavaDoc key) {
34     _key = key;
35   }
36
37   /**
38    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
39    */

40   public void execute(Result res) {
41     if (_key == null) {
42       throw new IllegalStateException JavaDoc("'key' not specified");
43     }
44
45     Object JavaDoc toExport;
46
47     if (_from != null) {
48       toExport = res.getContext().get(_key, _from);
49     } else {
50       toExport = res.getContext().get(_key);
51     }
52
53     if (toExport != null) {
54       res.getContext().push(toExport);
55     }
56   }
57 }
58
Popular Tags