Skip to main content



      Home
Home » Modeling » QVT-OML » Generalization relationship between stereotypes
Generalization relationship between stereotypes [message #1058852] Wed, 15 May 2013 08:08 Go to next message
Eclipse UserFriend
Hello,

Let's say that I have a UML profile defining a base stereotype called MyBaseStereo; the profile also defines a specialization of it, called MyDerivedStereo.

Now, let's say that I have an UML Model processed by a QVTo transform; in this Model I have a Class which I want to be stereotyped as MyDerivedStereo, because, conceptually, the Class _is_a_ MyDerivedStereo (and in turn is also a MyBaseStereo).

I apply the stereotype as myClass.applyStereotype(MyDerivedStereo) and it is correctly recognized as applied, but if I call myClass.isStereoTypeApplied(MyBaseStereo), this one returns false. Why this? How does the generalization relationship work for stereotypes?

EDIT: I forgot to say that if I apply the stereotype MyDerivedStereo, I'm also able to set values for properties defined in the base stereotype (myClass.setValue(MyBaseStereo, "attribute", attributeValue). Therefore, the base stereotype _is_ applied. But I'm not able to "detect" this fact by using myClass.isStereoTypeApplied(MyBaseStereo), and it becomes a pain when I want to select all the classes from a set that _are_ MyBaseStereo elements (stereotyped, e.g., as MyDerivedStereo1, MyDerivedStereo2, etc., that derive from MyBaseStereo) and that are collected in a set with other classes that are not stereotyped that way. Maybe is isStereoTypeApplied() not the right function to call?

--
Matteo

[Updated on: Thu, 16 May 2013 05:22] by Moderator

Re: Generalization relationship between stereotypes [message #1060413 is a reply to message #1058852] Fri, 24 May 2013 10:20 Go to previous messageGo to next message
Eclipse UserFriend
The problem is that generalization doesn't work for UML stereotypes. Operation .isStereoTypeApplied(..) is provided by UML and implemented in Element class. Below is code snippet for the operation:

	public boolean isStereotypeApplied(Stereotype stereotype) {
		return ElementOperations.isStereotypeApplied(this, stereotype);
	}
	public static boolean isStereotypeApplied(Element element, Stereotype stereotype) {
		return element.getStereotypeApplication(stereotype) != null;
	}
	public EObject getStereotypeApplication(Stereotype stereotype) {
		return ElementOperations.getStereotypeApplication(this, stereotype);
	}
	public static EObject getStereotypeApplication(Element element, Stereotype stereotype) {
		for (EObject stereotypeApplication : element.getStereotypeApplications()) {
			if (getStereotype(stereotypeApplication) == stereotype) {
				return stereotypeApplication;
			}
		}
		return null;
	}


As you can see UML directly compares stereotype instances. I propose to implement simple helper that considers generalization:

helper Element::isStereotypeAppliedEx(s : Stereotype) : Boolean {
	self.getApplicableStereotypes()->forEach(i) {
		if (i.general->includes(s)) then {
			return true;
		} endif;
	};
	return false;
}


Regards,
Sergey
Re: Generalization relationship between stereotypes [message #1060450 is a reply to message #1058852] Fri, 24 May 2013 13:02 Go to previous messageGo to next message
Eclipse UserFriend
Hi

IMHO Sterteotype generalization should work and the MDT/UML2 library
endeavours to support them and so MMT/QVTo should just work since it
just reuses MDT/UML2.

I suggest doing some Java API experiments with MDT/UML2 to see what
actually happens.

Regards

Ed Willink



On 15/05/2013 13:08, Matteo M. wrote:
> Hello,
>
> Let's say that I have a UML profile defining a base stereotype called
> MyBaseStereo; the profile also defines a specialization of it, called
> MyDerivedStereo.
>
> Now, let's say that I have an UML Model processed by a QVTo transform;
> in this Model I have a Class which I want to be stereotyped as
> MyDerivedStereo, because, conceptually, the Class _is_a_
> MyDerivedStereo (and in turn is also a MyBaseStereo).
>
> I apply the stereotype as myClass.applyStereotype(MyDerivedStereo) and
> it is correctly recognized as applied, but if I call
> myClass.isStereoTypeApplied(MyBaseStereo), this one returns false. Why
> this? How does the generalization relationship work for stereotypes?
>
> --
> Matteo
Re: Generalization relationship between stereotypes [message #1060516 is a reply to message #1060450] Sat, 25 May 2013 18:08 Go to previous message
Eclipse UserFriend
Hi,

Let's consider mentioned hierarchy of stereotypes (MyDerivedStereo extends MyBaseStereo) and given that MyDerivedStereo is applied to myClass with 'myClass.applyStereotype(MyDerivedStereo)' function call.

Code snippet I gave was taken from the 'org.eclipse.uml2.uml_4.1.0' plug-in. It clearly shows that UML implementation doesn't consider stereotypes' hierarchy in method .isStereotypeApplied().
On the other side for property which is defined in MyBaseStereo stereotype the .getValue(MyDerivedStereo, "propertyFromBase") call returns correct value.
The reason is that UML operates on 'eAllStructuralFeatures' in stereotype therefore takes into account properties from the base stereotype.

In other words while .isStereotypeApplied(MyBaseStereo) returns 'false' the method .getValue(MyDerivedStereo, "propertyFromBase") / .setValue(MyDerivedStereo, "propertyFromBase") correctly
operates with the properties from the base stereotype.

Note that in QVT snippet I gave I made typo and method 'getAppliedStereotypes()' should be used instead of 'getApplicableStereotypes()'.

Regards,
Sergey
Previous Topic:[Announce] Eclipse QVT Operational 3.3.0 (Kepler) RC1 is now available
Next Topic:Stereotypes and multi-valued attributes
Goto Forum:
  


Current Time: Tue Jul 22 22:42:13 EDT 2025

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

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

Back to the top