Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Notification problem with class package(Notification problem when the package of a class changed)
Notification problem with class package [message #1393806] Fri, 04 July 2014 09:41 Go to next message
Justin Trentesaux is currently offline Justin TrentesauxFriend
Messages: 2
Registered: July 2014
Junior Member
Hi,

I use the UML2 implementation in my project and I want to be notified when the package of a class changed.
For illutrate my problem, I wrote the following code:

Model model = UMLFactory.eINSTANCE.createModel();
model.setName("model");
Package package1 = model.createNestedPackage("package1");
Package package2 = model.createNestedPackage("package2");
Class class1 = package1.createOwnedClass("Class1", false);

class1.eAdapters().add(new AdapterImpl() {
	@Override
	public void notifyChanged(Notification notification)
	{
		super.notifyChanged(notification);
		
		if(notification.isTouch()) 
		{
		   return;
		}
		
		System.out.println("Notification received");
	}
});

class1.setPackage(package2); 
// same problem with 'package2.getPackagedElements().add(class1)'


The problem is that my observer (adapter) is never notified by the class that its package has changed.
Am I doing something wrong? Or this is a bug in the UML implementation?

Regards,
Justin
Re: Notification problem with class package [message #1393977 is a reply to message #1393806] Fri, 04 July 2014 15:21 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Justin,

The setPackage(Package) implementation inherited by the implementation
of Class looks like this:

public void setPackage(org.eclipse.uml2.uml.Package newPackage) {
if (newPackage != eInternalContainer()) {
if (EcoreUtil.isAncestor(this, newPackage))
throw new IllegalArgumentException(
"Recursive containment not allowed for " + toString()); //$NON-NLS-1$
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newPackage != null)
msgs = ((InternalEList<Type>) newPackage.getOwnedTypes())
.basicAdd(this, msgs);
msgs = eBasicSetContainer((InternalEObject) newPackage,
InternalEObject.EOPPOSITE_FEATURE_BASE
- UMLPackage.PACKAGE__PACKAGED_ELEMENT, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.CLASSIFIER__PACKAGE, newPackage, newPackage));
}

As you can see, the class will notify the change in its package
property if the package is being set to the same package that is
already referenced (generating a "touch" notification). In all other
cases, you will get notification of the Package::packagedElement
collection changing in both the old and new packages and this will
produce also notifications for whatever reference is the opposite of
Package::packagedElement. Unfortunately, there is no opposite in this
case, so you will only get notifications from the packages.

This looks to me like an oversight in the codegen template for
container references like this. I'd suggest raising an enhancement
request in bugzilla. At the very least, it seems inconsistent to me
that setPackage() will sometimes notify a Classifier::package "change"
and sometimes not.

HTH,

Christian


On 2014-07-04 14:40:02 +0000, Justin Trentesaux said:

> Hi,
>
> I use the UML2 implementation in my project and I want to be notified
> when the package of a class changed.
> For illutrate my problem, I wrote the following code:
>
>
> Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("model");
> Package package1 = model.createNestedPackage("package1");
> Package package2 = model.createNestedPackage("package2");
> Class class1 = package1.createOwnedClass("Class1", false);
>
> class1.eAdapters().add(new AdapterImpl() {
> @Override
> public void notifyChanged(Notification notification)
> {
> super.notifyChanged(notification);
>
> if(notification.isTouch()) {
> return;
> }
>
> System.out.println("Notification received");
> }
> });
>
> class1.setPackage(package2); // same problem with
> 'package2.getPackagedElements().add(class1)'
>
>
> The problem is that my observer (adapter) is never notified by the
> class that its package has changed.
> Am I doing something wrong? Or this is a bug in the UML implementation?
>
> Regards,
> Justin
Re: Notification problem with class package [message #1397993 is a reply to message #1393977] Thu, 10 July 2014 12:57 Go to previous message
Justin Trentesaux is currently offline Justin TrentesauxFriend
Messages: 2
Registered: July 2014
Junior Member
Hi Christian,

Thanks for your explanation.
Well as you recommend me I will raise an enhancement in bugzilla.

Regards,
Justin
Previous Topic:IntroductionToUMLProfiles Question
Next Topic:Documentation of the UML2/EMF codegen
Goto Forum:
  


Current Time: Thu Mar 28 09:47:29 GMT 2024

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

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

Back to the top