在Eclipse UML2 3.1中,如果构造型B是构造型A的泛化,那么B是否继承了A的元类扩展?

时间:2012-02-17 16:32:39

标签: java eclipse uml xmi

直到最近,我才使用旧版本的Eclipse UML2(2.4)。更新到Eclipse UML2 3.1后,在尝试将从另一个构造型推广的构造型应用于相应扩展元类的元素时,我收到IllegalArgumentException。单步执行eclipse uml源表明,底层Ecore模型中缺少属性“base_Class”。

Java测试代码:

// Init a resource set to load the standard UML profiles
ResourceSet rset = null;
{
  rset = new ResourceSetImpl();

  rset.getPackageRegistry().put("http://www.eclipse.org/uml2/3.0.0/UML", UMLPackage.eINSTANCE);      

  // Register the UML resource factory
  rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

  // Get one of the standard profiles to build a jar path 
  final URL url = ClassLoader.getSystemResource("profiles/UML2.profile.uml");
  if(url == null) {
    throw new RuntimeException("Could not load 'profiles/UML2.profile.uml' from class path");
  }

  // Need the jarfile path so chop off the file specific stuff
  final String path = url.toExternalForm().split("!")[0] + "!/";

  // Build a uri for this path
  final URI baseURI = URI.createURI(path);


  // Build mappings from 'pathmap://UML_PROFILES' (or metamodels or libraries) to the point at the jarfile path
  final Map<URI,URI> uriMap = rset.getURIConverter().getURIMap();
  // pathmap://UML_PROFILES
  uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), baseURI.appendSegment("libraries").appendSegment(""));
  // pathmap://UML_LIBRARIES
  uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), baseURI.appendSegment("metamodels").appendSegment(""));
  // pathmap://UML_PROFILES
  uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), baseURI.appendSegment("profiles").appendSegment(""));
}

// Load the test profile
Profile test = null;
{
  final URL url = ClassLoader.getSystemResource("profiles/test.profile.uml");
  if(url == null) {
    throw new RuntimeException("Could not load 'profiles/test.profile.uml' from class path");
  }

  final Resource r = rset.createResource(URI.createURI(url.toExternalForm()));

  r.load(null);

  test = (Profile)EcoreUtil.getObjectByType(r.getContents(), UMLPackage.Literals.PROFILE);
  if(test == null) {
    throw new RuntimeException("Could not load 'profiles/test.profile.uml'");
  }
}

Stereotype A = test.getOwnedStereotype("A");
Stereotype B = test.getOwnedStereotype("B");

Model m = UMLFactory.eINSTANCE.createModel();

org.eclipse.uml2.uml.Package pkg = m.createNestedPackage("pkg");

org.eclipse.uml2.uml.Class c1 = pkg.createOwnedClass("c1", false);
org.eclipse.uml2.uml.Class c2 = pkg.createOwnedClass("c2", false);

pkg.applyProfile(test);

c1.applyStereotype(A);
c2.applyStereotype(B); // throws IllegalArgumentException

测试资料:

<?xml version="1.0" encoding="UTF-8"?>
<uml:Profile xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_17_0_1_1_57a01e4_1329493254282_739829_1797" name="test" metamodelReference="_17_0_1_1_57a01e4_1329493254285_456691_1798">
  <eAnnotations xmi:id="_RgZgwVl-EeG_l9KiXhjXuA" source="http://www.eclipse.org/uml2/2.0.0/UML">
    <contents xmi:type="ecore:EPackage" xmi:id="_RgZgwll-EeG_l9KiXhjXuA" name="test" nsURI="http:///schemas/test/_RgUBMFl-EeG_l9KiXhjXuA/0" nsPrefix="test">
      <eClassifiers xmi:type="ecore:EClass" xmi:id="_RgZgw1l-EeG_l9KiXhjXuA" name="A">
        <eAnnotations xmi:id="_RgZgxFl-EeG_l9KiXhjXuA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_17_0_1_1_57a01e4_1329493260539_647682_1799"/>
        <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_RgZgxVl-EeG_l9KiXhjXuA" name="base_Class" ordered="false" lowerBound="1">
          <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/3.0.0/UML#//Class"/>
        </eStructuralFeatures>
      </eClassifiers>
      <eClassifiers xmi:type="ecore:EClass" xmi:id="_RgZgx1l-EeG_l9KiXhjXuA" name="B" eSuperTypes="_RgZgw1l-EeG_l9KiXhjXuA">
        <eAnnotations xmi:id="_RgZgyFl-EeG_l9KiXhjXuA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_17_0_1_1_57a01e4_1329493272173_447751_1805"/>
      </eClassifiers>
    </contents>
  </eAnnotations>
  <packageImport xmi:id="_17_0_1_1_57a01e4_1329493254285_456691_1798">
    <importedPackage xmi:type="uml:Model" href="pathmap://UML_METAMODELS/UML.metamodel.uml#_0"/>
  </packageImport>
  <packageImport xmi:id="_0primitiveTypestest">
    <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
  </packageImport>
  <packageImport xmi:id="_0javaPrimitiveTypestest">
    <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/JavaPrimitiveTypes.library.uml#_0"/>
  </packageImport>
  <packagedElement xmi:type="uml:Stereotype" xmi:id="_17_0_1_1_57a01e4_1329493260539_647682_1799" name="A">
    <ownedAttribute xmi:id="_17_0_1_1_57a01e4_1329493385577_849191_1812" name="base_Class" visibility="private" association="_17_0_1_1_57a01e4_1329493385577_76750_1811">
      <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Stereotype" xmi:id="_17_0_1_1_57a01e4_1329493272173_447751_1805" name="B">
    <generalization xmi:id="_17_0_1_1_57a01e4_1329493436355_971859_1821" general="_17_0_1_1_57a01e4_1329493260539_647682_1799"/>
  </packagedElement>
  <packagedElement xmi:type="uml:Extension" xmi:id="_17_0_1_1_57a01e4_1329493385577_76750_1811" name="" memberEnd="_17_0_1_1_57a01e4_1329493385578_204693_1813 _17_0_1_1_57a01e4_1329493385577_849191_1812" navigableOwnedEnd="_17_0_1_1_57a01e4_1329493385578_204693_1813">
    <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_17_0_1_1_57a01e4_1329493385578_204693_1813" name="extension_A" visibility="private" type="_17_0_1_1_57a01e4_1329493260539_647682_1799" aggregation="composite" association="_17_0_1_1_57a01e4_1329493385577_76750_1811">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_17_0_1_1_57a01e4_1329493385578_803186_1815" name="" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_17_0_1_1_57a01e4_1329493385578_297198_1814" name=""/>
    </ownedEnd>
  </packagedElement>
</uml:Profile>

1 个答案:

答案 0 :(得分:0)

这只是一个错误。报告它,如果上帝会帮助你: - )