Decision决定状态。Decision和Node一样,都是即时状态,而不是等待状态。Decision的多个离开转向transition中可以设置条件。业务程序实例执行到Decision状态时,会依次计算所有的离开转向的条件,遇到条件为真的转向时,就会立即执行这个转向。如果没有为转向设置条件,那么这个转向的条件值就是true。Decision是功能最强大的即时状态。
processdefinition.xml
<?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 "升学";
}
}
测试(JUnit4)
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());
}
}
文章出处:DIY部落(http://www.diybl.com/course/3_program/java/javajs/2007927/74805.html)
分享到:
相关推荐
jbpm-eclipse插件,这个插件随jbpm4.4 一起发布,位于 jbpm-4.4/install/src/gpd 目录下,由于许多人找不到这个包,所有传上来,赚点积分。
jbpm-4.4\jbpm-4.4\doc\javadocsjbpm-4.4\jbpm-4.4\doc\javadocsjbpm-4.4\jbpm-4.4\doc\javadocs
jeecg-jbpm-framework 20130202.zipjeecg-jbpm-framework 20130202.zipjeecg-jbpm-framework 20130202.zipjeecg-jbpm-framework 20130202.zipjeecg-jbpm-framework 20130202.zipjeecg-jbpm-framework 20130202....
jbpm-4.4.zip
jbpm-jpdl-suite-3.2GA -(5)分开压缩(共5个文件)jbpm下载 jbpm-jpdl-suite-3.2GA -(5)分开压缩(共5个文件)jbpm下载
jbpm-jpdl-designer-site-3.1.7.zip jbpm-jpdl-designer-site-3.1.7.zip jbpm-jpdl-designer-site-3.1.7.zip
jbpm-starters-kit-3.1.2插件,jbpm-starters-kit-3.1.2插件,jbpm-starters-kit-3.1.2插件,jbpm-starters-kit-3.1.2插件,jbpm-starters-kit-3.1.2插件,jbpm-starters-kit-3.1.2插件,共两卷
jbpm-flow-builder-5.1.0.Final.jar jbpm5
jbpm-jpdl-suite-3.2.GA.zip
jbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3.zipjbpm-jpdl-suite-3.2.3....
eclipse 下安装jbpm-4.4 的安装步骤
jbpm-6.1.0.Final-installer
jbpm-jpdl.jar jbpm-jpdl.jar
这个是jbpm-jpdl-3.2.3.zip的server部分,有60多兆, 只要将"jbpm-jpdl-3.2.3(没有server部分).rar"和这个合在一起就是整个的jbpm-jpdl-3.2.3.zip "jbpm-jpdl-3.2.3(没有server部分).rar"在我的另外一个上传资源里面
jbpm-identity.jar jbpm-identity.jar
jbpm-jpdl-suite-3.2.GA.zip
jbpm-jpdl-designer资源
jbpm-jpdl-suite-3.2.GA.zip
jbpm-flow-5.1.0.Final.jar jbpm5