提问人:Mahdi 提问时间:11/10/2023 更新时间:11/10/2023 访问量:13
如何在Eclipse中使用BPMN2 Modeler插件修改和保存BPMN模型?
How to modify and save a BPMN model using BPMN2 Modeler plugin in Eclipse?
问:
我想对 BPMN 模型进行更改,并将修改后的模型另存为新模型。我有下面的代码作为演示,它试图删除模型的最后一个元素,但似乎它没有正确完成。打开修改后的模型时,图表信息似乎消失了。我还收到有关序列流未解析引用的错误。我很感激你在这方面的帮助?
private static void removeLastNode() {
String modelPath = "process_2.bpmn";
URI uri = URI.createURI(modelPath);
Bpmn2ResourceFactoryImpl resFactory = new Bpmn2ResourceFactoryImpl();
Resource resource = resFactory.createResource(uri);
HashMap<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
try {
// Load the resource
resource.load(options);
}
catch(Exception e){
}
// This is the root element of the XML document
Definitions d = (Definitions) resource.getContents().get(0).eContents().get(0);
//if more than 1 node in the process, then extract and remove the last node
for(RootElement re: d.getRootElements()) {
if(re instanceof Process) {
Process p = (Process)re;
FlowElement node_toRemove = null;
List<SequenceFlow> seqflowList_toRemove = new ArrayList();
for(FlowElement fe: p.getFlowElements()) {
if(fe instanceof FlowNode) {
FlowNode fn = (FlowNode)fe;
if(fn.getOutgoing().size()==0) {//no outgoing node
node_toRemove = fe;
//get the list of the incoming sequence flows of the element
for(SequenceFlow sf: fn.getIncoming()) {
seqflowList_toRemove.add(sf);
}
break;
}
}
}
//remove node and its seq flows
for(SequenceFlow sf: seqflowList_toRemove) {
p.getFlowElements().remove(sf);
}
p.getFlowElements().remove(node_toRemove);
}
}
String newFileName = "newModel" + ".bpmn";
try {
File f = new File(newFileName);
URI new_uri = URI.createURI(f.getPath());
resource.setURI(new_uri);
resource.save(options);
System.out.println("model " + newFileName + " saved!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答: 暂无答案
评论