Acceleo: using custom UML Profile as metamodal, and its stereotypes in templates?

987 views Asked by At

I'm new to Acceleo. I use IBM RSA (8.5.1). I created a custom UML Profile (with a few stereotypes extending default metaclasses, it's pretty usual). The UML profile is a .epx file. In addition, I created a simple model on which I applied my custom UML Profile, and "tagged" a few classes with my custom stereotypes.

My questions (sorry if it is trivial, but I didn't find a straight answer...):

  • Can I use my custom UML Profile as metamodel in Acceleo? Simply saying, instead of writing in my module file the following: [module main('http://www.eclipse.org/uml2/3.0.0/UML')] (this one works okay) can I write something like this: [module main('platform:/resource/MyProfileProject/MyProfile.epx')]? If I try this, I get an error message: "The metamodel couldn't be resolved". I tried to convert my UML Profile from .epx format to .xmi and to .uml. None of those work.

  • If this can be made working somehow, can I use my custom stereotypes as type qualifiers in Acceleo templates (in "for" cycles, etc.)?

Any help is appreciated. Thank you in advance. Marcell

2

There are 2 answers

0
PALEN On

It can be done. I'm adding an example to show how to do it, since it took me quite some time to retrieve the profile stereotypes. I'm adding it for a future reference (to whoever may need it).

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/uml2/4.0.0/UML')]

[template public generateElement(p : Class)]
[comment @main /]
[file (p.name.concat('.php'), false)]
  [if (hasStereotype(p, 'Soa Logic Profile::bOperation'))]
    code for bOperation stereotype  
  [/if]
  [if (hasStereotype(p, 'UML Standard Profile::entity'))]
    code for entity stereotype
  [/if]

  [p._package.member.getApplicableStereotypes().qualifiedName/]
  [hasStereotype(p, 'Soa Logic Profile::bOperation')/]

[/file]
[/template]

Notice that in the code above, the qualified name Soa Logic Profile::bOperation corresponds to the stereotype bOperation defined in the Soa Logic Profile. entity is a stereotype defined in the UML Standard Profile. Both Soa Logic Profile::bOperation and UML Standard Profile::entity are qualified names.

Note: You only need to use the UML-metamodel, this model (the .uml file) already has information about the applied profile. This can be checked by inspecting the .uml file. Also, as far as I understand, the *.profile.uml files do have to be in the same folder as the .uml model file.

Greetings from Paraguay!

0
Laurent On

I don't think you can.

As far as I know, you're supposed to use services to retrieve the profile data from your UML elements (stereotypes and so on), but the metamodel remains UML and this cannot be changed for Acceleo.

You can iterate over UML elements on lists of elements filtered according to their stereotype information though.