Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to get instance of stereotype as generated ecore class instance
How to get instance of stereotype as generated ecore class instance [message #1790507] Tue, 12 June 2018 06:01 Go to next message
Randall Hudson is currently offline Randall HudsonFriend
Messages: 2
Registered: June 2018
Junior Member
If I create a UML profile, and then generate the Ecore representation and its generated code we get a java interface and class for each stereotype in the profile. Now if I apply the profile to a UML model, and then apply one of its stereotypes to some element, lets say component A, I would like to programatically take A as input and be able to get the instance of the java class generated for that stereotype.

I have been spinning my wheels on this for a while now and I suspect either that it is not possible or (more likely) I am misunderstanding something about how to use UML profiles. Any help would be appreciated. If you need more information to help, just let me know and I will explain what I am doing in more detail.

Thanks for your time.
-Randall
Re: How to get instance of stereotype as generated ecore class instance [message #1790548 is a reply to message #1790507] Tue, 12 June 2018 17:56 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Randall,

An Element to which stereotypes are applied can provide the EObject implementations of those stereotype instances via the Element::getStereotypeApplications() operation. These EObjects, in turn, provide their EClasses via the EObject::eClass() operation. And an EClass provides the generated Java interface that it represents via EClass::getInstanceClass().

Also, the Element::getStereotypeApplication(Stereotype) operation finds the particular instance of an applied stereotype if you know which one you're looking for.

HTH,

Christian
Re: How to get instance of stereotype as generated ecore class instance [message #1790573 is a reply to message #1790507] Wed, 13 June 2018 07:30 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi,

There's also a shortcut from UMLUtil:

UMLUtil.getStereotypeApplication(Element, Class<T>)

Where Class<T> is your generated stereotype interface.

MyStereotype s = UMLUtil.getStereotypeApplication(myComponentA, MyStereotype.class);


HTH,
Camille


Camille Letavernier
Re: How to get instance of stereotype as generated ecore class instance [message #1793795 is a reply to message #1790573] Thu, 16 August 2018 02:02 Go to previous message
Randall Hudson is currently offline Randall HudsonFriend
Messages: 2
Registered: June 2018
Junior Member
I forgot to reply earlier, but just wanted to say thanks for the help. It solved my problem.
Previous Topic:XML/XMI import/export issues?
Next Topic:reference to attribute in tagged value
Goto Forum:
  


Current Time: Thu Apr 18 03:54:39 GMT 2024

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

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

Back to the top