Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to serialize XMI model to Xtext file
How to serialize XMI model to Xtext file [message #1801382] Thu, 17 January 2019 23:34 Go to next message
smaoui asma is currently offline smaoui asmaFriend
Messages: 35
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 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 687
Registered: July 2009
Location: Dortmund, Germany
Senior Member

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.
Re: How to serialize XMI model to Xtext file [message #1801426 is a reply to message #1801388] Fri, 18 January 2019 21:23 Go to previous message
smaoui asma is currently offline smaoui asmaFriend
Messages: 35
Registered: July 2009
Location: Paris Saclay, France
Member
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 !
Previous Topic:xtend-maven plugin does not work in 2.12.0 release
Next Topic:Formatter2 xtend classes not converted to java on Linux
Goto Forum:
  


Current Time: Mon Aug 19 06:28:08 GMT 2019

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

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

Back to the top