Skip to main content



      Home
Home » Modeling » UML2 » Find stereotypes applicable to instances of EClass?
Find stereotypes applicable to instances of EClass? [message #479543] Tue, 11 August 2009 09:57 Go to next message
Eclipse UserFriend
Hi,
given an EClass, corresponding to an UML meta-class, and a stereotype, I wonder what is the most elegant way to find out
whether the stereotype is applicable to an instances of this EClass?
Any ideas?

Thanks for helping

Joel
Re: Find stereotypes applicable to instances of EClass? [message #479545 is a reply to message #479543] Tue, 11 August 2009 10:06 Go to previous messageGo to next message
Eclipse UserFriend
Hey,

what about:

Element element = (Element)UMLFactory.create(eclass);
final boolean isApplicable = element.isStereotypeApplicable(stereo);

Timothy

Joel Greenyer schrieb:
> Hi,
> given an EClass, corresponding to an UML meta-class, and a stereotype, I
> wonder what is the most elegant way to find out whether the stereotype
> is applicable to an instances of this EClass?
> Any ideas?
>
> Thanks for helping
>
> Joel
Re: Find stereotypes applicable to instances of EClass? [message #479559 is a reply to message #479545] Tue, 11 August 2009 10:30 Go to previous messageGo to next message
Eclipse UserFriend
Timothy,
thanks for the quick answer.
Your idea is not bad. However, what happens in case that the EClass is an abstract class?

The next thing that confuses me--but that's probably a whole different problem--is that wrong elements are created when
I hand the EClass to the UMLFactory. E.g. I have the EClass 'Class' and get an instance of 'Signal'. Any idea why that
may be?

Thanks

Joel


Timothy Marc wrote:
> Hey,
>
> what about:
>
> Element element = (Element)UMLFactory.create(eclass);
> final boolean isApplicable = element.isStereotypeApplicable(stereo);
>
> Timothy
>
> Joel Greenyer schrieb:
>> Hi,
>> given an EClass, corresponding to an UML meta-class, and a stereotype,
>> I wonder what is the most elegant way to find out whether the
>> stereotype is applicable to an instances of this EClass?
>> Any ideas?
>>
>> Thanks for helping
>>
>> Joel
Re: Find stereotypes applicable to instances of EClass? [message #479595 is a reply to message #479559] Tue, 11 August 2009 12:24 Go to previous messageGo to next message
Eclipse UserFriend
I solved my problem as follows:

suppose I have EClass eClass and the Stereotype stereotype, then I add all stereotypes applicable to instances of the
EClass to an array list:

/*
* When is a stereotye applicable to instances of eClass?
*
* 1. when the eClass equals an extended meta-class of the stereotype
* 2. when the eClass is a subclass of the extended meta-class of the stereotype
* <=> the extended meta-class is in the set of superclasses of eClass
*/
ArrayList<Stereotype> applicableStereotypesList = new ArrayList<Stereotype>();
for (Class extendedMetaClass : stereotype.getAllExtendedMetaclasses()) {
EClassifier eExtendedMetaClass = UMLFactory.eINSTANCE.getEPackage().getEClassifier(extendedMe taClass.getName());
// 1.
if (eExtendedMetaClass == eClass){
applicableStereotypesList.add(stereotype);
break;
}
// 2.
if (eClass.getEAllSuperTypes().contains(eExtendedMetaClass)){
applicableStereotypesList.add(stereotype);
break;
}
}


Joel Greenyer wrote:
> Timothy,
> thanks for the quick answer.
> Your idea is not bad. However, what happens in case that the EClass is
> an abstract class?
>
> The next thing that confuses me--but that's probably a whole different
> problem--is that wrong elements are created when I hand the EClass to
> the UMLFactory. E.g. I have the EClass 'Class' and get an instance of
> 'Signal'. Any idea why that may be?
>
> Thanks
>
> Joel
>
>
> Timothy Marc wrote:
>> Hey,
>>
>> what about:
>>
>> Element element = (Element)UMLFactory.create(eclass);
>> final boolean isApplicable = element.isStereotypeApplicable(stereo);
>>
>> Timothy
>>
>> Joel Greenyer schrieb:
>>> Hi,
>>> given an EClass, corresponding to an UML meta-class, and a
>>> stereotype, I wonder what is the most elegant way to find out whether
>>> the stereotype is applicable to an instances of this EClass?
>>> Any ideas?
>>>
>>> Thanks for helping
>>>
>>> Joel
Re: Find stereotypes applicable to instances of EClass? [message #479627 is a reply to message #479595] Tue, 11 August 2009 14:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi Joel,

even though it looks quite the same, I post my solution here as well,
because I think such methods should make it into the eclipse UML API:


boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
{
for(Property attribute : stereotype.getAllAttributes())
{
if(attribute.getAssociation() instanceof Extension)
{
Type type = attribute.getType();
EClassifier eClassifier = UMLPackage.eINSTANCE
.getEClassifier(type.getName());
if(eClassifier instanceof EClass &&
((EClass) eClassifier).isSuperTypeOf(eClass))
{
return true;
}
}
}
return false;
}


It assumes the Stereotype is properly defined and is inspired by
ElementOperations.isApplicableStereotype.

Greetings to Paderborn from Kassel,
Christian
Re: Find stereotypes applicable to instances of EClass? [message #479706 is a reply to message #479627] Wed, 12 August 2009 02:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
thanks for the comment. Do you have a reason not to use stereotype.getAllExtendedMetaclasses()?
Indeed I was missing such a method in the UML API.

Greetings from Paderborn to Kassel

Joel

Christian Schneider wrote:
> Hi Joel,
>
> even though it looks quite the same, I post my solution here as well,
> because I think such methods should make it into the eclipse UML API:
>
>
> boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
> {
> for(Property attribute : stereotype.getAllAttributes())
> {
> if(attribute.getAssociation() instanceof Extension)
> {
> Type type = attribute.getType();
> EClassifier eClassifier = UMLPackage.eINSTANCE
> .getEClassifier(type.getName());
> if(eClassifier instanceof EClass &&
> ((EClass) eClassifier).isSuperTypeOf(eClass))
> {
> return true;
> }
> }
> }
> return false;
> }
>
>
> It assumes the Stereotype is properly defined and is inspired by
> ElementOperations.isApplicableStereotype.
>
> Greetings to Paderborn from Kassel,
> Christian
Re: Find stereotypes applicable to instances of EClass? [message #479724 is a reply to message #479706] Wed, 12 August 2009 04:03 Go to previous message
Eclipse UserFriend
Joel Greenyer wrote:
> thanks for the comment. Do you have a reason not to use
> stereotype.getAllExtendedMetaclasses()?
Well, the reason is, that ElementOperations.isApplicableStereotype did
not use it. But looking into the implementation it seems to be
equivalent so using getAllExtendedMetaclasses is even better as it's
shorter.

/Christian
Re: Find stereotypes applicable to instances of EClass? [message #627869 is a reply to message #479543] Tue, 11 August 2009 10:06 Go to previous message
Eclipse UserFriend
Hey,

what about:

Element element = (Element)UMLFactory.create(eclass);
final boolean isApplicable = element.isStereotypeApplicable(stereo);

Timothy

Joel Greenyer schrieb:
> Hi,
> given an EClass, corresponding to an UML meta-class, and a stereotype, I
> wonder what is the most elegant way to find out whether the stereotype
> is applicable to an instances of this EClass?
> Any ideas?
>
> Thanks for helping
>
> Joel
Re: Find stereotypes applicable to instances of EClass? [message #627870 is a reply to message #479545] Tue, 11 August 2009 10:30 Go to previous message
Eclipse UserFriend
Timothy,
thanks for the quick answer.
Your idea is not bad. However, what happens in case that the EClass is an abstract class?

The next thing that confuses me--but that's probably a whole different problem--is that wrong elements are created when
I hand the EClass to the UMLFactory. E.g. I have the EClass 'Class' and get an instance of 'Signal'. Any idea why that
may be?

Thanks

Joel


Timothy Marc wrote:
> Hey,
>
> what about:
>
> Element element = (Element)UMLFactory.create(eclass);
> final boolean isApplicable = element.isStereotypeApplicable(stereo);
>
> Timothy
>
> Joel Greenyer schrieb:
>> Hi,
>> given an EClass, corresponding to an UML meta-class, and a stereotype,
>> I wonder what is the most elegant way to find out whether the
>> stereotype is applicable to an instances of this EClass?
>> Any ideas?
>>
>> Thanks for helping
>>
>> Joel
Re: Find stereotypes applicable to instances of EClass? [message #627871 is a reply to message #479559] Tue, 11 August 2009 12:24 Go to previous message
Eclipse UserFriend
I solved my problem as follows:

suppose I have EClass eClass and the Stereotype stereotype, then I add all stereotypes applicable to instances of the
EClass to an array list:

/*
* When is a stereotye applicable to instances of eClass?
*
* 1. when the eClass equals an extended meta-class of the stereotype
* 2. when the eClass is a subclass of the extended meta-class of the stereotype
* <=> the extended meta-class is in the set of superclasses of eClass
*/
ArrayList<Stereotype> applicableStereotypesList = new ArrayList<Stereotype>();
for (Class extendedMetaClass : stereotype.getAllExtendedMetaclasses()) {
EClassifier eExtendedMetaClass = UMLFactory.eINSTANCE.getEPackage().getEClassifier(extendedMe taClass.getName());
// 1.
if (eExtendedMetaClass == eClass){
applicableStereotypesList.add(stereotype);
break;
}
// 2.
if (eClass.getEAllSuperTypes().contains(eExtendedMetaClass)){
applicableStereotypesList.add(stereotype);
break;
}
}


Joel Greenyer wrote:
> Timothy,
> thanks for the quick answer.
> Your idea is not bad. However, what happens in case that the EClass is
> an abstract class?
>
> The next thing that confuses me--but that's probably a whole different
> problem--is that wrong elements are created when I hand the EClass to
> the UMLFactory. E.g. I have the EClass 'Class' and get an instance of
> 'Signal'. Any idea why that may be?
>
> Thanks
>
> Joel
>
>
> Timothy Marc wrote:
>> Hey,
>>
>> what about:
>>
>> Element element = (Element)UMLFactory.create(eclass);
>> final boolean isApplicable = element.isStereotypeApplicable(stereo);
>>
>> Timothy
>>
>> Joel Greenyer schrieb:
>>> Hi,
>>> given an EClass, corresponding to an UML meta-class, and a
>>> stereotype, I wonder what is the most elegant way to find out whether
>>> the stereotype is applicable to an instances of this EClass?
>>> Any ideas?
>>>
>>> Thanks for helping
>>>
>>> Joel
Re: Find stereotypes applicable to instances of EClass? [message #627872 is a reply to message #479595] Tue, 11 August 2009 14:44 Go to previous message
Eclipse UserFriend
Hi Joel,

even though it looks quite the same, I post my solution here as well,
because I think such methods should make it into the eclipse UML API:


boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
{
for(Property attribute : stereotype.getAllAttributes())
{
if(attribute.getAssociation() instanceof Extension)
{
Type type = attribute.getType();
EClassifier eClassifier = UMLPackage.eINSTANCE
.getEClassifier(type.getName());
if(eClassifier instanceof EClass &&
((EClass) eClassifier).isSuperTypeOf(eClass))
{
return true;
}
}
}
return false;
}


It assumes the Stereotype is properly defined and is inspired by
ElementOperations.isApplicableStereotype.

Greetings to Paderborn from Kassel,
Christian
Re: Find stereotypes applicable to instances of EClass? [message #627873 is a reply to message #479627] Wed, 12 August 2009 02:55 Go to previous message
Eclipse UserFriend
Hi Christian,
thanks for the comment. Do you have a reason not to use stereotype.getAllExtendedMetaclasses()?
Indeed I was missing such a method in the UML API.

Greetings from Paderborn to Kassel

Joel

Christian Schneider wrote:
> Hi Joel,
>
> even though it looks quite the same, I post my solution here as well,
> because I think such methods should make it into the eclipse UML API:
>
>
> boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
> {
> for(Property attribute : stereotype.getAllAttributes())
> {
> if(attribute.getAssociation() instanceof Extension)
> {
> Type type = attribute.getType();
> EClassifier eClassifier = UMLPackage.eINSTANCE
> .getEClassifier(type.getName());
> if(eClassifier instanceof EClass &&
> ((EClass) eClassifier).isSuperTypeOf(eClass))
> {
> return true;
> }
> }
> }
> return false;
> }
>
>
> It assumes the Stereotype is properly defined and is inspired by
> ElementOperations.isApplicableStereotype.
>
> Greetings to Paderborn from Kassel,
> Christian
Re: Find stereotypes applicable to instances of EClass? [message #627874 is a reply to message #479706] Wed, 12 August 2009 04:03 Go to previous message
Eclipse UserFriend
Joel Greenyer wrote:
> thanks for the comment. Do you have a reason not to use
> stereotype.getAllExtendedMetaclasses()?
Well, the reason is, that ElementOperations.isApplicableStereotype did
not use it. But looking into the implementation it seems to be
equivalent so using getAllExtendedMetaclasses is even better as it's
shorter.

/Christian
Previous Topic:Find stereotypes applicable to instances of EClass?
Next Topic:[Announce] MDT UML2 3.1.0M1 is available
Goto Forum:
  


Current Time: Sun Jul 06 00:13:47 EDT 2025

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

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

Back to the top