Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Serialization: XMI to Text
Serialization: XMI to Text [message #503241] Fri, 11 December 2009 09:52 Go to next message
Eclipse UserFriend
Hi,

I have an (DSL) XMI file, a serialized representation of a model which is conformed to the Ecore (DSL) metamodel automatically generated by Xtext.

Now, I would like to write (DSL) XMI model back to Text (concrete syntax).
More precisely, I would like to generate from the XMI file a textual representation which is conformed to the DSL grammar previously defined in Xtext.

I try something like that:
IFile dslFile = .......
ResourceSet rs = new ResourceSetImpl();
strURI = "platform:/resource" + dslFile.getFullPath().toString();
mmURI = URI.createURI(strURI);
XtextResource xtextRes = (XtextResource) rs.getResource(mmURI, true);

try {
Resource res = rs.createResource(mmURI.appendFileExtension(".txt")); // .mydsl
res.getContents().add(xtextRes.getContents().get(0));
res.save(null);
}
...

Unfortunately, I get the XMI content instead of the original DSL with its concrete syntax...

Is it the right way to do so?
Where is the mistake?

Cheers,

Mathieu

[Updated on: Fri, 11 December 2009 05:38] by Moderator

Re: Serialization: XMI to Text [message #503317 is a reply to message #503241] Fri, 11 December 2009 14:34 Go to previous message
Eclipse UserFriend
Hi Acher,
> Hi,
> I have an (DSL) XMI file, a serialized representation of a model which
> is conformed to the Ecore (DSL) metamodel automatically generated by Xtext.
> Now, I would like to write (DSL) XMI model back to Text (concrete syntax).
>
> I try something like that:
> IFile dslFile = .......
> ResourceSet rs = new ResourceSetImpl();
> strURI = "platform:/resource" + dslFile.getFullPath().toString();
> mmURI = URI.createURI(strURI);
> XtextResource xtextRes = (XtextResource) rs.getResource(mmURI, true);
>
> try {
> Resource res = rs.createResource(mmURI.appendFileExtension(".txt"));
> res.getContents().add(xtextRes.getContents().get(0));
> res.save(null);
> }
> ..
>
> Unfortunately, I get the XMI content instead of the original DSL with
> its concrete syntax...
> Is it the right way to do so? Where is the mistake?

Your code looks about right. Please check if rs.createResource(..)
really retruns an instance of org.eclipse.xtext.resource.XtextResource.

If not, and you are running your code in a non-OSGi-environment (like a
JUnit-test), you'll need to call <MyLanguage>StandaloneSetup.doSetup()
first. This registers the XtextResoure for the fileextesntion of your
language.

hth,
Moritz

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Cyclic resolution of lazy links while typing
Next Topic:grammar for logical and arithmetical expressions
Goto Forum:
  


Current Time: Wed Nov 05 17:45:40 EST 2025

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

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

Back to the top