[Acceleo/Papyrus] Problem with FlowPort direction [message #696243] |
Wed, 13 July 2011 10:58  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04039 seconds