| Serialization: XMI to Text [message #503241] |
Fri, 11 December 2009 09:52  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03713 seconds