Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » setValue() of a stereotype attribute of custom type
setValue() of a stereotype attribute of custom type [message #925156] Thu, 27 September 2012 12:38 Go to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Hi all,
I need some help for a standalone application that uses UML2 and EMF API.

Starting point is that I have a custom UML2Profile with a stereotype that has a required attribute. It is custom type defined in the Profile, e.g.:

+---------------+
| <Stereotype> |
| MyStereotype |
|---------------|
|- attr: MyType |
+---------------+

MyType is an interface defined into the UML2Profile that owns "MyStereotype".
I created a new UML model programmatically and I applied MyStereotype to an element but I also need to value "attr".
It can be done by the following method of org.eclipse.uml2.uml.Element:

setValue(Stereotype stereotype, String propertyName, Object newValue)

Now my question is:
How can I instantiate Object of right type? Do I need java code of the UML2Profile (e.g.: generated by genmodel)? I mean like L2Profile or L3Profile API?
I'm using a uml class with an InterfaceRealization relationship with MyType, but it doesn't work.

Thanks in advance for any help
Re: setValue() of a stereotype attribute of custom type [message #925210 is a reply to message #925156] Thu, 27 September 2012 13:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

The UML2 Java API is both powerful and confusing, many apparently
visible methods should not be used and many methods should be used in
appropriate combinations.

I recommend using Papyrus or the UML Model editor to create something
similar to what you want and then recreate it with Java code.

Regards

Ed Willink


On 27/09/2012 13:38, Mauro Faella wrote:
> Hi all,
> I need some help for a standalone application that uses UML2 and EMF API.
>
> Starting point is that I have a custom UML2Profile with a stereotype
> that has a required attribute. It is custom type defined in the
> Profile, e.g.:
>
> +---------------+
> | <Stereotype> | | MyStereotype |
> |---------------|
> |- attr: MyType |
> +---------------+
>
> MyType is an interface defined into the UML2Profile that owns
> "MyStereotype".
> I created a new UML model programmatically and I applied MyStereotype
> to an element but I also need to value "attr". It can be done by the
> following method of org.eclipse.uml2.uml.Element:
>
> setValue(Stereotype stereotype, String propertyName, Object newValue)
>
> Now my question is:
> How can I instantiate Object of right type? Do I need java code of the
> UML2Profile (e.g.: generated by genmodel)? I mean like L2Profile or
> L3Profile API?
> I'm using a uml class with an InterfaceRealization relationship with
> MyType, but it doesn't work.
>
> Thanks in advance for any help
Re: setValue() of a stereotype attribute of custom type [message #925219 is a reply to message #925210] Thu, 27 September 2012 13:59 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Ed Willink wrote on Thu, 27 September 2012 09:47
Hi

The UML2 Java API is both powerful and confusing, many apparently
visible methods should not be used and many methods should be used in
appropriate combinations.

I recommend using Papyrus or the UML Model editor to create something
similar to what you want and then recreate it with Java code.

Regards

Ed Willink

Thanks for advice.
But even in UML Editor and Papyrus I can't do what I want with a custom type attribute. In the Properties view I have no choice for "attr" so I guess that it depends on the fact that there isn't the right element in my model.
Re: setValue() of a stereotype attribute of custom type [message #925238 is a reply to message #925156] Thu, 27 September 2012 14:17 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 789
Registered: July 2009
Senior Member
Hi, Mauro,

You say that 'MyType' is an interface. Do you mean, literally, an
instance of the UML Interface metaclass? If so, then be aware that
interfaces aren't really used in metamodels (profiles are metamodel
extensions). At best, UML2 can generate an EClass that has
isInterface=true, which maps to a Java interface. Interfaces aren't
instantiable, so the editor wouldn't have any idea of what to do.

Why is 'MyType' not a UML Class? If it is a class, then UML2 can
generate an EClass that you can instantiate. Note that it will also
have to be contained (perhaps indirectly) in some stereotype somewhere,
otherwise you won't be able to create it in a UML model.

HTH,

Christian


On 2012-09-27 12:38:38 +0000, Mauro Faella said:

> Hi all,
> I need some help for a standalone application that uses UML2 and EMF API.
>
> Starting point is that I have a custom UML2Profile with a stereotype
> that has a required attribute. It is custom type defined in the
> Profile, e.g.:
>
> +---------------+
> | <Stereotype> | | MyStereotype |
> |---------------|
> |- attr: MyType |
> +---------------+
>
> MyType is an interface defined into the UML2Profile that owns "MyStereotype".
> I created a new UML model programmatically and I applied MyStereotype
> to an element but I also need to value "attr". It can be done by the
> following method of org.eclipse.uml2.uml.Element:
>
> setValue(Stereotype stereotype, String propertyName, Object newValue)
>
> Now my question is:
> How can I instantiate Object of right type? Do I need java code of the
> UML2Profile (e.g.: generated by genmodel)? I mean like L2Profile or
> L3Profile API?
> I'm using a uml class with an InterfaceRealization relationship with
> MyType, but it doesn't work.
>
> Thanks in advance for any help
Re: setValue() of a stereotype attribute of custom type [message #926029 is a reply to message #925238] Fri, 28 September 2012 08:34 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Hi Christian,
thank you for reply.
I'd got the profile from external source and it is developed in that way, but I understood what are you saying and I agree.
I will try to modify the Interface into a Class.
Re: setValue() of a stereotype attribute of custom type [message #932895 is a reply to message #926029] Thu, 04 October 2012 14:46 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Hi,
I tried to modify the profile changing the Interface into a Class without success.
Even so if I add a 'MyType' class to my UML model I can't choice an element to 'attr'. I tried also to add a property of type MyType to stereotyped element but it doesn't work.

[Updated on: Thu, 04 October 2012 14:46]

Report message to a moderator

Re: setValue() of a stereotype attribute of custom type [message #933624 is a reply to message #932895] Fri, 05 October 2012 07:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

Try posting an example. It's unlikely that any can accurately guess at
what your doing from your vague overview.

Regards

ed Willink


On 04/10/2012 16:46, Mauro Faella wrote:
> Hi,
> I tried to modify the profile changing the Interface into a Class
> without success. Even so if I add a 'MyType' class to my UML model I
> can't choice an element to 'attr'. I tried also to add a property of
> type MyType to stereotyped elemend but it doesn't work.
>
Re: setValue() of a stereotype attribute of custom type [message #933772 is a reply to message #933624] Fri, 05 October 2012 10:26 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Hi Ed,
I attach an example, I hope that it explains better then me Razz

As you can see I can't choice element for the required attribute of the Stereotype applied. I tried to create a class (MyTypeDerived) that implements the interface specified into the Profile and even two properties (one of type MyType and other of type MyTypeDerived) into the stereotyped class, but it didn't work.

Thanks for replying,
m
  • Attachment: example.JPG
    (Size: 285.99KB, Downloaded 140 times)
Re: setValue() of a stereotype attribute of custom type [message #933782 is a reply to message #933772] Fri, 05 October 2012 10:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

Without the *.uml to play with it is unclear whether

a) You have no instances of MyType to be offered
b) the offered instances have no name and so appear blank

Regards

Ed Willink



On 05/10/2012 12:26, Mauro Faella wrote:
> Hi Ed,
> I attach an example, I hope that it explains better then me :p
>
> As you can see I can't choice element for the required attribute of the Stereotype applied. I tried to create a class (MyTypeDerived) that implements the interface specified into the Profile and even two properties (one of type MyType and other of type MyTypeDerived) into the stereotyped class, but it didn't work.
>
> Thanks for replying,
> m
Re: setValue() of a stereotype attribute of custom type [message #933811 is a reply to message #933782] Fri, 05 October 2012 11:13 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
You're right, here are the .uml files

Anyway I don't follow you about instance... What do I wrong? Isn't a property enough?
  • Attachment: Profile.uml
    (Size: 2.74KB, Downloaded 111 times)
  • Attachment: Model.uml
    (Size: 1.99KB, Downloaded 87 times)
Re: setValue() of a stereotype attribute of custom type [message #934795 is a reply to message #933811] Sat, 06 October 2012 09:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

Ok. I can see the models now. They look ok.

The two blank lines in your PNG look unhelpful but not wrong.

What is it that you cannot do?

Regards

Ed Willink


On 05/10/2012 13:13, Mauro Faella wrote:
> You're right, here are the .uml files
>
> Anyway I don't follow you about instance... What do I wrong? Isn't a property enough?
Re: setValue() of a stereotype attribute of custom type [message #937738 is a reply to message #934795] Tue, 09 October 2012 08:11 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
Hi

I cannot assign a value to the 'Attr', the two blank lines aren't selectable.
I also tried programmatically with uml2 API, as I described in the first post, and I get the same problem.

[Updated on: Tue, 09 October 2012 08:12]

Report message to a moderator

Re: setValue() of a stereotype attribute of custom type [message #937808 is a reply to message #937738] Tue, 09 October 2012 09:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

Without reproducible details, I cannot give you any further help.

Regards

Ed Willink

On 09/10/2012 09:11, Mauro Faella wrote:
> Hi
>
> I cannot assign a value to the 'Attr'. I also tried programmatically
> with uml2 API, as I described in the first post, and I get the same
> problem.
Re: setValue() of a stereotype attribute of custom type [message #937867 is a reply to message #937808] Tue, 09 October 2012 10:36 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
With the two uml that I attached previously you can reproduce the problem.
You try to assign a value to 'Attr' in Properties view... simply you can't
Re: setValue() of a stereotype attribute of custom type [message #937880 is a reply to message #937867] Tue, 09 October 2012 10:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

If I spent an hour trying to reproduce your code, I might be able to
reproduce it, but I might not reproduce your bugs and I have better
things to do with my time.

If you want free help, you need to make it easy to help you.

Provide a zipped project with a launch configuration that just runs and
shows and error.

Regards

Ed Willink


On 09/10/2012 11:36, Mauro Faella wrote:
> With the two uml that I attached previously you can reproduce the
> problem.
> You try to assign a value to 'Attr' in Properties view... simply you
> can't
Re: setValue() of a stereotype attribute of custom type [message #937967 is a reply to message #937880] Tue, 09 October 2012 12:20 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro Faella
Messages: 31
Registered: June 2012
Member
In this case a runnable project isn't needed. I don't understand which is the right UML element to set 'Attr'
You can reproduce the problem into uml editor of Eclipse Modeling (I'm using Juno). The programmatically part cames later in simple way (I hope).
Anyway I thank you for any help that you are providing me.

Regards
Re: setValue() of a stereotype attribute of custom type [message #938058 is a reply to message #937738] Tue, 09 October 2012 14:03 Go to previous messageGo to next message
Peter  is currently offline Peter
Messages: 85
Registered: July 2009
Member
Hi Mauro,
I think you should take a look at this page to get uml extensions right
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Customizing_UML2_Which_Technique_is_Right_For_You/article.html

What should be assigned to Attr? The Interface MyType?
Then the Datatype of Attr must be set to the "Metaclass" Interface from
the UML.metamodel.uml file.
Greetings

Am 09.10.2012 10:11, schrieb Mauro Faella:
> Hi
>
> I cannot assign a value to the 'Attr'. I also tried programmatically
> with uml2 API, as I described in the first post, and I get the same
> problem.
Re: setValue() of a stereotype attribute of custom type [message #939133 is a reply to message #933811] Wed, 10 October 2012 13:05 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 789
Registered: July 2009
Senior Member
Hi, Mauro,

I see in the profile that the 'attr' property of type MyType is not a
composite aggregation, which in Ecore terms is a containment reference.
So, in Ecore terms, an instance of MyStereotype has a cross-reference
named 'attr' to an instance of MyType.

The editor requires you to have an instance of MyType available to
assign to the 'attr' reference. That's why the Properties view
provides a drop-down list to pick from. The problem that you have is
that there isn't any place to create an instance of MyType because

* there is no containment reference of type MyType or some concrete
subtype of it
that can hold a MyType instance
* there is no concrete subtype of the MyType interface in the
profile, so you wouldn't
be able to create any instances of it, anyways

HTH,

Christian


On 2012-10-05 11:13:08 +0000, Mauro Faella said:

> You're right, here are the .uml files
>
> Anyway I don't follow you about instance... What do I wrong? Isn't a
> property enough?
> <image><image>
Previous Topic:Singelton Design Pattern using UML Profile
Next Topic:Missing UML2 library in Indigo
Goto Forum:
  


Current Time: Thu Sep 18 11:52:51 GMT 2014

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

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