Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Removing metaclass reference and extension?(question about stereotype modeling)
Removing metaclass reference and extension? [message #503595] Mon, 14 December 2009 15:37 Go to next message
Thomas Neustupny is currently offline Thomas Neustupny
Messages: 75
Registered: October 2009
Member
This code extends a stereotype:
            org.eclipse.uml2.uml.Class metaclass = getMetaclass(...);
            Profile profile = stereo.getProfile();
            if (metaclass != null && profile != null) {
                profile.createMetaclassReference(metaclass);
                stereo.createExtension(metaclass, false);
                return;
            }

But how can I later reverse that? This doesn't work:
            org.eclipse.uml2.uml.Class metaclass = getMetaclass(...);
            Profile profile = stereo.getProfile();
            if (metaclass != null && profile != null) {
                for (Extension ext : profile.getOwnedExtensions(false)) {
                    if (ext.getMetaclass() == metaclass
                            && ext.getEndTypes().contains(stereo)) {
                        stereo.getExtendedMetaclasses().remove(metaclass); // throws exception!
                        profile.getOwnedExtensions(false).remove(ext); // throws exception!
                        break;
                    }
                }
            }
Re: Removing metaclass reference and extension? [message #504283 is a reply to message #503595] Thu, 17 December 2009 23:27 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn Hussey
Messages: 1618
Registered: July 2009
Senior Member
The list of extended metaclasses for a stereotype isn't meant to be modified directly. Instead, consider obtaining a reference to the extension (a special kind of association) and destroying it via the Element#destroy() method.

Kenn
Re: Removing metaclass reference and extension? [message #504522 is a reply to message #504283] Mon, 21 December 2009 03:38 Go to previous messageGo to next message
Thomas Neustupny is currently offline Thomas Neustupny
Messages: 75
Registered: October 2009
Member
Kenn Hussey wrote on Thu, 17 December 2009 23:27
The list of extended metaclasses for a stereotype isn't meant to be modified directly. Instead, consider obtaining a reference to the extension (a special kind of association) and destroying it via the Element#destroy() method.


This one works, thank you very much Kenn!!!

However, many fragments remain in the model, so some additional cleanup is needed. Report will follow.

Thomas
Re: Removing metaclass reference and extension? [message #504693 is a reply to message #504522] Mon, 21 December 2009 22:55 Go to previous message
Thomas Neustupny is currently offline Thomas Neustupny
Messages: 75
Registered: October 2009
Member
With calling destroy() on the extension, the referencing attribute remains in the stereotype, so this must be destroyed, too. Here is my final working code:
            org.eclipse.uml2.uml.Class metaclass = getMetaclass(...);
            Profile profile = stereo.getProfile();
            if (metaclass != null && profile != null) {
                for (Extension ext : profile.getOwnedExtensions(false)) {
                    if (ext.getMetaclass() == metaclass
                            && ext.getEndTypes().contains(stereo)) {
                        for (Property p : stereo.getAttributes()) {
                            Association assoc = p.getAssociation();
                            if (assoc != null && assoc == ext) {
                                // additional cleanup needed, because
                                // this would not be removed by ext.destroy():
                                p.destroy();
                                break;
                            }
                        }
                        // remove base class by destroying the extension
                        ext.destroy();
                        break;
                    }
                }
            }
Previous Topic:Extending UML
Next Topic:Removing metaclass reference and extension?
Goto Forum:
  


Current Time: Sat Aug 23 01:33:14 EDT 2014

Powered by FUDForum. Page generated in 0.01817 seconds