|
Re: [Acceleo/Papyrus] Problem with FlowPort direction [message #698296 is a reply to message #696243] |
Tue, 19 July 2011 08:26  |
|
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.02082 seconds