Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to transform xText to XMI
How to transform xText to XMI [message #666060] Mon, 18 April 2011 20:29 Go to next message
Alex Loh is currently offline Alex LohFriend
Messages: 5
Registered: June 2010
Location: Austin, TX
Junior Member
Hi,

xText comes with a snazzy ecore inference model that can take a grammar and guess a suitable eCore model for it. However, after I write a short program conforming to this grammar, I found that I still needed to write xpand templates to transform this to text!

Is there a way to turn the textual program in my specified grammar into an XMI (or similar) file conforming to the inferred ecore model?

Thanks!
Re: How to transform xText to XMI [message #666091 is a reply to message #666060] Tue, 19 April 2011 05:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13591
Registered: July 2009
Senior Member
Hi,

if you work e.g. with a programmatically read model it is actually an model instance based on the generated ecore.

How you can read in the model files standalone you can find in the docs section Processing Xtext Models.

If you still need an XMI Feel free to move the contents of the read Xtext Resource to and XMI Resource.

ResourceSet rs = new ResourceSetImpl();
Resource resource = rs.getResource(URI.createURI("./mymodel.dmodel"), true);
EObject eobject = resource.getContents().get(0);
//create xmi resource
Resource xmiResource = ....
xmiResource.getContents().add(eobject);
//persist xmi resource
....


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 19 April 2011 05:50]

Report message to a moderator

Re: How to transform xText to XMI [message #666101 is a reply to message #666091] Tue, 19 April 2011 07:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6839
Registered: July 2009
Senior Member
Hi Christian

This is an area where I feel that Xtext has been too clever.

You can open an Xtext CS file in the Sample Ecore Editor and see the
tree view, but if you then do SaveAs *.xmi, the result is saved as CS
text rather than XMI text. Somehow Xtext has higher priority than XMI.
It would be nice to have this interactive approach work fully.

Regards

Ed Willink

On 19/04/2011 06:44, Christian Dietrich wrote:
> Hi,
>
> if you work e.g. with a programmatically read model it is actually an
> model instance based on the generated ecore.
>
> How you can read in the model files standalone you can find in the
> docs section Processing Xtext Models.
>
> If you still need an XMI Feel free to move the contents of the read
> Xtext Resource to and XMI Resource.
>
>
> ResourceSet rs = new ResourceSetImpl();
> Resource resource = rs.getResource(URI.createURI("./mymodel.dmodel"),
> true);
> EObject eobject = resource.getContents().get(0);
> Resource xmiResource = ....
> xmiResource.getContents.add(eobject);
> ...
>
>
> ~Christian
Re: How to transform xText to XMI [message #666121 is a reply to message #666101] Tue, 19 April 2011 08:13 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Hi Ed,

this seems to be a bug in the sample Ecore editor, which renames the
resource's URI rather than creating a new one with the extension from
the new URI, if it's not a conversion between "ecore" and "emof":

(EcoreEditor.doSaveAs)

if (currentExtension.equals(ECORE_FILE_EXTENSION) &&
newExtension.equals(EMOF_FILE_EXTENSION) ||
currentExtension.equals(EMOF_FILE_EXTENSION) &&
newExtension.equals(ECORE_FILE_EXTENSION))
{
Resource newResource = resourceSet.createResource(newURI);
newResource.getContents().addAll(currentResource.getContents ());
resourceSet.getResources().remove(0);
resourceSet.getResources().move(0, newResource);
}
else
{
currentResource.setURI(newURI);
}

Regards
Jan


Am 19.04.11 09:07, schrieb Ed Willink:
> Hi Christian
>
> This is an area where I feel that Xtext has been too clever.
>
> You can open an Xtext CS file in the Sample Ecore Editor and see the
> tree view, but if you then do SaveAs *.xmi, the result is saved as CS
> text rather than XMI text. Somehow Xtext has higher priority than XMI.
> It would be nice to have this interactive approach work fully.
>
> Regards
>
> Ed Willink
>
> On 19/04/2011 06:44, Christian Dietrich wrote:
>> Hi,
>>
>> if you work e.g. with a programmatically read model it is actually an
>> model instance based on the generated ecore.
>>
>> How you can read in the model files standalone you can find in the
>> docs section Processing Xtext Models.
>>
>> If you still need an XMI Feel free to move the contents of the read
>> Xtext Resource to and XMI Resource.
>>
>>
>> ResourceSet rs = new ResourceSetImpl();
>> Resource resource = rs.getResource(URI.createURI("./mymodel.dmodel"),
>> true);
>> EObject eobject = resource.getContents().get(0);
>> Resource xmiResource = ....
>> xmiResource.getContents.add(eobject);
>> ...
>>
>>
>> ~Christian
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: How to transform xText to XMI [message #666303 is a reply to message #666091] Tue, 19 April 2011 20:02 Go to previous messageGo to next message
Alex Loh is currently offline Alex LohFriend
Messages: 5
Registered: June 2010
Location: Austin, TX
Junior Member
Hi Christian,

Thanks a lot for the speedy response!

This works. Would be nice if the feature was part of the generated tooling rather than something you had to implement manually (eg some button that says "Save as XMI" in the generated UI).

Just for completeness this is the code I used with holes left out:

XMIResourceFactoryImpl resFactory = new XMIResourceFactoryImpl();
URI xmiuri = URI.createFileURI("blabla/bla/output.xmi);
XMIResource xmiresource = (XMIResource) resFactory.createResource(xmiuri);
xmiresource.getContents().add(app);
xmiresource.save(new HashMap());

where "app" is the resource that represents my model. Should be obvious to EMF pros but took me some time to figure out.
Re: How to transform xText to XMI [message #666310 is a reply to message #666303] Tue, 19 April 2011 20:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13591
Registered: July 2009
Senior Member

Hi,

Regarding the "to xmi" Button. Since the model files are a texual persistence of the ecore Based model and the xmi files are a xml based persistence the only difference is the way of persisting. So there is usually no need for a transformation except some special usecases e.g. If you want deploy the Models to somewhere where Xtext is Not available.

Regards, Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to transform xText to XMI [message #697619 is a reply to message #666310] Sun, 17 July 2011 13:08 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Currently I too use this approach, save it as .xmi, which is then read by eg. ATL (in an ant based transformation sequence).

Christian, do you still think there is need for m2m transformations, that read the xtext-generated xmi model, and transform it, followed by an eventual XPand transformation to text?

Because this is my current approach (ie. I have an MDA that generates webapps). Allthough I don't use any expressions in my model, just declarative structural stuff, and generate 'defaults' in terms of behaviours, so for that purpose I'd say the XTend thing is very useful.

I wonder what your opinion is about this.


My company: Sytematic, building business software from models.
Re: How to transform xText to XMI [message #697625 is a reply to message #697619] Sun, 17 July 2011 13:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13591
Registered: July 2009
Senior Member
Hi,

Hi, if you need an M2M depends on your usecase Wink if you use Xtend, Xpand, ATL, Acceleo or any other M2M/M2T Tech depends on your usecase too. And of course on your person knowledge of the technologies. As itemis guy i of cource would't like to see you using Xtend(2)

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to transform xText to XMI [message #697825 is a reply to message #697625] Mon, 18 July 2011 06:59 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Yeah okay, thanks for the reply.

I was thinking about it, and what is an advantage of my approach is that with the m2m step you can lower the abstraction level very much. Would it make sense to use XTend2 AFTER a m2m step? (is that even possible? Just kind of 'thinking out loud at the moment')


My company: Sytematic, building business software from models.
Re: How to transform xText to XMI [message #697855 is a reply to message #697825] Mon, 18 July 2011 07:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13591
Registered: July 2009
Senior Member
Hi, as far as the m2m target metamodel is emf based and you ve got
Java classes for it this should be no problem. You can even use
Xtend2 for the m2m itself.~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Nomenclature question about Parser Rules
Next Topic:Xtext from 2 ecore files
Goto Forum:
  


Current Time: Sat Sep 19 20:15:58 GMT 2020

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

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

Back to the top