[jboss-user] [JBoss jBPM] - Re: Do we really need
deepuin9
do-not-reply at jboss.com
Thu Mar 6 14:00:38 EST 2008
Hi bungrudi ,
I was trying to do something similar to what you are talking about. My idea is to have a node using which I should be able to define the transitions at runtime.
Have a look at the sample process definition below, if you observe state 3 does not have any transition.
<?xml version="1.0" encoding="UTF-8"?>
| <process-definition xmlns="" name="statetrans">
| <start-state name="start-state1">
| <transition to="state1"></transition>
| </start-state>
|
| <state name="state1">
| <transition to="state2"></transition>
| </state>
|
| <state name="state2">
| <transition to="end-state1"></transition>
| <transition to="state1" name="to state1"></transition>
| </state>
|
| <state name="state3"></state>
|
| <end-state name="end-state1"></end-state>
| </process-definition>
In the below test case, I tried to added the transition at runtime and it worked :) . Now I am in the process of building my custom node :)
public void testAddingTransitionsToState3AtRuntime() {
| Node node3 = processDefinition.getNode("state3");
| Node node2 = processDefinition.getNode("state2");
| Node end = processDefinition.getNode("end-state1");
|
|
| Token token = processInstance.getRootToken();
| assertEquals("start-state1", token.getNode().getName());
|
| processInstance.signal();
| assertEquals("state1", token.getNode().getName());
|
| //Ideally I would like to add new transition from state1 to state3
| Transition trans = processInstance.getRootToken().getNode()
| .getDefaultLeavingTransition();
| Node to = trans.getTo();
| Node from = trans.getFrom();
| System.out.println("from " + from.getName() + " to " + to.getName());
|
| trans.setTo(node3);
| processInstance.signal();
| assertEquals("state3", token.getNode().getName());
| //As state 3 does not have any transition defined it will return null
| Transition leavingTransitionState3 = processInstance.getRootToken().getNode()
| .getDefaultLeavingTransition();
| //Creating new transition.
| leavingTransitionState3 = new Transition("test");
| leavingTransitionState3.setTo(node2);
| leavingTransitionState3.setFrom(node3);
| processInstance.getRootToken().getNode().addLeavingTransition(leavingTransitionState3);
| System.out.println("from " + leavingTransitionState3.getFrom().getName() + " to " + leavingTransitionState3.getTo().getName());
|
| processInstance.signal();
| assertEquals("state2", token.getNode().getName());
| processInstance.signal();
| assertEquals("end-state1", token.getNode().getName());
| }
| [/url]
Hope it helped.
Thanks
Sandeep
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4134653#4134653
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4134653
More information about the jboss-user
mailing list