Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to assign a value for a slot of instance specification(How to assign a value for a slot of instance specification?)
How to assign a value for a slot of instance specification [message #1028066] Wed, 27 March 2013 15:52 Go to next message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,


I have created an instance specification, then I created a slot for the property "value", and then to assign a value I'm using the getValues().add(ValueSpecification e) method, but my requirement is how to modify the value of my valueSpecification.

I used this code in java:
InstanceSpecification is = UMLFactory.eINSTANCE.createInstanceSpecification();
is.setName("Instance");
is.getClassifiers().add(myClass);
Slot sn = is.createSlot();
Property value = myClass.getAttribute("value", Integer);
sn.setDefiningFeature(value);
//sn.getValues.add(e)


The valueSpecification which I want to modify its value is:
org.eclipse.uml2.uml.internal.impl.LiteralIntegerImpl@6f564a (name: <unset>, visibility: <unset>) (value: 5)


I want to assign for example the value 20 insteadof the value 5.

Can you help me please.

Thanks in advance

[Updated on: Wed, 27 March 2013 16:09]

Report message to a moderator

Re: How to assign a value for instance specification [message #1028092 is a reply to message #1028066] Wed, 27 March 2013 16:31 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 759
Registered: July 2009
Senior Member
Hi, Sabrina,

The Slot owns its values, so you probably shouldn't change the value of
a LiteralInteger that exists elsewhere in the model because it can't be
shared with another element (only one element can own the value). You
probably should create a new LiteralInteger.

So, for example:

LiteralInteger literal = (LiteralInteger) sn.createValue(null, null,
UMLPackage.Literals.LITERAL_INTEGER);
literal.setValue(5);

HTH,

Christian


On 2013-03-27 19:53:00 +0000, sabrina ing said:

> Hi,
>
>
> I have created an instance specification, then I created a slot for the
> property "value", and then to assign a value I'm using the
> getValues().add(ValueSpecification e) method, but my requirement is how
> to modify the value of my valueSpecification.
> I used this code in java:
> InstanceSpecification is = UMLFactory.eINSTANCE.createInstanceSpecification();
> is.setName("Instance");
> is.getClassifiers().add(myClass);
> Slot sn = is.createSlot();
> Property value = myClass.getAttribute("value", Integer);
> sn.setDefiningFeature(value);
> //sn.getValues.add(e)
>
> The valueSpecification which I want to modify its value is:
> org.eclipse.uml2.uml.internal.impl.LiteralIntegerImpl@6f564a (name:
> <unset>, visibility: <unset>) (value: 5)
>
> I want to assign for example the value 20 insteadof the value 5.
>
> Can you help me please.
>
> Thanks in advance
Re: How to assign a value for instance specification [message #1028104 is a reply to message #1028092] Wed, 27 March 2013 16:59 Go to previous message
sabrina ing is currently offline sabrina ing
Messages: 39
Registered: February 2013
Member
Hi,

Thank you Christian, it is working now.
I'm very grateful for your help Smile
Previous Topic:Position of a Class in a Composite Structure Diagram
Next Topic:The UML metemodel of Papyrus
Goto Forum:
  


Current Time: Tue Jul 22 19:38:38 EDT 2014

Powered by FUDForum. Page generated in 0.01744 seconds