Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Problem in set property value
Problem in set property value [message #642908] Fri, 03 December 2010 10:11 Go to next message
123star  is currently offline 123star Friend
Messages: 70
Registered: June 2010
Member
Hi,

I have a Port that is stereotyped with RtFeature, this stereotype has a property named "specification" that is a list.
I'd like to add comments that annotate that port, but when I try with this code it doesn't work:
Object tmp = thePort.getValue(stereoRtFeature, "specification");
		
if(tmp instanceof List){
				
	List specList = (List)tmp;
	specList.add(theComment);
}


How can I add a value to a property that is a list?
Thanks in advance, 123star
Re: Problem in set property value [message #643013 is a reply to message #642908] Fri, 03 December 2010 15:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi 123star

I think you'll get on better by adding comments to ...getOwnedComment().

Regards

Ed Willink


On 03/12/2010 10:11, 123star wrote:
> Hi,
>
> I have a Port that is stereotyped with RtFeature, this stereotype has
> a property named "specification" that is a list.
> I'd like to add comments that annotate that port, but when I try with
> this code it doesn't work:
>
> Object tmp = thePort.getValue(stereoRtFeature, "specification");
>
> if(tmp instanceof List){
>
> List specList = (List)tmp;
> specList.add(theComment);
> }
>
>
> How can I add a value to a property that is a list?
> Thanks in advance, 123star
Re: Problem in set property value [message #643026 is a reply to message #642908] Fri, 03 December 2010 17:12 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 161
Registered: July 2009
Senior Member
Dammit, lost my original post.

1) if you never set the value before, it will be null, and thus not an instance of list

2) if you did, then you need to copy the value into a modifiable list, add to it, then set the new list as the new value with setValue.

3) Ed gotta a point - UML already has support for comments, why not use them?\

Cheers,

Rafael
http://abstratt.com/blog
Re: Problem in set property value [message #643043 is a reply to message #642908] Fri, 03 December 2010 17:54 Go to previous messageGo to next message
123star  is currently offline 123star Friend
Messages: 70
Registered: June 2010
Member
Hi, thanks for your reply.

3) I have to follow this way because it's a requirement Sad

1 & 2) When I get the value the list is not null, so I add the element to it

I tried to create a new list ( by the way, what kind of list I can use? i tried arraylist with no success ), add the element to it and then set the list with setValue, but an IllegalArgumentException is thrown for doing this.

Why I can't add the element directly to the list that I get with getValue?

Thanks in advance, 123


Re: Problem in set property value [message #643083 is a reply to message #643043] Sat, 04 December 2010 01:31 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 161
Registered: July 2009
Senior Member
Quote:
Why I can't add the element directly to the list that I get with getValue?


First, because the collection you get is not the actual collection used internally. Second, because it may not be modifiable. Third, UML2 API aside, unless a method documentation states it returns a modifiable collection and that you should modify it at will, that is the sensible thing to do.

Quote:
I tried to create a new list ( by the way, what kind of list I can use? i tried arraylist with no success ), add the element to it and then set the list with setValue, but an IllegalArgumentException is thrown for doing this.


There can be many reasons for an IAE in setValue (for instance, is the type of "theComment" variable compatible with the stereotype property type?). Your best bet is to ensure you have the source for UML2 (for instance, you have the UML2 Extender SDK, not only the binary libraries), and step through the call to setValue and see exactly where it is failing.

Good luck,

Rafael
http://alphasimple.com
Previous Topic:Unable to create 'ResourceSetImpl' instance in Eclipse 3.4.1
Next Topic:Modifying UML2 profile makes stereotype references invalid
Goto Forum:
  


Current Time: Fri Apr 19 06:36:31 GMT 2024

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

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

Back to the top