0

I am developing a M2T generator in Acceleo (in Eclipse). The model is basically a UML model with SysML profile created in Papyrus. It includes Blocks and FlowPorts. I have to access these stereotypes but it seems that I cannot retrieve any SysML object even though they appear in list (code suggestion). Actually I have to access ‘Direction’ property of FlowPort associated with Port. I have already tried suggestions and answers from various forums (including https://www.eclipse.org/forums/index.php/t/452587/) but in vain.

The code is given below. I have created java services as suggested by https://www.eclipse.org/forums/index.php?t=msg&th=1060450&goto=1693765& but port.hasStereotype(‘FlowPort’) always return false. I have also tried ‘SysML::PortAndFlows::FlowPort’ instead of ‘FlowPort’. I use Acceleo 3.6.2 on Eclipse Mars.

...
[template public generateElement(model : Model)]
[comment @main/]

[file ('created.txt', false, 'UTF-8')]
[for(port: Port | model.eAllContents(Port))]
    [if(port.hasStereotype('FlowPort'))]
        OK
    [else]
        NOT OK
    [/if]
[/for]
[/file]
[/template]

I include following metamodels in the Module at the time of creating the module:

http://www.eclipse.org/uml2/5.0.0/UML
http://www.eclipse.org/papyrus/0.7.0/SysML
http://www.eclipse.org/papyrus/0.7.0/SysML/Blocks
http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints
http://www.eclipse.org/papyrus/0.7.0/SysML/PortAndFlows
http://www.eclipse.org/emf/2002/Ecore

Also, I do register required packages including following in registerPackages() of Generate.java as suggested by the link just mentioned above.

    // UML2 profiles
    URI uri = URI.createURI("platform:/plugin/org.eclipse.uml2.uml.resources");
    uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));  

    // SysML profiles
    uri = URI.createURI("platform:/plugin/org.eclipse.papyrus.sysml");
    uriMap.put(URI.createURI(SysmlResource.LIBRARIES_PATHMAP), uri.appendSegment("librairies").appendSegment(""));
    uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"), uri.appendSegment("SysML.profile.uml").appendSegment("")); 
    uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"), uri.appendSegment("model").appendSegment(""));

Any sort of help is appreciated.

Yasir
  • 1
  • 2

1 Answers1

0

I had an identical problem, but with UML/MARTE rather than SysML.

I bet that port.getAppliedStereotypes() always returns the empty list, no matter what (even if of course, port is stereotyped). I also tried everything you did, unsuccessfully, including double-checking if there was a @generated NOT in the javadoc of the registerPackages method (to it being re-generated each time).

I fixed the issue whit a little workaround. I assume that you (like I did) use as input for the transformation the model.uml file generated by Papyrus. This might actually be the cause of the problem, even though I don't see an alternative. If you open that file with a text editor, you'll find that the <FlowPort> tags are outside the <uml:Model> tag. This means that, for reasons that I still fail to understand, the stereotype() methods cannot "see" the stereotypes and always return null, or empty lists. This is possibly because they fail to match the stereotype base_NamedElement to the xmi:id inside the <uml:Model> tag.

On the other hand, if you define a template which takes as input a FlowPort (rather than a Model) you will be able to get your stereotyped element and all of its properties.

[template public generateElement(aFlowPort: FlowPort)]
[comment @main /]
[comment here you can access to the aFlowPort fields]
[/template]

Among others, you can also access the base_NamedElement property of the stereotype (i.e., the Port that is stereotyped FlowPort in your model), and you can use the qualifiedName property of the base element to map back the stereotype to the Port in your Model. In practice, this means that you have to link the stereotypes to their stereotyped entities by hand.

Clunky and annoying, but still gets the job done until somebody comes with a less "workaroundy" solution.

st1led
  • 385
  • 2
  • 4
  • 18
  • Hi st1led, Yes, I was using a papyrus generated uml model. I had already discovered your suggested work around but I am not sure if we can access all UML objects in that template (with FlowPort). For example can I access containing Class or Package object? – Yasir Feb 12 '16 at 21:52
  • Once you access the `base_namedElement` of the `FlowPort`, i.e., a `Port`, you can navigate from the `Port` using the APIs for UML objects, such as `owner`, `ownedElements`, and so on. Is this what you are looking for? – st1led Mar 02 '16 at 14:33