在 Eclipse UML2 3.1 中,如果构造型 B 是构造型 A 的泛化,那么 B 是否继承 A 的元类扩展?
直到最近,我还在使用旧版本的 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>
Until recently I was using an older version of Eclipse UML2 (2.4) where this worked. After updating to Eclipse UML2 3.1, I receive an IllegalArgumentException when attempting to apply a stereotype generalized from another stereotype to an element of the appropriate extended meta-class. Stepping through the eclipse uml source showed that the attribute "base_Class" was missing in the underlying Ecore model for the stereotype.
Java test code:
// 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
Test profile:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是一个错误。举报,也许上帝会帮助你:-)
This is just a bug. Report it and if maybe god will help you :-)