如何使用Acceleo检查SysML构造型?

时间:2017-05-28 16:35:08

标签: uml acceleo papyrus sysml

我使用Eclipse 4.6.3(Neon.3)和Acceleo 3.6.6,Paprus 2.0.3和Papyrus SysML 1.4 0.10.1。 如何从Acceleo MTL脚本中检查我的模型类是否应用了SysML Block构造型?方法getAppliedStereotypes()仅适用于我自己定义的构造型,但不适用于SysML 1.4。

在我创建的UML模型(Papyrus项目)中

  • "的Class1"我已经应用了自己的刻板印象" MyProfile :: MyStereotype"在"模型资源管理器"中创建通过"简介" /"更新个人资料"以及

  • "等级2"我申请了#34; SysML :: Blocks :: Block"在"属性" /"简介" /"应用刻板印象"

在generate.mtl的Acceleo项目中,如果我在这两个类中的每个类上调用getAppliedStereotypes(),我只会得到" Class1"的构造型,但是#34没有;等级2"

model.uml:

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Blocks="http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks" xmlns:MyProfile="http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks http://www.eclipse.org/papyrus/sysml/1.4/SysML#//blocks http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0 MyProfile.profile.uml#__olvQUO5EeezquIZgVUJBA">
  <uml:Model xmi:id="_Jl27kEO4EeezquIZgVUJBA" name="RootElement">
    <packagedElement xmi:type="uml:Class" xmi:id="_LpXEYEO4EeezquIZgVUJBA" name="Class1"/>
    <packagedElement xmi:type="uml:Class" xmi:id="_ZFGQwEO4EeezquIZgVUJBA" name="Class2"/>
    <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_SLhJ0EO4EeezquIZgVUJBA">
      <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_SLi_AEO4EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/papyrus/sysml/1.4/SysML#//blocks"/>
      </eAnnotations>
      <appliedProfile xmi:type="uml:Profile" href="pathmap://SysML14_PROFILES/SysML.profile.uml#SysML.package_packagedElement_Blocks"/>
    </profileApplication>
    <profileApplication xmi:type="uml:ProfileApplication" xmi:id="__om9ZkO5EeezquIZgVUJBA">
      <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__om9Z0O5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="MyProfile.profile.uml#__olvQUO5EeezquIZgVUJBA"/>
      </eAnnotations>
      <appliedProfile xmi:type="uml:Profile" href="MyProfile.profile.uml#__og2wEO5EeezquIZgVUJBA"/>
    </profileApplication>
  </uml:Model>
  <Blocks:Block xmi:id="_bBkkgEO4EeezquIZgVUJBA" base_Class="_ZFGQwEO4EeezquIZgVUJBA"/>
  <MyProfile:MyStereotype xmi:id="__ooykEO5EeezquIZgVUJBA" base_Class="_LpXEYEO4EeezquIZgVUJBA"/>
</xmi:XMI>

MyProfile.profile.uml:

<?xml version="1.0" encoding="UTF-8"?>
<uml:Profile xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="__og2wEO5EeezquIZgVUJBA" name="MyProfile" metaclassReference="__oiE4EO5EeezquIZgVUJBA">
  <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__olvQEO5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML">
    <contents xmi:type="ecore:EPackage" xmi:id="__olvQUO5EeezquIZgVUJBA" name="MyProfile" nsURI="http:///schemas/MyProfile/__okhIEO5EeezquIZgVUJBA/0" nsPrefix="MyProfile">
      <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__om9YEO5EeezquIZgVUJBA" source="PapyrusVersion">
        <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9YUO5EeezquIZgVUJBA" key="Version" value="0.0.1"/>
        <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9YkO5EeezquIZgVUJBA" key="Comment" value=""/>
        <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9Y0O5EeezquIZgVUJBA" key="Copyright" value=""/>
        <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9ZEO5EeezquIZgVUJBA" key="Date" value="28.05.17 17:26"/>
        <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__om9ZUO5EeezquIZgVUJBA" key="Author" value=""/>
      </eAnnotations>
      <eClassifiers xmi:type="ecore:EClass" xmi:id="__olvQkO5EeezquIZgVUJBA" name="MyStereotype">
        <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__olvQ0O5EeezquIZgVUJBA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="__og2wUO5EeezquIZgVUJBA"/>
        <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="__olvREO5EeezquIZgVUJBA" name="base_Class" ordered="false" lowerBound="1">
          <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
        </eStructuralFeatures>
      </eClassifiers>
    </contents>
  </eAnnotations>
  <elementImport xmi:type="uml:ElementImport" xmi:id="__oiE4EO5EeezquIZgVUJBA">
    <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
  </elementImport>
  <packagedElement xmi:type="uml:Stereotype" xmi:id="__og2wUO5EeezquIZgVUJBA" name="MyStereotype">
    <ownedAttribute xmi:type="uml:Property" xmi:id="__oir8kO5EeezquIZgVUJBA" name="base_Class" association="__oir8EO5EeezquIZgVUJBA">
      <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Extension" xmi:id="__oir8EO5EeezquIZgVUJBA" name="Class_MyStereotype" memberEnd="__oir8UO5EeezquIZgVUJBA __oir8kO5EeezquIZgVUJBA">
    <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="__oir8UO5EeezquIZgVUJBA" name="extension_MyStereotype" type="__og2wUO5EeezquIZgVUJBA" aggregation="composite" association="__oir8EO5EeezquIZgVUJBA"/>
  </packagedElement>
</uml:Profile>

generate.mtl:

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks', 'http://www.eclipse.org/uml2/5.0.0/UML')]


[template public generateModel(model : Model)]
[comment @main/]
[file (model.name, false, 'UTF-8')]
    [for (c : Class | model.eContents(Class))]
[c.name/]
        [for (s : Stereotype | c.getAppliedStereotypes())]
  [s/]
        [/for]
    [/for]
[/file]
[/template]

输出:

Class1
  org.eclipse.uml2.uml.internal.impl.StereotypeImpl@485a3466 (name: MyStereotype, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Class2

papyrus_project:

papyrus_project
papyrus_project/model.uml
papyrus_project/MyProfile.profile.di
papyrus_project/MyProfile.profile.notation
papyrus_project/model.di
papyrus_project/.project
papyrus_project/MyProfile.profile.uml
papyrus_project/model.notation

acceleo_project:

acceleo_project
acceleo_project/src
acceleo_project/src/acceleo_project
acceleo_project/src/acceleo_project/main
acceleo_project/src/acceleo_project/main/generate.mtl
acceleo_project/src/acceleo_project/main/Generate.java
acceleo_project/src/acceleo_project/Activator.java
acceleo_project/dst
acceleo_project/dst/RootElement
acceleo_project/build.properties
acceleo_project/tasks
acceleo_project/tasks/generate.xml
acceleo_project/tasks/generateTarget.xml
acceleo_project/.project
acceleo_project/bin
acceleo_project/bin/acceleo_project
acceleo_project/bin/acceleo_project/Activator.class
acceleo_project/bin/acceleo_project/main
acceleo_project/bin/acceleo_project/main/Generate.class
acceleo_project/bin/acceleo_project/main/generate.mtl
acceleo_project/bin/acceleo_project/main/generate.emtl
acceleo_project/.classpath
acceleo_project/META-INF
acceleo_project/META-INF/MANIFEST.MF

1 个答案:

答案 0 :(得分:0)

我不确定那里发生了什么,但我会猜测并说Acceleo无法解决SysML配置文件。

如果您查看生成的启动器(&#34; @ main&#34; mtl模板旁边的java文件),您将看到&#34; registerPackages&#34;方法。您需要找到正确的URI来注册SysML配置文件以便在您的应用程序中使用;您可以在the Acceleo FAQ上看到以前版本的纸莎草纸如何完成的示例。