How to force EMF not to manipulate reference ids [message #1691906] |
Fri, 10 April 2015 12:15 |
Flavio Donze Messages: 211 Registered: July 2009 Location: Switzerland |
Senior Member |
|
|
Having the following code I'm loading a BPMN model.
// 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);
Saving the resource resource.save(null); manipulates the output and adds data.bpmn# to references:
<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>
Where it looks like this coming from the input stream:
<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>
Is there a way to force EMF not to manipulate the references?
Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
|
|
|
|
|
|
|
Re: How to force EMF not to manipulate reference ids [message #1691943 is a reply to message #1691935] |
Fri, 10 April 2015 16:16 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Flavio,
Comments below.
On 10/04/2015 3:53 PM, Flavio Donze wrote:
> Sorry the "resource.save(null);" was wrong I actually use an
> OutputStream.
>
> I created a small test case, the references are still manipulated but
> are not "data.bpmn#ID" anymore, now they are "#ID".
>
>
> // previously storing the database input stream to dataFile,
> file looks OK
> InputStream in = new FileInputStream(dataFile);
> ResourceSet resourceSet = new ResourceSetImpl();
> URI modelUri = URI.createFileURI("d:/temp/data.bpmn");
> Resource resource = resourceSet.createResource(modelUri,
> "org.eclipse.bpmn2.content-type.xml");
Which resource factory ends up creating which type of resource?
Presumably tou're expecting something registered by the BPMN2 project.
The factory should create the right type of resource with the right
options, but that's a BPMN2 question, so probably better to ask on their
forum.
> resource.load(in, null);
> in.close();
>
> OutputStream outputStream = new FileOutputStream(dataFile);
> resource.save(outputStream, null);
> outputStream.close();
> // now the file contains #ID as references
>
>
> Using URI modelUri = URI.createFileURI("data.bpmn"); will result in
> "data.bpmn#ID" again.
> The file "d:/temp/data.bpmn" does not exist.
>
> Is there maybe some save option or hook to handle this?
>
> Thanks for your help
> Flavio
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: How to force EMF not to manipulate reference ids [message #1692111 is a reply to message #1692109] |
Mon, 13 April 2015 14:02 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Flavio,
I would generally expect a #<id> to appear. But that depends on what
funky things the BPMN2 folks have in their specialized
XmlExtendedMetaData. Is there any reason you should not expect it to
appear as #<id>? In any case, the implementation of this will
determine which save style is used in
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(EObject,
boolean). Again, this is a question best asked on the BPMN2 folks.
On 13/04/2015 3:47 PM, Flavio Donze wrote:
> This is the factory class used by BPMN:
> org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl
>
> Here is how the resource is created:
> public Resource createResource(URI uri) {
> Bpmn2ResourceImpl result = new Bpmn2ResourceImpl(uri);
> ExtendedMetaData extendedMetadata = new XmlExtendedMetadata();
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
> extendedMetadata);
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
> extendedMetadata);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE_TYPE_INFORMATION,
> new OnlyContainmentTypeInfo());
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
> Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ELEMENT_HANDLER,
> new ElementHandlerImpl(true));
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
>
> return result;
> }
>
>
> Can any of those options cause this?
>
> greets
> Flavio
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to force EMF not to manipulate reference ids [message #1692549 is a reply to message #1692111] |
Thu, 16 April 2015 12:38 |
Flavio Donze Messages: 211 Registered: July 2009 Location: Switzerland |
Senior Member |
|
|
For the record, this is how I solved it:
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);
greets
Flavio
Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
[Updated on: Thu, 16 April 2015 13:24] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04070 seconds