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 ; 12 13 14 22 public class CallStep implements Step { 23 private String _targetState; 24 private String _targetModule; 25 private String _returnState; 26 private String _returnModule; 27 private String _uri; 28 29 public CallStep() { 30 super(); 31 } 32 33 36 public String getName() { 37 return ClassUtils.getShortClassName(getClass()); 38 } 39 40 public void setUri(String uri) { 41 _uri = uri; 42 } 43 44 public void setTarget(String 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 returnState) { 52 StateIdParser.Created returnInfo = StateIdParser.parseStateFrom(returnState, 53 null); 54 _returnState = returnInfo.state; 55 _returnModule = returnInfo.module; 56 } 57 58 61 public void execute(Result res) { 62 CocoonContext ctx = (CocoonContext) res.getContext(); 63 64 if (_targetState == null) { 65 throw new IllegalArgumentException ("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 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 |