how to setValue() of a stereotype property that refers to another stereotype [message #1722930] |
Wed, 10 February 2016 10:50 |
Rajiv Murali Messages: 5 Registered: May 2014 |
Junior Member |
|
|
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 #1722957 is a reply to message #1722939] |
Wed, 10 February 2016 14:15 |
|
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 #1723010 is a reply to message #1722980] |
Wed, 10 February 2016 19:34 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04531 seconds