Decision决定状态。Decision和Node一样,都是即时状态,而不是等待状态。Decision的多个离开转向transition中可以设置条件。业务程序实例执行到Decision状态时,会依次计算所有的离开转向的条件,遇到条件为真的转向时,就会立即执行这个转向。如果没有为转向设置条件,那么这个转向的条件值就是true。Decision是功能最强大的即时状态。
<?xml version="1.0" encoding="UTF-8"?>

<process-definition
xmlns="urn:jbpm.org:jpdl-3.1" name="example_8">
<start-state name="考试">
<transition name="" to="评判"/>
</start-state>
<decision name="评判">
<handler class="com.wide.example8.JudgeDecisionHandler"/>
<transition name="升学" to="进大学深造"/>
<transition name="复习" to="复习备考"/>
<transition name="辍学" to="闯荡江湖"/>
</decision>
<state name="进大学深造">
<transition name="" to="End"/>
</state>
<state name="复习备考">
<transition name="" to="End"/>
</state>
<state name="闯荡江湖">
<transition name="" to="End"/>
</state>
<end-state name="End"></end-state>
</process-definition>
JudgeDecisionHandler.java
package com.wide.example8;

import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;


public class JudgeDecisionHandler implements DecisionHandler ...{


public String decide(ExecutionContext executionContext) throws Exception ...{
int score = (Integer)executionContext.getContextInstance().getVariable("score");
if(score < 30)
return "辍学";
else if(score < 60)
return "复习";
else
return "升学";
}

}
package com.sample;

import static org.junit.Assert.assertEquals;

import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.junit.Before;
import org.junit.Test;


public class Example8 ...{
private ProcessDefinition processDefinition = null;

@Before

public void init() ...{
processDefinition = ProcessDefinition
.parseXmlResource("example_8/processdefinition.xml");
}

@Test

public void process1() ...{
ProcessInstance processInstance = new ProcessInstance(processDefinition);

Token token = processInstance.getRootToken();
processInstance.getContextInstance().setVariable("score", 80);
token.signal();
assertEquals("进大学深造", token.getNode().getName());
token.signal();
assertEquals("End", token.getNode().getName());
}

@Test

public void process2() ...{
ProcessInstance processInstance = new ProcessInstance(processDefinition);

Token token = processInstance.getRootToken();
processInstance.getContextInstance().setVariable("score", 50);
token.signal();
assertEquals("复习备考", token.getNode().getName());
token.signal();
assertEquals("End", token.getNode().getName());
}

@Test

public void process3() ...{
ProcessInstance processInstance = new ProcessInstance(processDefinition);

Token token = processInstance.getRootToken();
processInstance.getContextInstance().setVariable("score", 10);
token.signal();
assertEquals("闯荡江湖", token.getNode().getName());
token.signal();
assertEquals("End", token.getNode().getName());
}
}
processdefinition.xml














































测试(JUnit4)



























































