本文介绍了如何使用 Acceleo 检查 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 的构造型.

I'm using Eclipse 4.6.3 (Neon.3) with Acceleo 3.6.6, Paprus 2.0.3 and Papyrus SysML 1.4 0.10.1.How can I check from an Acceleo MTL script, whether a class of my model has the SysML Block stereotype applied? The method getAppliedStereotypes() only works for my own defined stereotypes but not for SysML 1.4 ones.

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

In my UML model (Papyrus project) I have created

  • Class1",我通过配置文件"/更新配置文件"和

  • "Class1" to which I have applied my own stereotype "MyProfile::MyStereotype" created in the "Model Explorer" via "Profile"/"Update Profile" and

我在属性"/配置文件"/应用构造型"下应用了SysML::Blocks::Block"的Class2"

"Class2" to which I have applied "SysML::Blocks::Block" under "Properties"/"Profile"/"Applied stereotypes"

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

In the Acceleo project in generate.mtl, if I'm calling getAppliedStereotypes() on each of these 2 classes, I only get the stereotype of "Class1", but none for "Class2".

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:

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:

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

推荐答案

我不确定那里发生了什么,但我会大胆猜测并说 Acceleo 无法解析此处的 SysML 配置文件.

I'm not really sure what's happening in there but I'll take a wild guess and say Acceleo cannot resolve the SysML profile here.

如果您查看生成的启动器(@main"mtl 模板旁边的 java 文件),您将看到registerPackages"方法.您需要找到正确的 URI 来注册在您的应用程序中使用的 SysML 配置文件;您可以在 the Acceleo FAQ.

If you look at your generated launcher (the java file beside your "@main" mtl template), you will see a "registerPackages" method. You will need to find the proper URI to register the SysML profile for use in your application; you can see an example of how it was done for previous versions of papyrus on the Acceleo FAQ.

这篇关于如何使用 Acceleo 检查 SysML 构造型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 02:24