Add token with external application
jeanc Mar 11, 2008 11:31 AMI have a process that automatically create nodes (node1). I want to add a new node1 with an external application. I try to call the execute method of the forkHandler but I can not get the executionContext.
I put all the code of the execute method in the external application, I can obtain the rootToken, but when I try this code the jpbCxt is always null
ExecutionContext executionContext = new ExecutionContext(rootToken);
JbpmContext jpbCxt = executionContext.getJbpmContext();
Is it possible to do this and how can I do this?
Thanks
<?xml version="1.0" encoding="UTF-8"?> <process-definition xmlns="" name="dynamic fork"> <start-state name="start"> <transition name="" to="fork"></transition> </start-state> <end-state name="end"></end-state> <node name="fork"> <action class="be.labocollard.server.kernel.handlers.ForkHandler"></action> <transition name="" to="node1"></transition> </node> <task-node name="task"> <task name="taskFork"> <assignment expression="user(abc)"></assignment> </task> <transition name="" to="join"></transition> </task-node> <join name="join"> <transition name="" to="end"></transition> </join> <node name="node1"> <transition name="" to="task"></transition> </node> </process-definition>
public class ForkHandler implements ActionHandler { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(ForkHandler.class); /** * */ private static final long serialVersionUID = 1L; /** * Create a new child token for each item in list. * * @param executionContext * @throws Exception */ public void execute(final ExecutionContext executionContext) throws Exception { logger.debug("execute(ExecutionContext executionContext=" + executionContext + ") - start"); List<? extends Object> forkList = null; forkList = initializeList(executionContext); final Token rootToken = executionContext.getToken(); final Node node = executionContext.getNode(); final List<Object[]> argSets = new LinkedList<Object[]>(); // // First, create a new token and execution context for each item in // list. // for (int i = 0; i < node.getLeavingTransitions().size(); i++) { final Transition transition = (Transition) node.getLeavingTransitions().get(i); for (Object object : forkList) { final Token newToken = new Token(rootToken, Cola.PREFIX + node.getId() + "." + ((OpCodeTime) object).getId()); newToken.setTerminationImplicit(true); JbpmContext jpbCxt = executionContext.getJbpmContext(); Session session = jpbCxt.getSession(); session.save(newToken); final ExecutionContext newExecutionContext = new ExecutionContext(newToken); newExecutionContext.setVariable(Cola.OPCODETIME, object); argSets.add(new Object[] { newExecutionContext, transition }); } } // // Now, let each new token leave the node. // for (int i = 0; i < argSets.size(); i++) { final Object[] args = argSets.get(i); node.leave((ExecutionContext) args[0], (Transition) args[1]); } logger.debug("execute(ExecutionContext) - end"); } // @SuppressWarnings("unchecked") protected List<? extends Object> initializeList(final ExecutionContext executionContext) { List<? extends Object> list = (List<? extends Object>) executionContext.getContextInstance().getVariable(Cola.FORKLIST); return list; } }