How do I get "xmi:type" value

514 views Asked by At

I am trying to generate a java program to implement a State Machine from a UML model using Acceleo.

In my model I have entries like:--

 <subvertex xmi:type="uml:State" xmi:id="{BB1999-E740-4e7d-A1BE-F099BEXYD970}" name="WaitingApproval">

I want to check the value of "xmi:type" but I cannot work out how to access this from Acceleo. (I have tried every combination of gets I can think of and the type only appears as part of a longer string if I dump the whole vertex.)

1

There are 1 answers

1
Vincent Aranega On BEST ANSWER

If you are on the subvertex relation, you must be on a Region. The xmi:type is the way XMI handles polymorphic references. As subvertex is defined as Vertex [*], XMI must specify the type of each element in the collection. To check this field, you simply need to test the type of the element (using oclIsTypeOf or oclIsKindOf)

So, from a Region:

[template public test(r : Region)]
[r.subvertex->filter(State)/] --> filter all States from the subvertex collection
which is equ. to
[r.subvertex->select(oclIsKindOf(State))/]
and if you want only the State elements (no subclasses)
[r.subvertex->select(oclIsTypeOf(State))/] 
[/template]

Also, you can handle them in different templates by adding template guard:

[template public test(r : Region)]
[r.subvertex.test2()/]
[/template]

[template public test2(s : Vertex) ? (oclIsKindOf(State))]
[s/] is a state for sure
[/template]

you can also avoid guard by rewriting the above templates as this:

[template public test(r : Region)]
[r.subvertex.test2()/]
[/template]

[template public test2(v : Vertex)/]
[template public test2(s : State)]
[s/] is a state for sure
[/template]

EDIT

If you absolutely want the type value in a String format, you have to go check the element metaclass and ask for its name:

...
[s.eClass().name/] -> result as String, s.eClass() gets the EClass
...