2015-06-10 24 views
0

我正嘗試使用Acceleo生成一個從UML模型實現狀態機的java程序。我如何得到「xmi:type」值

在我的模型我有這樣的條目: -

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

我要檢查的價值「XMI:類型」,但我不能工作了如何從Acceleo訪問此。 (我已經嘗試了所有我能想到的組合,並且類型只會作爲較長字符串的一部分出現,如果我轉儲整個頂點)。

+0

https://stackoverflow.com/問題/ 48024563/how-to-get-xmiid-from-xmi-files-in-acceleo – kincki

回答

1

如果您處於subvertex關係中,您必須位於Regionxmi:type是XMI處理多態引用的方式。由於subvertex定義爲Vertex [*],因此XMI必須指定集合中每個元素的類型。要檢查該字段,你只需要測試的元素的類型(使用oclIsTypeOfoclIsKindOf

所以,從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] 

此外,您還可以在不同的模板處理它們通過添加模板後衛:

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

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

您也可避免後衛通過重寫上面的模板,因爲這:

[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] 

編輯

如果你絕對要以字符串格式類型值,你必須去檢查元素元類,並要求它的名字:

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

謝謝!在可用的方法中看不到oclIsTypeOf! –