Skip to main content


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 14:58 Go to next message
Gianmaria De Tommasi is currently offline Gianmaria De TommasiFriend
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 08:26 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
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: Thu Apr 25 04:10:05 GMT 2024

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

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

Back to the top