1 package org.sapia.soto.state.cocoon; 2 3 import org.apache.cocoon.environment.ObjectModelHelper; 4 import org.apache.cocoon.environment.Request; 5 import org.apache.cocoon.environment.Session; 6 7 import org.sapia.soto.Env; 8 import org.sapia.soto.EnvAware; 9 import org.sapia.soto.Service; 10 import org.sapia.soto.state.StateMachineService; 11 12 import org.sapia.util.xml.confix.ObjectHandlerIF; 13 14 import org.xml.sax.ContentHandler ; 15 16 import java.util.Map ; 17 import java.util.Stack ; 18 19 20 28 public class CocoonStateMachineService extends StateMachineService 29 implements Service, EnvAware, ObjectHandlerIF, Consts { 30 private Env _env; 31 32 35 public void setEnv(Env env) { 36 _env = env; 37 } 38 39 42 public void start() throws Exception { 43 } 44 45 public void execute(String state, String module, Map objectModel, 46 ContentHandler handler) throws Exception { 47 CocoonContext ctx = new CocoonContext(_env, handler, objectModel); 48 Request req = (Request) objectModel.get(ObjectModelHelper.REQUEST_OBJECT); 49 Session sess; 50 51 if (req.getParameter(CONTINUATION_KEY) != null) { 52 sess = req.getSession(); 53 54 Stack callStack; 55 56 if ((sess != null) && 57 ((callStack = (Stack ) sess.getAttribute(CONTINUATION_KEY)) != null)) { 58 if (callStack.size() > 0) { 59 Call c = (Call) callStack.peek(); 60 61 try { 62 if (c.isExecuted()) { 63 ctx.setStack(c.getContextStack()); 64 super.execute(c.getReturnState(), c.getReturnModule(), ctx); 65 callStack.pop(); 66 } else { 67 ctx.setStack(c.getContextStack()); 68 super.execute(c.getTargetState(), c.getTargetModule(), ctx); 69 c.setExecuted(); 70 } 71 } finally { 72 sess.setAttribute(CONTINUATION_KEY, callStack); 73 } 74 } else { 75 super.execute(state, module, ctx); 76 } 77 } 78 } else if ((sess = req.getSession(false)) != null) { 79 Stack callStack; 80 81 if (((callStack = (Stack ) sess.getAttribute(CONTINUATION_KEY)) != null) && 82 (callStack.size() > 0)) { 83 Call c = (Call) callStack.pop(); 84 85 try { 86 super.execute(c.getReturnState(), c.getReturnModule(), ctx); 87 } finally { 88 sess.setAttribute(CONTINUATION_KEY, callStack); 89 } 90 } else { 91 super.execute(state, module, ctx); 92 } 93 } else { 94 super.execute(state, module, ctx); 95 } 96 } 97 } 98 | Popular Tags |