Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo/Papyrus] Problem with FlowPort direction
[Acceleo/Papyrus] Problem with FlowPort direction [message #696243] Wed, 13 July 2011 10:58 Go to next message
Gianmaria De Tommasi is currently offline Gianmaria De Tommasi
Messages: 2
Registered: July 2011
Junior Member
Hi,

I'm trying to access to the "direction" attribute of a SysML FlowPort in my Papyrus model using Acceleo.

In my template I need to access to the 'direction' of the flow ports. That's what I'm trying to do

[template private generateHeaderFile(myGAM : Class)]

...

[for (p : Property | myGAM.getAllAttributes())]
[let fp : Stereotype = p.getApplicableStereotype('SysML::PortAndFlows::FlowPort')]
[if not fp->asBag()->isEmpty()]
/** [fp.getAllAttributes()->select(name='direction').toString()/] */
[/if]
[/let]
[/for]

...

[/template]

although the 'direction' attribute should be equal to 'in', 'out' or 'inout', I'm not able to retrieve it

Any hint ?

Thanks
Re: [Acceleo/Papyrus] Problem with FlowPort direction [message #698296 is a reply to message #696243] Tue, 19 July 2011 04:26 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
Hi,

Retrieving an UML tagged value from Acceleo is quite tricky, and I strongly recommend that you use a Java service for that. Create a Java service with code such as this :

public boolean hasStereotype(Element element, String stereotypeName) {
    return element.getAppliedStereotype(stereotypeName) != null;
} 

public List<Object> getTaggedValue(Element element, String stereotypeName, String property) {
    Stereotype stereotype = element.getAppliedStereotype(stereotypeName);
    List<Object> result = new ArrayList<Object>();
    if (stereotype == null) {
        return 
    }

    Object value = element.getValue(stereotype, property);
    if (value instanceof Collection) {
        result.addAll((Collection)value);
    } else {
        result.add(value);
    }
    return result;
}


Then either use the wizard "File > New > Other > Acceleo > Acceleo Module File" and make sure you select "create service wrapper" in the combo box "initialize contents". Select the Java file containing the method above and you'll get a new Acceleo module with the query corresponding to that java service (or watch the step by step http://www.obeonetwork.com/page/the-acceleo-queries).

You'll then be able to call that service from your module (example if you've called the Acceleo module containing the service "acceleo::service::StereotypeUtils") :

...
[import acceleo::service::StereotypeUtils/]
...
[if (element.hasStereotype('SysML::PortAndFlows::FlowPort')]
    /** direction : getTaggedValue(element, 'SysML::PortAndFlows::FlowPort', 'direction') */
[/if]
...


Laurent Goubet
Obeo
Previous Topic:[Acceleo] Service class not found in the bundle containing module emtl
Next Topic:[XPand]trying to start Xpand from a plugin
Goto Forum:
  


Current Time: Wed Jul 30 15:18:36 EDT 2014

Powered by FUDForum. Page generated in 0.01486 seconds