我正在尝试将 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 图附上了一张图片。