If stereotype B is a generalization of stereotype A, does B inherit the meta-class [message #800892] |
Fri, 17 February 2012 16:48 |
Lance Gatlin Messages: 1 Registered: February 2012 |
Junior Member |
|
|
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("...", UMLPackage.eINSTANCE); // Forum filter prevents me from posting this: h_t_t_p_:_/_/www.eclipse.org/uml2/3.0.0/UML
// 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 is attached.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02693 seconds