我正在尝试将End或Terminate事件添加到BPMN图中的现有网关,因为另一个输出序列在运行时在Java中实用地流了下来。要实现此目标需要遵循哪些步骤? 我将这些示例作为参考。
BpmnModelInstance bpmn = execution.getBpmnModelInstance();
Collection<ExclusiveGateway> gateways = execution.getBpmnModelInstance().getModelElementsByType(ExclusiveGateway.class);
ExclusiveGateway gateway; // getting the instance of gateway from collection
SequenceFlow sequenceFlow = bpmn.newInstance(SequenceFlow.class);
sequenceFlow.setName("Sequence_flow_2");
ConditionExpression conditionExpression = bpmn.newInstance(ConditionExpression.class);
conditionExpression.setTextContent("${x == 2}");
sequenceFlow.setConditionExpression(conditionExpression);
CamundaExecutionListener executionListener = bpmn.newInstance(CamundaExecutionListener.class);
executionListener.setCamundaEvent("start");
executionListener.setCamundaDelegateExpression("Terminate");
EndEvent endEvent = bpmn.newInstance(EndEvent.class);
endEvent.setName("End error");
if (endEvent.getExtensionElements() == null) {
ExtensionElements extensionElements = bpmn.newInstance(ExtensionElements.class);
endEvent.addChildElement(extensionElements);
}
endEvent.getExtensionElements().addChildElement(executionListener);
if (sequenceFlow.getExtensionElements() == null) {
ExtensionElements extensionElements = bpmn.newInstance(ExtensionElements.class);
sequenceFlow.addChildElement(extensionElements);
}
sequenceFlow.getExtensionElements().addChildElement(endEvent);
if((gateway.getExtensionElements() == null) {
ExtensionElements extensionElements = bpmn.newInstance(ExtensionElements.class);
gateway.addChildElement(extensionElements);
}
gateway.getExtensionElements().addChildElement(sequenceFlow);
//sequenceFlow.setSource(gateway);
//sequenceFlow.setTarget(endEvent);
bpmn.setDocumentElement(sequenceFlow);
gateway.getOutgoing().add(sequenceFlow);
我为下面的bpmn图附加了一张图片。