KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > cocoon > CallStep


1 package org.sapia.soto.state.cocoon;
2
3 import org.apache.commons.lang.ClassUtils;
4
5 import org.sapia.soto.state.Result;
6 import org.sapia.soto.state.Step;
7 import org.sapia.soto.state.util.StateIdParser;
8
9 import org.sapia.ubik.net.UriSyntaxException;
10
11 import java.io.IOException JavaDoc;
12
13
14 /**
15  * @author Yanick Duchesne
16  * <dl>
17  * <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>
18  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
19  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
20  * </dl>
21  */

22 public class CallStep implements Step {
23   private String JavaDoc _targetState;
24   private String JavaDoc _targetModule;
25   private String JavaDoc _returnState;
26   private String JavaDoc _returnModule;
27   private String JavaDoc _uri;
28
29   public CallStep() {
30     super();
31   }
32
33   /**
34    * @see org.sapia.soto.state.Step#getName()
35    */

36   public String JavaDoc getName() {
37     return ClassUtils.getShortClassName(getClass());
38   }
39
40   public void setUri(String JavaDoc uri) {
41     _uri = uri;
42   }
43
44   public void setTarget(String JavaDoc targetState) {
45     StateIdParser.Created targetInfo = StateIdParser.parseStateFrom(targetState,
46         null);
47     _targetState = targetInfo.state;
48     _targetModule = targetInfo.module;
49   }
50
51   public void setReturn(String JavaDoc returnState) {
52     StateIdParser.Created returnInfo = StateIdParser.parseStateFrom(returnState,
53         null);
54     _returnState = returnInfo.state;
55     _returnModule = returnInfo.module;
56   }
57
58   /**
59    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
60    */

61   public void execute(Result res) {
62     CocoonContext ctx = (CocoonContext) res.getContext();
63
64     if (_targetState == null) {
65       throw new IllegalArgumentException JavaDoc("Target state not defined");
66     }
67
68     try {
69       ctx.executeCall(_uri, _targetState, _targetModule,
70         (_returnState == null) ? res.getCurrentStateId() : _returnState,
71         _returnModule);
72     } catch (IOException JavaDoc e) {
73       res.error("Could not perform call", e);
74     } catch (UriSyntaxException e) {
75       res.error("Could not perform call; invalid uri", e);
76     }
77   }
78 }
79
Popular Tags