Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Passing arbitrary data to Xpand
Passing arbitrary data to Xpand [message #630696] Mon, 04 October 2010 15:29 Go to next message
Ben Tenne is currently offline Ben TenneFriend
Messages: 49
Registered: October 2009
Member
Hi,

I'm a newcomer to Xpand and have run into something that I suspect there is a very simple answer to (but haven't found it yet).

I'm starting with an EMF model and wish to generate Java code from it. However, there is various data that I need to make visible to my Xpand template that cannot be found in the model itself. Taking an example, let's assume the model contains an EClass with name='Hello' and I want to generate a corresponding Java class called 'HelloDAO'. No problem - I can say:

«DEFINE DAOClass FOR ecore::EClass»
«FILE name + "DAO.java"»
// DAO code goes here
«ENDFILE»
«ENDDEFINE»

..and that works fine.

However, what my EMF model doesn't tell you is that 'HelloDAO' needs to exist in a package called 'com.example', so I need a 'package com.example' declaration at the top and HelloDAO.java needs to reside in /com/example, relative to my src root. How can I make this information visible to my script?

I'm aware that I can write a Java helper class and expose its methods to my XPT via an .ext file, but given that those Java methods are static, I can't see how I'd pass a separate set of meta-data for each transformation.

Many thanks in advance for any help.

Ben.
Re: Passing arbitrary data to Xpand [message #630760 is a reply to message #630696] Mon, 04 October 2010 19:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

there are several possibilities to achive this
- use global vars (built-in or from std lib)
- or pass it as param to the template

«DEFINE DAOClass(String basePath) FOR ecore::EClass»
«FILE basePath + "/" + name + "DAO.java"»
// DAO code goes here
«ENDFILE»
«ENDDEFINE»


<expand value="somenamespace::example::DAOClass('com/example') FOR myModel"/>


See Xpand and Std libs for the documentation of the possibilities



~Christian
Re: Passing arbitrary data to Xpand [message #630965 is a reply to message #630760] Tue, 05 October 2010 16:17 Go to previous message
Ben Tenne is currently offline Ben TenneFriend
Messages: 49
Registered: October 2009
Member
Thanks Christian.

It looks like global vars are the right choice in my case (as I have many such pieces of data to pass around).

Thanks again,
Ben.
Previous Topic:[Check] Under HELIOS
Next Topic:<XPAND> collaboration diagram
Goto Forum:
  


Current Time: Sat Dec 20 21:06:03 GMT 2014

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

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