Skip to main content



      Home
Home » Modeling » UML2 » how to setValue() of a stereotype property that refers to another stereotype
how to setValue() of a stereotype property that refers to another stereotype [message #1722930] Wed, 10 February 2016 05:50 Go to next message
Eclipse UserFriend
Hi all,

I created a UML profile that has a stereotype (e.g. S1) with a property (s2_reference) that refers to another stereotype (S2). An example:

|-------------------------|
|<<Stereotype>> |
| S1 |
|-------------------------|
|label: String |
|s2_ref: S2 |
|-------------------------|

This stereotype is applied to a NamedElement in UML and I'm able to set the property value for types like String, Boolean, Integer. Example for property label, this code works:

namedElement.setValue(S1, labelProperty.getName, "Some String Object");

However, I'm not sure how to create an object for stereotype S2 in order to set value for property s2_ref:

namedElement.setValue(S1, s2refProperty.getName, ??);

I have tried to get to get an EObject:

EObject s2Object = s1.getStereotypeApplication(s2);

But this returns null. How do I create an instance of stereotype S2?

Many thanks,
Rajiv
Re: how to setValue() of a stereotype property that refers to another stereotype [message #1722939 is a reply to message #1722930] Wed, 10 February 2016 06:22 Go to previous messageGo to next message
Eclipse UserFriend
Solved! So basically the ''create'' method for Profile does the trick:

EObject s2Object = profile.create(S2);

Takes in the stereotype S2 as its parameter creates an object.

This can be set as the value for s2_ref property in stereotype S1.

namedElement.setValue(S1, s2refProperty.getName, s2Object);

I was stuck on this silliness for a whole day, happy it works.

Many thanks
Rajiv
Re: how to setValue() of a stereotype property that refers to another stereotype [message #1722957 is a reply to message #1722939] Wed, 10 February 2016 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Rajiv,

I think you might rather use the Profile::create(Classifier) API only
for creating instances of Classes defined in your profile. Instances
of Stereotypes must always be applied to some element in the model, and
the way to do that is by either taking the result of the
Element::applyStereotype(Stereotype) method or
Element::getStereotypeApplication(Stereotype) for a stereotype that is
already applied.

The procedure that you sketched in your post will result in a dangling
instance of the S2 stereotype that isn't applied to any element.

HTH,

Christian


On 2016-02-10 11:22:13 +0000, Rajiv Murali said:

> Solved! So basically the ''create'' method for Profile does the trick:
>
> EObject s2Object = profile.create(S2);
>
> Takes in the stereotype S2 as its parameter creates an object.
>
> This can be set as the value for s2_ref property in stereotype S1.
>
> namedElement.setValue(S1, s2refProperty.getName, s2Object);
>
> I was stuck on this silliness for a whole day, happy it works.
>
> Many thanks
> Rajiv
Re: how to setValue() of a stereotype property that refers to another stereotype [message #1722980 is a reply to message #1722957] Wed, 10 February 2016 11:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

Thank you for your reply. ''Instances of Stereotypes must always be applied to some element in the model.''

Sorry, I'm new to UML Profile. I think I should introduce S2 as a regular class rather than as a stereotype (in the profile). As it don't intend for S2 to be applied to any UML named element.

Thanks,
Rajiv



Re: how to setValue() of a stereotype property that refers to another stereotype [message #1723010 is a reply to message #1722980] Wed, 10 February 2016 14:34 Go to previous message
Eclipse UserFriend
Right, with a Class you're all set then, Rajiv.

Enjoy!

Christian

On 2016-02-10 16:06:51 +0000, Rajiv Murali said:

> Hi Christian,
>
> Thank you for your reply. ''Instances of Stereotypes must always be
> applied to some element in the model.''
>
> Sorry, I'm new to UML Profile. I think I should introduce S2 as a
> regular class rather than as a stereotype (in the profile). As it don't
> intend for S2 to be applied to any UML named element.
> Thanks,
> Rajiv
Previous Topic:How to convert the .uml generated from Magic draw to .ecore using UML2EcoreConverter
Next Topic:Stereotype definitions and applications in the same file
Goto Forum:
  


Current Time: Sat Jul 12 12:15:20 EDT 2025

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

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

Back to the top