How to add a semantic resource with relative path [message #1835174] |
Thu, 26 November 2020 10:45  |
Felix S 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   |
|
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 Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Powered by
FUDForum. Page generated in 0.02058 seconds