Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » If stereotype B is a generalization of stereotype A, does B inherit the meta-class(In Eclipse UML2 3.1, if stereotype B is a generalization of stereotype A, does B inherit the meta-class extension of A?)
If stereotype B is a generalization of stereotype A, does B inherit the meta-class [message #800892] Fri, 17 February 2012 16:48 Go to next message
Lance Gatlin is currently offline Lance GatlinFriend
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.
Re: If stereotype B is a generalization of stereotype A, does B inherit the meta-class [message #803776 is a reply to message #800892] Tue, 21 February 2012 19:56 Go to previous message
Carsten Reckord is currently offline Carsten ReckordFriend
Messages: 139
Registered: July 2009
Senior Member
Hi Lance,

This should work perfectly fine. B does inherit the extension and applying
the stereotypes should work.

On 17.02.2012 17:48, Lance Gatlin wrote:
> 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.

You can see in your test.profile.uml that the base_Class property is there
in the ecore model.

I ran your example code and only had to adjust the base URI part a bit
because in my setup, the models were not found on the system classpath.
After that, your code worked perfectly for me with Eclipse UML2 3.2.100.

Best regards,
Carsten
Previous Topic:3rd Biannual Eclipse/OMG Workshop on March 25
Next Topic:Sources for current Indigo 3.2.100 version in git
Goto Forum:
  


Current Time: Thu Apr 25 10:09:21 GMT 2024

Powered by FUDForum. Page generated in 0.02693 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top