2010-07-05 56 views
0

我使用來自JBoss工作流引擎的流程定義語言jPDL:jBPM。在JBPM中集成子流程定義JPDL

欲一個非常簡單的過程定義圖表整合:基本上,予有一個主流程定義(簡單/ processdefinition.xml中),包括:

  • 一個開始節點,
  • 一個進程狀態節點,
  • 一個結束節點。

這裏是圖的定義:含有

<process-definition 
    xmlns="urn:jbpm.org:jpdl-3.2" 
    name="simple"> 
    <start-state name="start"> 
     <transition name="to_state" to="process-state"> 
     <action name="action" class="com.sample.action.MessageActionHandler"> 
      <message> 
        Going to the sub-state! 
       </message> 
     </action> 
     </transition> 
     <event type="node-leave"> 
      <action class="com.sample.action.MessageActionHandler"> 
       <message> 
        Start. 
       </message> 
      </action> 
     </event> 
    </start-state> 
    <process-state name="process-state"> 
     <sub-process name="subsimple" binding="late"/> 
     <variable access="read,write" name="message" mapped-name="message">  </variable> 
     <event type="node-enter"> 
      <action class="com.sample.action.MessageActionHandler"></action> 
     </event> 
     <transition to="end" name="to_end"></transition> 
    </process-state> 
    <end-state name="end"> 
     <event type="node-enter"> 
      <action class="com.sample.action.MessageActionHandler"> 
       <message> 
        End. 
       </message> 
      </action> 
     </event> 
    </end-state> 
</process-definition> 

在我所限定的子過程圖形處理狀態節點(subsimple/processdefinition.xml中):

  • a開始節點,
  • 狀態節點,
  • 終端節點。

這裏是圖的定義:

<process-definition 
    xmlns="urn:jbpm.org:jpdl-3.2" 
    name="subsimple"> 
    <start-state name="start"> 
     <transition name="to_state" to="first"> 
     <action name="action" class="com.sample.action.MessageActionHandler"> 
      <message>Going to the first state!</message> 
     </action> 
     </transition> 
     <event type="node-leave"> 
      <action class="com.sample.action.MessageActionHandler"> 
       <message> 
        Start. 
       </message> 
      </action> 
     </event> 
    </start-state> 
    <state name="first"> 
     <event type="node-enter"> 
      <action class="com.sample.action.MessageActionHandler"> 
       <message> 
        In first state !! 
       </message> 
      </action> 
     </event> 
     <transition name="to_end" to="end"> 
     <action name="action" class="com.sample.action.MessageActionHandler"> 
      <message> 
        About to go out of sub-process ! 
       </message> 
     </action> 
     </transition> 
    </state> 
    <end-state name="end"> 
     <event type="node-enter"> 
      <action class="com.sample.action.MessageActionHandler"> 
       <message> 
        End. 
       </message> 
      </action> 
     </event> 
    </end-state> 
</process-definition> 

這裏是的ActionHandler分配給每一個事件和轉換:

public class MessageActionHandler implements ActionHandler { 

    private static final long serialVersionUID = 1L; 

    String message; 

    public void execute(ExecutionContext context) throws Exception { 
     context.getContextInstance().setVariable("message", message); 

     System.out.println(context.getContextInstance().getVariable("message")); 
    } 
} 

最終,這裏是主類從中我開始了整個過程:

public class testJBPM { 

public static void main(String[] args) { 

    ProcessDefinition processDefinition = ProcessDefinition 
      .parseXmlResource("simple/processdefinition.xml"); 

    // Create an instance of the process definition. 
    ProcessInstance instance = new ProcessInstance(processDefinition); 

    // Move the process instance from its start state to the first state. 
    instance.signal(); 

    // Move the process instance to the end state. 
    instance.signal(); 
} 
} 

正如我在JBoss論壇上看到的,我在主進程定義中正確設置了子進程綁定binding=late。然後我嘗試不同的方式來實例化的子進程的流程定義,但我總是試圖進入子狀態/子流程節點時出現以下異常:

Exception in thread "main" org.jbpm.JbpmException: can't create a process instance  when processDefinition is null 
    at org.jbpm.graph.exe.ProcessInstance.<init>(ProcessInstance.java:128) 
    at org.jbpm.graph.exe.ProcessInstance.<init>(ProcessInstance.java:92) 
    at org.jbpm.graph.exe.Token.createSubProcessInstance(Token.java:624) 
    at org.jbpm.graph.node.ProcessState.execute(ProcessState.java:164) 
    at org.jbpm.graph.def.Node.enter(Node.java:319) 
    at org.jbpm.graph.def.Transition.take(Transition.java:151) 
    at org.jbpm.graph.def.Node.leave(Node.java:394) 
    at org.jbpm.graph.node.StartState.leave(StartState.java:70) 
    at org.jbpm.graph.exe.Token.signal(Token.java:195) 
    at org.jbpm.graph.exe.Token.signal(Token.java:140) 
    at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:271) 
    at com.sample.main.testJBPM.main(testJBPM.java:21) 

任何人可以給我通知:如何管理子流程定義和使用?

回答

0

我最終找到了出路由我自己:

  • 首先,只有一個instance.signal();是必要的衝動整體main()處理蹤跡。

  • 然後,接口必須被實現爲允許jBPM的搜索和實例化所需的子過程:

    public class DbSubProcessResolver implements SubProcessResolver { 
        private static final long serialVersionUID = 1L; 
    
         public ProcessDefinition findSubProcess(Element subProcessElement) { 
    
          String name = subProcessElement.attributeValue("name").replaceAll(
           "\\.", ""); 
          ProcessDefinition subProcessDefinition = ProcessDefinition 
           .parseXmlResource(name + "/processdefinition.xml"); 
    
          return subProcessDefinition; 
         } 
    } 
    
  • 最終,jBPM配置文件必須被指定映射jBPM的框架分解器所實現的一個:

    <jbpm-configuration> 
        <bean name="jbpm.sub.process.resolver" class="com.sample.resolver.DbSubProcessResolver" /> 
    </jbpm-configuration> 
    

...它工作正常!