Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Defining multiple metamodels within the same template
[Acceleo] Defining multiple metamodels within the same template [message #532208] Fri, 07 May 2010 14:26 Go to next message
labassim  is currently offline labassim Friend
Messages: 6
Registered: May 2010
Junior Member
Hi,
I have two metamodels, let's say A and B which are independant of each other.
For example, A describes the GUI of an application while B describes its logic.
I would like to use A and B in the same template.
For example, for a particular graphical element of A, I want to create a particular entity of B.
Even if I managed to import both models in the template header :
...
[module generateAB('www.modelA.org', 'www.modelB.org')/]
[template public generateAB(a : aEntity, b : bEntity)]
...
I can't find out where to pass the two models as arguments.
In fact, the generated java file associated to the mtl template is defined to accept one model only :

GenerateAB generator = new GenerateAB(modelURI, folder, arguments);

Is there a way to pass the two models instead ?
Thanks in advance.

[Updated on: Fri, 07 May 2010 14:27]

Report message to a moderator

Re: [Acceleo] Defining multiple metamodels within the same template [message #533091 is a reply to message #532208] Wed, 12 May 2010 08:26 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050900020804020607060000
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Mehdi,

The generated Java class is mainly a convenience class to show users how
they can call Acceleo generations and offer them a quick API that will
be sufficient in most cases.

However, yours is not the "usual" case as you have to pass on two
elements (and coming from different models) to your templates. This can
be done with the Acceleo API, yet you'll have to get your hands dirty
and either change the generated methods directly or add new methods to
the generated class.

What you wish to look at are the "main()" and "doGenerate()" methods.
You can change the "main" so that
- the first String is the first model (this is the case by default),
- the second String is the second mode (you can load it through the same
APIs as what's used for the first one),
- the third String is the generation folder (a simple relocation from
the default "second" to "third"),
- subsequent Strings are the optional template arguments (as before,
relocating them from "3 and above" to "4 and above").

and the "doGenerate" so that instead of calling for 'super()' you have
your own code. Here is the content of the default "doGenerate" we call :

----------8<----------
File target = getTargetFolder();
if (!target.exists() && !target.mkdirs()) {
throw new IOException("target directory " + target + " couldn't be
created."); //$NON-NLS-1$ //$NON-NLS-2$
}
AcceleoService service = createAcceleoService();
String[] templateNames = getTemplateNames();
Map<String, String> result = new HashMap<String, String>();
for (int i = 0; i < templateNames.length; i++) {
result.putAll(service.doGenerate(getModule(), templateNames[i],
getModel(), getArguments(), target, monitor));
}
return result;
---------->8----------

What you wish to change is the call to "service.doGenerate". Again, this
is a convenience method that will iterate over the contents of the
passed EObject in order to find elements matching the type of the
template's _first_ argument. Since you need to iterate on two models,
you cannot use that. The method you need to call instead is
"service.doGenerateTemplate". You'll have to iterate over your two
models to find the tuples on which you wish to call the template and
pass these tuples over in the argument list "doGenerateTemplate" takes
as its third argument.

I believe you have enough information here to know where to change the
code in order to suit your needs, do not hesitate to come back with any
question that might pop-up when doing so.

Laurent Goubet
Obeo

labassim wrote:
> Hi,
> I have two metamodels, let's say A and B which are independant of each
> other.
> For example, A describes the GUI of an application while B describes its
> logic.
> I would like to use A and B in the same template.
> For example, for a particular graphical element of A, I want to create a
> particular entity of B.
> Even if I managed to import both models in the template header :
> ..
> [module generateAB('http://www.modelA.org', 'http://www.modelB.org')/]
> [template public generateAB(a : aEntity, b : bEntity)]
> ..
> I can't find out where to pass the two models as arguments.
> In fact, the generated java file associated to the mtl template is
> defined to accept one model only :
>
> GenerateAB generator = new GenerateAB(modelURI, folder, arguments);
>
> Is there a way to pass the two models instead ?
> Thanks in advance.


--------------050900020804020607060000
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050900020804020607060000--
Previous Topic:[Acceleo] Accessing external variables from templates
Next Topic:[Acceleo] Good way to get operations object from MessageOccurenceSpecification
Goto Forum:
  


Current Time: Thu Apr 25 03:35:23 GMT 2024

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

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

Back to the top