Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to add a semantic resource with relative path
How to add a semantic resource with relative path [message #1835174] Thu, 26 November 2020 10:45 Go to next message
Felix S is currently offline Felix SFriend
Messages: 10
Registered: November 2014
Junior Member
Hi all,

I want to create a representation file programmatically and add an xmi file, which is located in the same directory. But I'm not sure, how to get the right URI of the semantic resource.

I implemented a Wizard, where a new representation file (aird file) is created and an xmi file added as semantic resource. The semantic resource URI is a platform resource URI and points to the xmi in the same directory as the representation file.

Opening the representation file works fine and I can use the editor without any problems. But when I save the representation file, I see the following exception silently (i.e. only visible in the errror log, but no UI alert):
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Value 'model.xmi' is not legal. (file:///myProject/model/model.aird, 4, 53)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
	at org.eclipse.sirius.business.internal.resource.AirdResourceXMILoad.load(AirdResourceXMILoad.java:79)
	[...]
Caused by: org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'model.xmi' is not legal. (file:///myProject/model/model.aird, 4, 53)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2715)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2700)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.endElement(XMLHandler.java:1624)
	at org.eclipse.sirius.business.internal.resource.AirdResourceXMILoad$AirdHandler.endElement(AirdResourceXMILoad.java:107)
	[...]
Caused by: java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base
	at org.eclipse.emf.common.util.URI$Hierarchical.resolve(URI.java:3548)
	at org.eclipse.emf.common.util.URI.resolve(URI.java:5580)
	at org.eclipse.sirius.business.internal.resource.parser.RepresentationsFileXMIHelper.createFromString(RepresentationsFileXMIHelper.java:148)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1147)
	at org.eclipse.sirius.business.internal.resource.parser.RepresentationsFileXMIHelper.setValue(RepresentationsFileXMIHelper.java:79)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2710)
	... 60 more

This exception is only thrown on the first save action. The changes are saved successfully, so there is no data loss. Later saves work fine, as I said, the exception is thrown only once.

I inspected the aird-file before and after the save and I see, that the save command seem to convert the platform URI of the semantic resource to a relative URI:
before:
<semanticResources>platform:/resource/myProject/model/model.xmi</semanticResources>
after save:
<semanticResources>model.xmi</semanticResources>


But the reason why I use a platform resource URI instead of a simple relative file URI is, that with the file URI I get an FileNotFoundException, when adding the xmi file as semantic resource.

Did I miss something or is there a way to avoid any of these exceptions?

Cheers,
Felix
Re: How to add a semantic resource with relative path [message #1835490 is a reply to message #1835174] Fri, 04 December 2020 15:56 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 508
Registered: May 2011
Senior Member
Hello,

If you want to programmatically add a semantic resource to a Sirius session, you can first create the URI:

final URI semanticModelURI= URI.createPlatformResourceURI("/" + PROJECT_NAME + "/" + FOLDER_PATH_IF_YOU_HAVE_SOME + "/" + "semanticModel.fileextension", true);

after that you can register this URI to the session using a recording command like this:

TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

@Override
protected void doExecute() {
// add resources to session
session.addSemanticResource(semanticModelURI, new NullProgressMonitor());
}
});

Best regards,
Steve


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to add a semantic resource with relative path [message #1835925 is a reply to message #1835490] Wed, 16 December 2020 15:34 Go to previous message
Felix S is currently offline Felix SFriend
Messages: 10
Registered: November 2014
Junior Member
Hi Steve,

thank you for your answer. Unfortunately I get the same exception with your code.

Cheers,
Felix
Previous Topic:JUnit testing and Sirius
Next Topic:upgrade Papyrus IDE (with RCP)
Goto Forum:
  


Current Time: Sat Apr 10 21:42:55 GMT 2021

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

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

Back to the top