До недавнего времени я использовал более старую версию Eclipse UML2 (2.4), где это работало. После обновления до Eclipse UML2 3.1 я получаю исключение IllegalArgumentException при попытке применить стереотип, обобщенный из другого стереотипа, к элементу соответствующего расширенного метакласса. Проход по источнику eclipse uml показал, что атрибут «base_Class» отсутствовал в базовой модели Ecore для стереотипа.
Тестовый код 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>