jbpm知识点——ProcessState

用来定义子流程,当主流程遇到ProcessState就会停滞并生成子流程运行,子流程运行完毕重新回到主流程运行。主子流程的部署有点特殊(耗费了我3个小时才搞定,我开始认为只要在processdefinition.xml中定义好2个流程的关系,然后分别发布就好了,但是不行,一定要程序设置好两者的关系再发布)

主流程xml:
<?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>
--------------------------------------------------

子流程xml:
<?xml version="1.0" encoding="UTF-8"?>
<process-definition
  xmlns=""  name="subyytest">
   <start-state name="subyyteststart">
      <transition name="" to="subyyteststate1"></transition>
   </start-state>
   <state name="subyyteststate1">
      <transition name="" to="subyytestend"></transition>
   </state>
   <end-state name="subyytestend"></end-state>
</process-definition>

 -----------------------------------------------------

部署以及过程生成:
private static void Deploying_processstate(){
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  try {
   InputStream is = new FileInputStream("processes/yytest/processdefinition.xml");
   processDefinition = ProcessDefinition.parseXmlInputStream(is);
   InputStream subis = new FileInputStream("processes/subyytest/processdefinition.xml");
   ProcessDefinition subprocessDefinition = ProcessDefinition.parseXmlInputStream(subis);
   //建立关联关系
   ProcessState processState = (ProcessState) processDefinition.getNode("initial_subyytest");
   processState.setSubProcessDefinition(subprocessDefinition);
   //一定要先部署子流程,不然hibernate会报错。
   jbpmContext.deployProcessDefinition(subprocessDefinition);
   jbpmContext.deployProcessDefinition(processDefinition);
  } catch(FileNotFoundException e){
   e.printStackTrace();
  }finally {
    jbpmContext.close();
  }
 }
private static void Starting_process(){
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  try {
   String processName="yytest";
   processInstance =jbpmContext.newProcessInstance(processName);//只生成主流程就好了
   }finally {
     jbpmContext.close();
   }
 }

---------------------------------------------------

private static void run(){
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
  try {
   long processInstanceId =1;
   processInstance = jbpmContext.loadProcessInstance(processInstanceId);
   Token token = processInstance.getRootToken();
   System.out.println(token.getNode());
   token.signal();
   ProcessInstance subprocessInstance=token.getSubProcessInstance();
   Token subtoken = subprocessInstance.getRootToken();
   System.out.println(token.getNode());
   System.out.println(subtoken.getNode());
   subtoken.signal();
   System.out.println(subtoken.getNode());
   System.out.println(token.getNode());
   jbpmContext.save(processInstance);
   }finally {
     jbpmContext.close();
   }
 }

-----------------------------------------------------

运行结果:
StartState(yyteststart)
ProcessState(initial_subyytest)
State(subyyteststate1)
EndState(subyytestend)
EndState(yytestend)


补充:
自循环的流程:
<process-definition name="recursive process">
 <start-state>
  <transition to="first wait"/>
 </start-state>
 <state name="first wait">
  <transition to="subprocessnode"/>
  <transition name="done" to="end"/>
 </state>
 <process-state name="subprocessnode">
  <sub-process name="recursive process"/>
  <transition to="end"/>
 </process-state>
 <end-state name="end"/>
</process-definition>
-----------------------------------------------------
关联指定version的子流程
<process-definition>
 <process-state name="the sub process state">
  <sub-process name="the ultimate subprocess" version="1"/>
 </process-state>
</process-definition> 



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