主流程中包含子流程

一、主流程
<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="sumProcessNode">


<start-state name="start-state1">
<transition to="task-node1"></transition>
</start-state>


<process-state name="process-state1">
   <sub-process name="slaveNode"/>
<variable access="read" name="masterV"></variable>
<variable access="write" name="slaveV"></variable>
<transition to="task-node2"></transition>
</process-state>

<task-node name="task-node1">
<task name="masterTask1111">
<description>
11111111111111111
</description>
<assignment actor-id="masterTask1-id"></assignment>
</task>
<transition to="process-state1"></transition>
</task-node>

<task-node name="task-node2">
<task name="masterTask2222">
<description>
2222222222
</description>
<assignment actor-id="masterTask2-id"></assignment>
</task>
<transition to="end-state1"></transition>
</task-node>


<end-state name="end-state1"></end-state>


</process-definition>
*********************************************************************
二、子流程

<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="slaveNode">


<start-state name="start-state1">
<transition to="task-node1"></transition>
</start-state>


<task-node name="task-node1">
<task name="sub task">
<description>
00000000000000
</description>
<assignment actor-id="slave-id"></assignment>
</task>
<transition to="end-state1"></transition>
</task-node>


<end-state name="end-state1"></end-state>


</process-definition>
三、测试
******************************
package cn.oa.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;

public class MasterSubNodeTest {

/**
* @param args
*/
public static void main(String[] args) {
JbpmContext jbpmContext=JbpmConfiguration.getInstance().createJbpmContext();
try {
ProcessInstance pi=jbpmContext.newProcessInstance("sumProcessNode");
pi.getContextInstance().setVariable("masterV", "masterV的值");
Token token=pi.getRootToken();
token.signal();
System.out.println("****"+token.getNode().getName());
} finally {
jbpmContext.close();
}

}

}
****************
package cn.oa.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;

public class MasterSubNodeTest2 {

/**
* @param args
*/
public static void main(String[] args) {
JbpmContext jbpmContext=JbpmConfiguration.getInstance().createJbpmContext();
try {
//取得主流程的任务实例
TaskInstance pi=jbpmContext.loadTaskInstance(16);
pi.getContextInstance().setVariable("masterV", "masterV的值");
/**
* 该任务实例结束,这样就有子流程产生,同时子流程会运行到子流程上的task-node1节点,产生一个子流程对应的任务实例
*
*/
pi.end();
} finally {
jbpmContext.close();
}

}

}
***********************

package cn.oa.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;

public class MasterSubNodeTest3 {

/**
* @param args
*/
public static void main(String[] args) {
JbpmContext jbpmContext=JbpmConfiguration.getInstance().createJbpmContext();
try {
//取得子流程的任务实例
TaskInstance pi=jbpmContext.loadTaskInstance(17);
ContextInstance ci=pi.getContextInstance();
//取出从主流程中 传过来的变量masterV
System.out.println("从主流程中 传过来的变量masterV:"+ci.getVariable("masterV"));
//向子流程中写入slaveV
ci.setVariable("slaveV", "子流程的变量slaveV");
/**
* 该任务实例结束,这样子流程就结束,进入主流程,主流程向下路由到主流程中的task-node2节点,产生新的任务实例
*
*/
pi.end();
} finally {
jbpmContext.close();
}

}

}
*****************************
package cn.oa.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;

public class MasterSubNodeTest4 {

/**
* @param args
*/
public static void main(String[] args) {
JbpmContext jbpmContext=JbpmConfiguration.getInstance().createJbpmContext();
try {
//取得主流程的任务实例
TaskInstance pi=jbpmContext.loadTaskInstance(18);
ContextInstance ci=pi.getContextInstance();
//取出从子流程中 传过来的变量masterV
System.out.println("从子流程中 传回来的变量slaveV:"+ci.getVariable("slaveV"));
//该任务实例结束,这样整个流程就结束
pi.end();
} finally {
jbpmContext.close();
}

}

}

你可能感兴趣的:(流程)