0

我正在使用来自 JBoss Workflow 引擎的流程定义语言 jPDL:jBPM。

我想集成一个非常简单的流程定义图:基本上,我有一个主要流程定义(simple/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 ),其中包含:

  • 一个起始节点,
  • 一个状态节点,
  • 一个结束节点。

这是图形的定义:

<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"));
    }
}

最终,这是我开始整个过程​​的Main 类:

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)

谁能给我关于如何管理子流程定义和使用的建议?

4

1 回答 1

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>
    

...而且效果很好!

于 2010-07-07T10:24:59.610 回答