拥有以下代码我正在加载BPMN模型。
// dummy URI, loading done through input stream
URI uri = URI.createURI("data.bpmn");
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(uri, "org.eclipse.bpmn2.content-type.xml");
resource.load(contentStream, null);
保存资源resource.save(outputStream, null);
操纵输出并将data.bpmn#
添加到引用:
<bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="data.bpmn#StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="162.0" y="182.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_1" labelStyle="data.bpmn#BPMNLabelStyle_1">
<dc:Bounds height="15.0" width="68.0" x="146.0" y="218.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
这看起来像来自输入流:
<bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="162.0" y="182.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_1" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="15.0" width="68.0" x="146.0" y="218.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
有没有办法强制EMF不操纵引用?
答案 0 :(得分:0)
改变这个:
URI uri = URI.createURI("data.bpmn");
到
URI.createPlatformResourceURI("/full/workspace/path/data.bpmn");
你必须使用ResourceSet的/ global包注册表将data.bpmn中的任何包定义注册到EPackage ...
如果你从Stream,XML等加载data.bpmn ......
Resource接口包含save()和load()方法的第二个版本,其中包含一个stream参数:
void save(OutputStream输出流, 映射选项)抛出IOException; void load(InputStream inputStream,Map options)抛出IOException; 您可能认为这意味着EMF资源本质上是“基于流的”。尽管EMF使用的大多数资源都倾向于基于流,包括EMF提供的XML资源,但也可以实现非基于流的(例如,关系数据库)资源....
答案 1 :(得分:0)
这就是我解决它的方法:
ResourceSet resourceSet = new ResourceSetImpl();
XMLResource resource = (XMLResource) resourceSet.createResource(modelUri, "org.eclipse.bpmn2.content-type.xml");
XMLResource.URIHandler uriHandler = new URIHandlerImpl() {
@Override
public URI deresolve(URI uri) {
// make sure references are stored without # URI prefix
return URI.createURI(uri.fragment());
}
};
resource.getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER, uriHandler);
resource.load(inputStream, null);