jbpm知识点——ProcessState2

通常,当一个子流程被启动,在离开开始状态的信号被发出之前,所有拥有“read”存取属性的变量都被从超流程载入新创建的子流程;当子流程结束时,所有拥有“write”存取属性的变量都被从子流程拷贝到超流程。variabled元素的mapped-name属性允许你指定在子流程中将使用的变量名称。
相对于上例改动如下
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="" name="yytest">
 <start-state name='yyteststart' >
    <transition  name='done' to="initial_subyytest" />
 </start-state>
 <process-state name="initial_subyytest">
    <sub-process name="subyytest" />
    <variable name="a" access="read,write" mapped-name="aa" />
    <variable name="b" access="read" mapped-name="bb" />
    <transition  name='done' to="yytestend" />
 </process-state>
 <end-state name="yytestend" />
</process-definition>

---------------------------------------
private static void run(){
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  try {
   long processInstanceId =1;
   processInstance = jbpmContext.loadProcessInstance(processInstanceId);
   ContextInstance contextInstance = processInstance.getContextInstance();
      contextInstance.setVariable("a", "1");
      contextInstance.setVariable("b", "1");
      System.out.println("主流程变量a:"+contextInstance.getVariable("a"));
   System.out.println("主流程变量b:"+contextInstance.getVariable("b"));
   Token token = processInstance.getRootToken();
   System.out.println(token.getNode());
   token.signal();
   ProcessInstance subprocessInstance=token.getSubProcessInstance();
   /*取得subprocessInstance方法二
    long processInstanceId = processInstance.getId();
       long subProcessInstanceId = processInstance.getRootToken().getSubProcessInstance().getId();
       processInstance = jbpmContext.loadProcessInstance(processInstanceId);
       ProcessInstance subprocessInstance = jbpmContext.loadProcessInstance(subProcessInstanceId);
    */
   contextInstance = subprocessInstance.getContextInstance();
   System.out.println("子流程变量aa:"+contextInstance.getVariable("aa"));
   System.out.println("子流程变量bb:"+contextInstance.getVariable("bb"));
   contextInstance.setVariable("aa", "2");
      contextInstance.setVariable("bb", "2");
   Token subtoken = subprocessInstance.getRootToken();
   System.out.println(token.getNode());
   System.out.println(subtoken.getNode());
   subtoken.signal();
   contextInstance = processInstance.getContextInstance();
   System.out.println("主流程变量a:"+contextInstance.getVariable("a"));
   System.out.println("主流程变量b:"+contextInstance.getVariable("b"));
   System.out.println(subtoken.getNode());
   System.out.println(token.getNode());
   jbpmContext.save(processInstance);
   }finally {
     jbpmContext.close();
   }
 } 
------------------------------
运行结果:

主流程变量a:1
主流程变量b:1
StartState(yyteststart)
子流程变量aa:1
子流程变量bb:1
ProcessState(initial_subyytest)
State(subyyteststate1)
主流程变量a:2
主流程变量b:1
EndState(subyytestend)
EndState(yytestend)
 



你可能感兴趣的:(xml,jbpm,Access)