Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] How to programmatically use an ecore model root object for code generation
[Xpand] How to programmatically use an ecore model root object for code generation [message #553267] Mon, 16 August 2010 21:34 Go to next message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: August 2010
Location: Munich
Junior Member

I have the following problem. I have already read an ecore model (which
is not available as an xmi file) into an object hierarchy and I have the
root element of the model as an object on which I can get a tree
iterator of all eObjects:

TreeIterator<EObject> iterator = root.eAllContents();

I also have a normal ecore metamodel describing the model "metamodel.ecore".

Now I want to programmatically invoke some templates in an eclipse
plugin (without using an mwe workflow). But as I saw from some
tutorials/examples I have to specifiy a modelSlot where the model is
stored. How can I do that with an object instance like "root"?

One try was to use the modelReader:

org.eclipse.emf.mwe2.runtime.workflow.WorkflowContextImpl context = new
// ...
org.eclipse.emf.mwe.utils.Reader modelReader = new Reader();

Before invoking the modelReader I have to call "setUri"

modelReader.setUri(new String()); // here I need the model URI

But I don't know how to get an URI from an object and at the moment I
don't see other possibilities :-(

The next problem is: How I can tell the generator programmatically to
use the model in the modelslot. I try the following at the moment, but
cannot test it:

org.eclipse.xpand2.Generator generator = new Generator();
// ...
generator.setExpand("xpand::template::Root FOR modelSlot");

Is it possible to do it like above? I saw that in some workflow.mwe
examples, but I'm not sure how the generator knows what the modelSlot
is, when I only set that in the modelReader (and not in the generator)

Does anybody knwo how to fix these problems? Or is it just not possible
in Xpand to use an model root object for code generation and I have to
save my model into an xmi file first and then read it again with the

Thank you very much for answers/solutions!
Re: [Xpand] How to programmatically use an ecore model root object for code generation [message #553271 is a reply to message #553267] Mon, 16 August 2010 22:14 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14650
Registered: July 2009
Senior Member
Hello Stephan, have a look at the XpandFacade to call the generator directly. or you erite your own workflow component that reads / creates the Model. Maybe you have a look at the Readers code. BTW i would not call the allcontentstreeiterator a model root. If you have already a root eobject why not pass this.~Christian

Update: You can store the model to a "slot" by just calling context.set("modelSlot",root) with context beeing a WorkflowContext.

Twitter : @chrdietrich
Blog :

[Updated on: Tue, 17 August 2010 06:40]

Report message to a moderator

Previous Topic:how to restrict generation to a set of packages
Next Topic:[Announce] M2T ACCELEO 3.1.0M1 is available
Goto Forum:

Current Time: Wed Feb 21 04:18:14 GMT 2024

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

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

Back to the top