2016-01-29 58 views
0

我正在Acceleo(在Eclipse中)中開發M2T生成器。該模型基本上是一個在Papyrus中創建SysML概要文件的UML模型。它包含Blocks和FlowPorts。我必須訪問這些構造型,但似乎我無法檢索任何SysML對象,即使它們出現在列表中(代碼建議)。實際上,我必須訪問與Port關聯的FlowPort的'Direction'屬性。我已經嘗試過各種論壇(包括https://www.eclipse.org/forums/index.php/t/452587/)的建議和答案,但徒勞無功。無法在Acceleo中訪問SysML構造型及其屬性

代碼如下。我按照https://www.eclipse.org/forums/index.php?t=msg&th=1060450&goto=1693765&的建議創建了java服務,但port.hasStereotype('FlowPort')總是返回false。我也嘗試過'SysML :: PortAndFlows :: FlowPort'而不是'FlowPort'。我在Eclipse Mars上使用Acceleo 3.6.2。

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

我包括在模塊以下元模型在創建模塊的時間:

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 

另外,我註冊所需的軟件包包括Generate.java在registerPackages)以下(通過的建議上面剛剛提到的鏈接。

// 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("")); 

任何形式的幫助表示讚賞。

回答

0

我有一個相同的問題,但與UML/MARTE而不是SysML。

我敢打賭,port.getAppliedStereotypes()總是返回空列表,不管是什麼(即使當然,端口千篇一律)。我也嘗試了你所做的一切,但沒有成功,包括仔細檢查registerPackages方法的javadoc中是否有@generated NOT(每次都重新生成)。

我解決了這個問題一點辦法。我假設你(就像我做過的那樣)用作輸入來轉換Papyrus生成的model.uml文件。這可能實際上是問題的原因,儘管我沒有看到替代方案。如果您使用文本編輯器打開該文件,則會發現<FlowPort>標籤位於<uml:Model>標籤之外。這意味着,由於我仍然無法理解的原因,stereotype()方法不能「看到」構造型並且總是返回null或空列表。這可能是因爲他們無法將原型base_NamedElement<uml:Model>標籤內的xmi:id相匹配。另一方面,如果您定義了一個模板,該模板將FlowPort(而不是模型)作爲輸入,您將能夠獲得您的刻板印刷的元素及其所有屬性。

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

其中,您還可以訪問刻板印象的base_NamedElement財產(即,在模型定型FlowPortPort),你可以使用基本元素的qualifiedName屬性映射回原型到您的Model中的Port。實際上,這意味着你必須親自將刻板印象與刻板印象的實體聯繫起來。

笨重和煩人的,但仍然得到的工作,直到有人提出一個較少的「解決方法」的解決方案。

+0

嗨st1led,是的,我正在使用紙莎草生成的uml模型。我已經發現了你的建議工作,但我不確定我們是否可以訪問該模板中的所有UML對象(使用FlowPort)。例如,我可以訪問包含Class或Package對象嗎? – Yasir

+0

訪問FlowPort的'base_namedElement',即'Port'後,就可以使用UML對象的API(例如'owner','ownedElements'等)從'Port'導航。這是你想要的? – st1led