gpt4 book ai didi

java - 如何使用java在jbpm项目的processdefinition.xml中添加转换?

转载 作者:太空宇宙 更新时间:2023-11-04 13:40:02 27 4
gpt4 key购买 nike

我的问题是我有一个 processdefintion.xml,其中有 5 个节点,但没有明确定义转换。

我想使用 java 代码添加转换。

我正在尝试使用以下代码。帮我看看这是否正确?

    ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("processdefinition.xml");
ProcessInstance instance = new ProcessInstance(processDefinition);
Node endState = processDefinition.findNode("end");
System.out.println("End State using findNode= "+endState);
Transition t2 = new Transition();
t2.setName("start to new State");
t2.setFrom(n);
t2.setTo(endState);
State newState = new State();
newState.setName("New State");
newState.addArrivingTransition(t2);
Node n2 = instance.getRootToken().getNode();
n2.addLeavingTransition(t2);

我想知道我的做法是否正确。以及如何更新更改,以便将其反射(reflect)回 processdefintion.xml 文件。

最佳答案

以编程方式在流程定义中添加转换

    //1
StartState startState = new StartState();
startState.setName("start");
System.out.println("Start State is = "+startState);
//2
Node firstNode = new Node();
firstNode.setName("firstNode");
System.out.println("First Node is = "+firstNode);
//3
State firstState = new State();
firstState.setName("firstState");
System.out.println("First State is = "+ firstState);
//4
Node secondNode = new Node();
secondNode.setName("secondNode");
System.out.println("Second Node is = "+secondNode);
//5
EndState endState = new EndState();
endState.setName("end");
System.out.println("End State is = "+endState);
// Transition from 1st to 2nd
Transition t1 = new Transition();
t1.setName("to_firstNode");
t1.setFrom(startState);
t1.setTo(firstNode);
System.out.println("Transition t1 = "+t1.toString());
// Transition from 2nd to 3rd
Transition t2 = new Transition();
t2.setName("to_firstState");
t2.setFrom(firstNode);
t2.setTo(firstState);
System.out.println("Transition t2 = "+t2.toString());
// Transition from 3rd to 4th
Transition t3 = new Transition();
t3.setName("to_secondNode");
t3.setFrom(firstState);
t3.setTo(secondNode);
System.out.println("Transition t3 = "+t3.toString());
// Transition from 4th to 5th
Transition t4 = new Transition();
t4.setName("to_end");
t4.setFrom(secondNode);
t4.setTo(endState);
System.out.println("Transition t4 = "+t4.toString());
// Create New Process Definition
ProcessDefinition newProcessDefinition = new ProcessDefinition();

// Set Name for Process Definition
newProcessDefinition.setName("CoolProcess");

// Adding Nodes to Process Definition
newProcessDefinition.setStartState(startState);
newProcessDefinition.addNode(firstNode);
newProcessDefinition.addNode(firstState);
newProcessDefinition.addNode(secondNode);
newProcessDefinition.addNode(endState);

// Adding Transitions to Process Definition
firstNode.addArrivingTransition(t1);
firstNode.addLeavingTransition(t2);
firstState.addArrivingTransition(t2);
firstState.addLeavingTransition(t3);
secondNode.addArrivingTransition(t3);
secondNode.addLeavingTransition(t4);
endState.addArrivingTransition(t4);

JbpmContext jbpmContext = jbpmconfig.createJbpmContext();

//Deploy the Created Process Definition to Database
jbpmContext.deployProcessDefinition(newProcessDefinition);

关于java - 如何使用java在jbpm项目的processdefinition.xml中添加转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com