Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Removing metaclass reference and extension?
Removing metaclass reference and extension? [message #628120] Mon, 14 December 2009 20:37 Go to next message
Thomas Neustupny is currently offline Thomas NeustupnyFriend
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 #628136 is a reply to message #628120] Fri, 18 December 2009 04:27 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
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 #628143 is a reply to message #628136] Mon, 21 December 2009 08:38 Go to previous messageGo to next message
Thomas Neustupny is currently offline Thomas NeustupnyFriend
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 #628144 is a reply to message #628143] Tue, 22 December 2009 03:55 Go to previous message
Thomas Neustupny is currently offline Thomas NeustupnyFriend
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:Removing metaclass reference and extension?
Next Topic:Extend Infrastructure.uml
Goto Forum:
  


Current Time: Fri Apr 19 00:35:13 GMT 2024

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

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

Back to the top