How to serialize XMI model to Xtext file [message #1801382] |
Thu, 17 January 2019 18:34  |
Eclipse User |
|
|
|
Hello,
I try to transform a uml model to a DSL built with xtext.
The DSL is called OML (for ontology) I have the oml.xtext and 4 xcore files that are referenced in the mwe workfow of OML.
language = StandardLanguage {
name = "${baseName}.OML"
fileExtensions = "oml"
referencedResource = "platform:/resource/org.eclipse.emf.ecore.xcore.lib/model/XcoreLang.xcore"
referencedResource = "platform:/resource/${modelName}/model/OMLCommon.xcore"
referencedResource = "platform:/resource/${modelName}/model/OMLTerminologies.xcore"
referencedResource = "platform:/resource/${modelName}/model/OMLGraphs.xcore"
referencedResource = "platform:/resource/${modelName}/model/OMLBundles.xcore"
referencedResource = "platform:/resource/${modelName}/model/OMLDescriptions.xcore"
all code of oml project is here : https://github.com/JPL-IMCE/gov.nasa.jpl.imce.ontologies.public
I tried to transform my uml model to oml using QVTO. my QVTO tranformation produce an xmi file (tranfo is OK, the xmi file contains all transformed elements, but serealized in an xmi resource).
I tried then to serealize my xmi file to an oml file, I created an xtext resource and loaded all 5 xcore packages
when I call xtextresource.save(null) I get this error :
Any help please ? I used to play with QVTO transfo, but not with xtext serealization. Thank you very much
org.eclipse.e4.core.di.InjectionException: java.lang.RuntimeException: Could not serialize TerminologyExtensionAxiom:
TerminologyExtensionAxiom.extendedTerminology is required to have a value, but it does not.
Semantic Object: Extent.modules[0]->TerminologyGraph.boxAxioms[0]->TerminologyExtensionAxiom
URI: platform:/resource/UML2OML/transforms/PersonModel.oml
Context: TerminologyBoxAxiom returns TerminologyExtensionAxiom
....
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:513)
at gov.nasa.jpl.imce.oml.dsl.serializer.OMLSemanticSequencer.sequence_TerminologyExtensionAxiom(OMLSemanticSequencer.java:1708)
at gov.nasa.jpl.imce.oml.dsl.serializer.OMLSemanticSequencer.sequence(OMLSemanticSequencer.java:375)
here is how I create my xtext resource and load all packages (I present here only the loading of TerminologiesPackage but I do the same with all 5 packages).
// convert to xtext resource
XtextResourceSet xrs = new XtextResourceSet();
xrs.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
XtextPackage.eINSTANCE.eClass();
EcorePackage.eINSTANCE.eClass();
xrs.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
// load the ecore resource
Resource ecoreResource = xrs.getResource(URI.createURI(EcoreFactory.eINSTANCE.getEPackage().getNsURI()), true);
try {
ecoreResource.load(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EcoreUtil2.resolveAll(ecoreResource);
// load the terminology xcore
TerminologiesPackage.eINSTANCE.eClass();
Resource xcoreResource = xrs.getResource(URI.createURI(TerminologiesFactory.eINSTANCE.getEPackage().getNsURI()), true);
try {
xcoreResource.load(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EcoreUtil2.resolveAll(xcoreResource);
// create the xtext resource
XtextResource xtextResource = (XtextResource) xrs.createResource(targetURI);
//val xtextRoot = EcoreUtil.copy(emfRoot)
EObject emfRoot = umlResource.getContents().get(0);
xtextResource.getContents().add(emfRoot);
try {
xtextResource.save(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|
|
|
|
Re: How to serialize XMI model to Xtext file [message #1801426 is a reply to message #1801388] |
Fri, 18 January 2019 16:23  |
Eclipse User |
|
|
|
Hello,
Thank you very much !! indeed The QVTo transfo did not give a value to a mandatory reference. I update my QVTo transfo and the file is automatically serialized by the DSL Editor (no need to create an xtext resource set, load the xmi file in an xtext resource , etc).
It works now even for the direct build of qvto transfo (without any java code)
Thanks again !
|
|
|
Powered by
FUDForum. Page generated in 0.04174 seconds