How to add a semantic resource with relative path [message #1835174] |
Thu, 26 November 2020 05:45  |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03945 seconds