Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to force EMF not to manipulate reference ids
How to force EMF not to manipulate reference ids [message #1691906] Fri, 10 April 2015 12:15 Go to next message
Flavio Donze is currently offline Flavio DonzeFriend
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 #1691908 is a reply to message #1691906] Fri, 10 April 2015 12:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Flavio,

Don't use a relative URI to load resources. Use an absolute URI. Where
are you expecting "data.bpmn" to actually exist? If it's in the
workspace, use a URI.createPlatformResourceURI with the full path in the
workspace. If it's in the file system, use File.getAbsolutePath() and
then use URI.createFileURI from that result.

On 10/04/2015 2:16 PM, Flavio Donze wrote:
> 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?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to force EMF not to manipulate reference ids [message #1691912 is a reply to message #1691908] Fri, 10 April 2015 12:38 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
Hi Ed,

Thanks for your very fast reply!

Actually I don't want to use an URI at all, since the model is loaded from the input stream (source is a database).
Is there a way to do that?
If not, creating a dummy temp file and using this as URI would solve the issue?

greets
Flavio


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: How to force EMF not to manipulate reference ids [message #1691913 is a reply to message #1691912] Fri, 10 April 2015 12:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Flavio,

Then use a fake absolute URI, dummy:/whatever. Presumably you do a save
passing in an output stream, not as you've shown in your sample code...


On 10/04/2015 2:38 PM, Flavio Donze wrote:
> Hi Ed,
> Thanks for your very fast reply!
>
> Actually I don't want to use an URI at all, since the model is loaded
> from the input stream (source is a database). Is there a way to do that?
> If not, creating a dummy temp file and using this as URI would solve
> the issue?
>
> greets
> Flavio
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to force EMF not to manipulate reference ids [message #1691935 is a reply to message #1691913] Fri, 10 April 2015 13:53 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
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");
		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


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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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 #1692109 is a reply to message #1691943] Mon, 13 April 2015 13:47 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
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


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: How to force EMF not to manipulate reference ids [message #1692111 is a reply to message #1692109] Mon, 13 April 2015 14:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
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

icon14.gif  Re: How to force EMF not to manipulate reference ids [message #1695415 is a reply to message #1692549] Thu, 14 May 2015 11:07 Go to previous message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Smile thanks same problem and proposed solution work out for me as well. Many thanks.

BR,
Bhuvan
Previous Topic:[xcore] No difference with annotation use
Next Topic:XMI instance with HREFs only
Goto Forum:
  


Current Time: Tue Apr 23 13:18:24 GMT 2024

Powered by FUDForum. Page generated in 0.03468 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top