How to serialize XMI model to Xtext file [message #1801382] |
Thu, 17 January 2019 23:34 |
smaoui asma Messages: 50 Registered: July 2009 Location: Paris Saclay, France |
Member |
|
|
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 #1801388 is a reply to message #1801382] |
Fri, 18 January 2019 05:44 |
|
The error suggests that your DSL declares a mandatory reference, which was not set by your transformation. The target model is incomplete and can't be serialized. So start checking the mentioned reference and the state of the model instance that is to be serialized. You may set a breakpoint when the exception is thrown and inspect the instance.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02784 seconds