Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Stereotypes and multi-valued attributes(Can't get the value of a multi-valued attribute defined in a Stereotype)
Stereotypes and multi-valued attributes [message #1060191] Thu, 23 May 2013 12:59 Go to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 28
Registered: May 2012
Junior Member
Dear all,

I've defined a Stereotype, MyStereo, with a multi-valued attribute (1..*, Integer), mvAttrib. I've applied the Stereotype to an element in my model, myElem, and I've been able to set its multi-value (3,5,1) through Papyrus.

Now, In a QVTo transform, I want to get back these values. I tried with

myElem.getValue(MyStereo, "mvAttrib")


but it returns a Bag(OclAny)[1] element, where the sole value in the returned element is 3 (i.e., the first one I set for mvAttrib). How do I retrieve ALL the values in a multi-value attribute of a Stereotype?

Side question: As I said, I've been able to set the multi-value through Papyrus. How do I set it in QVTo? I tried with

myElem.setValue(MyStereo, "mvAttrib", Sequence{3,5,1})


but the interpreter complains about "Cannot find operation (setValue(Stereotype, String, Sequence(Integer))) for the type ..."

Thanks and best regards,

Matteo
Re: Stereotypes and multi-valued attributes [message #1060197 is a reply to message #1060191] Thu, 23 May 2013 13:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

You assume that you have declared your'multi-value' myElem correctly. No
idea what a 'multi-value' is; I guess that you mean collection.

But since you haven't shared the declaration of myElem with us it is
difficult to comment.

You can save everyone a lot of time with a simple zipped project that
demonstrates your problem.

REgards

Ed Willink


On 23/05/2013 13:59, Matteo M. wrote:
> Dear all,
>
> I've defined a Stereotype, MyStereo, with a multi-valued attribute
> (1..*, Integer), mvAttrib. I've applied the Stereotype to an element
> in my model, myElem, and I've been able to set its multi-value (3,5,1)
> through Papyrus.
>
> Now, In a QVTo transform, I want to get back these values. I tried with
>
>
> myElem.getValue(MyStereo, "mvAttrib")
>
>
> but it returns a Bag(OclAny)[1] element, where the sole value in the
> returned element is 3 (i.e., the first one I set for mvAttrib). How do
> I retrieve ALL the values in a multi-value attribute of a Stereotype?
>
> Side question: As I said, I've been able to set the multi-value
> through Papyrus. How do I set it in QVTo? I tried with
>
>
> myElem.setValue(MyStereo, "mvAttrib", Sequence{3,5,1})
>
>
> but the interpreter complains about "Cannot find operation
> (setValue(Stereotype, String, Sequence(Integer))) for the type ..."
>
> Thanks and best regards,
>
> Matteo
Re: Stereotypes and multi-valued attributes [message #1060212 is a reply to message #1060197] Thu, 23 May 2013 14:24 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 28
Registered: May 2012
Junior Member
When I try to reply, I see this info:

File Attachments:	Allowed File Extensions: (unrestricted)
			Maximum File Size: 0KB
			Maximum Files Per Message: 0 


So, it seems that I'm unable to send file attachments. I do have a test project that illustrates the problem. Should I send it to you (how/where?) so that you can send it to the forum? Other options?
Re: Stereotypes and multi-valued attributes [message #1060216 is a reply to message #1060212] Thu, 23 May 2013 14:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
HI

I thought the limuits were only on the first five messages and you sent
more than that.

I find DropBox very useful.

Regards

Ed Willink


On 23/05/2013 15:24, Matteo M. wrote:
> When I try to reply, I see this info:
>
>
> File Attachments: Allowed File Extensions: (unrestricted)
> Maximum File Size: 0KB
> Maximum Files Per Message: 0
>
> So, it seems that I'm unable to send file attachments. I do have a
> test project that illustrates the problem. Should I send it to you
> (how/where?) so that you can send it to the forum? Other options?
Re: Stereotypes and multi-valued attributes [message #1060224 is a reply to message #1060216] Thu, 23 May 2013 15:15 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 28
Registered: May 2012
Junior Member
This is the link:
https://www.dropbox.com/s/pu7c3mzd3ruz8ab/MyProjects.zip

Let me explain how you (or others) can reproduce the issue.

Please unzip MyProjects.zip. There are 2 projects:

- MyProjectSysML
- MyProjectM2M

In MyProjectSysML you'll find a profile (model.profile) that defines the Stereotype MyStereo with the multi-valued attribute mvAttrib (1..*, Integer (from UML standard types)). Then you'll find the source model (model) that contains a SysML block, myElem, stereotyped as MyStereo. I set the values of mvAttrib of myElem through the Papyrus UI. I gave the values 3,5,1. Finally, you'll find an empty model, that is the target of the M2M transform.

In MyProjectM2M you'll find the QVTo transform (NewTransformation). Please set up your config so as MyProjectSysML/model.uml is your source model and MyProjectSysML/emptyModel.uml is your destination model. Then debug the QVTo transform (only debug the transform or you won't see anything; this is only a trivial example). You'll see that at line 11, the instruction

var mvAttribValues := myElem.getValue(MyStereo, "mvAttrib");


will put only the Integer value 3 in mvAttribValues and not the sequence (?) 3,5,1. How do I get all the values (3,5,1) of mvAttrib?

Matteo
Re: Stereotypes and multi-valued attributes [message #1060231 is a reply to message #1060224] Thu, 23 May 2013 15:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

As I suspected, it is the declaration of myElem that is at fault.

var myElem : Class := MyModel.ownedElement->select(e |
e.oclIsKindOf(Class))->oclAsType(Class)![name = "myElem"];

I'm not a fan of ! [] cuteness so I had to look them up and the
documentation is pretty thin.

Your code does not match the

list->prop![startswith("_")]) ; // calling collectselectOne(i;res=
i.prop | not res.startswith("_"))

template, so maybe it's illegal; who knows. Using common sense one might
like it to be

var myElem : Class := MyModel
.ownedElement
->select(e | e.oclIsKindOf(Class))
->oclAsType(Class)
->collectselectOne(not (name = "myElem"))

which might mean myElem is a random Class not named myElem. Not what you
wanted.

I find the pure OCL.

var myElem : Class := MyModel.ownedElement->select(e |
e.oclIsKindOf(Class))->oclAsType(Class)->any(name = "myElem");

clearer. As from Indigo you can do

var myElem : Class :=
MyModel.ownedElement->selectByKind(Class)->any(name = "myElem");

Regards

Ed Willink

On 23/05/2013 16:15, Matteo M. wrote:
> This is the link:
> https://www.dropbox.com/s/pu7c3mzd3ruz8ab/MyProjects.zip
>
> Let me explain how you (or others) can reproduce the issue.
>
> Please unzip MyProjects.zip. There are 2 projects:
>
> - MyProjectSysML
> - MyProjectM2M
>
> In MyProjectSysML you'll find a profile (model.profile) that defines
> the Stereotype MyStereo with the multi-valued attribute mvAttrib
> (1..*, Integer (from UML standard types)). Then you'll find the source
> model (model) that contains a SysML block, myElem, stereotyped as
> MyStereo. I set the values of mvAttrib of myElem through the Papyrus
> UI. I gave the values 3,5,1. Finally, you'll find an empty model, that
> is the target of the M2M transform.
>
> In MyProjectM2M you'll find the QVTo transform (NewTransformation).
> Please set up your config so as MyProjectSysML/model.uml is your
> source model and MyProjectSysML/emptyModel.uml is your destination
> model. Then debug the QVTo transform (only debug the transform or you
> won't see anything; this is only a trivial example). You'll see that
> at line 11, the instruction
>
>
> var mvAttribValues := myElem.getValue(MyStereo, "mvAttrib");
>
>
> will put only the Integer value 3 in mvAttribValues and not the
> sequence (?) 3,5,1. How do I get all the values (3,5,1) of mvAttrib?
>
> Matteo
Re: Stereotypes and multi-valued attributes [message #1060257 is a reply to message #1060231] Thu, 23 May 2013 17:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi

Reading more carefully; the declaration and pseudo code of
collectselectOne clearly returns a Sequence, so you should have a syntax
error when assigning to a Class. Please raise a Bugzilla.

Regards

Ed Willink

On 23/05/2013 16:53, Ed Willink wrote:
> Hi
>
> As I suspected, it is the declaration of myElem that is at fault.
>
> var myElem : Class := MyModel.ownedElement->select(e |
> e.oclIsKindOf(Class))->oclAsType(Class)![name = "myElem"];
>
> I'm not a fan of ! [] cuteness so I had to look them up and the
> documentation is pretty thin.
>
> Your code does not match the
>
> list->prop![startswith("_")]) ; // calling collectselectOne(i;res=
> i.prop | not res.startswith("_"))
>
> template, so maybe it's illegal; who knows. Using common sense one
> might like it to be
>
> var myElem : Class := MyModel
> .ownedElement
> ->select(e | e.oclIsKindOf(Class))
> ->oclAsType(Class)
> ->collectselectOne(not (name = "myElem"))
>
> which might mean myElem is a random Class not named myElem. Not what
> you wanted.
>
> I find the pure OCL.
>
> var myElem : Class := MyModel.ownedElement->select(e |
> e.oclIsKindOf(Class))->oclAsType(Class)->any(name = "myElem");
>
> clearer. As from Indigo you can do
>
> var myElem : Class :=
> MyModel.ownedElement->selectByKind(Class)->any(name = "myElem");
>
> Regards
>
> Ed Willink
>
> On 23/05/2013 16:15, Matteo M. wrote:
>> This is the link:
>> https://www.dropbox.com/s/pu7c3mzd3ruz8ab/MyProjects.zip
>>
>> Let me explain how you (or others) can reproduce the issue.
>>
>> Please unzip MyProjects.zip. There are 2 projects:
>>
>> - MyProjectSysML
>> - MyProjectM2M
>>
>> In MyProjectSysML you'll find a profile (model.profile) that defines
>> the Stereotype MyStereo with the multi-valued attribute mvAttrib
>> (1..*, Integer (from UML standard types)). Then you'll find the
>> source model (model) that contains a SysML block, myElem, stereotyped
>> as MyStereo. I set the values of mvAttrib of myElem through the
>> Papyrus UI. I gave the values 3,5,1. Finally, you'll find an empty
>> model, that is the target of the M2M transform.
>>
>> In MyProjectM2M you'll find the QVTo transform (NewTransformation).
>> Please set up your config so as MyProjectSysML/model.uml is your
>> source model and MyProjectSysML/emptyModel.uml is your destination
>> model. Then debug the QVTo transform (only debug the transform or you
>> won't see anything; this is only a trivial example). You'll see that
>> at line 11, the instruction
>>
>>
>> var mvAttribValues := myElem.getValue(MyStereo, "mvAttrib");
>>
>>
>> will put only the Integer value 3 in mvAttribValues and not the
>> sequence (?) 3,5,1. How do I get all the values (3,5,1) of mvAttrib?
>>
>> Matteo
>
Re: Stereotypes and multi-valued attributes [message #1060364 is a reply to message #1060231] Fri, 24 May 2013 10:05 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 28
Registered: May 2012
Junior Member
I admit I have not completely understood your complaints about the use of the ![] operator. However, from your reply it seems to me that you are suggesting that simply changing to

var myElem : Class := MyModel.ownedElement->selectByKind(Class)->any(name = "myElem");


does the job. I tried it, but it has not worked. I still get only one integer value (3) in mvAttribValue after the execution of:

var mvAttribValues := myElem.getValue(MyStereo, "mvAttrib");


Does the code you suggest work for you?

Anyway, I also tried this one:

var mvAttribValues : Sequence(Integer) := myElem.getValue(MyStereo, "mvAttrib");


but the interpreter says that "Type mismatch: can not convert from 'oclstdlib::OclAny' to 'NewTransformation::Sequence(Integer)' type"

Then I came across to this one:
http://www.eclipse.org/forums/index.php/mv/msg/440627/987427/#msg_987427

that it seems very similar to the problem I'm dealing with. So I tried to change to

var mvAttribValues := myElem.getValue(MyStereo, "mvAttrib").oclAsSet()->flatten()->selectByKind(Integer)


but it does not work for me (I get a Collection with only one integer value (3)). I tried with the latest QVTo (RC1 in Kepler). Nothing.

Maybe I have wrongly defined my SysML profile or my SysML model? I can't believe that there is no an easy way to get a collection of integers from an attribute of a stereotyped model element, when that attribute has type Integer [1..*] (so it should be straightforward to map its values to a collection).

Again, the link to the example project is this one:
https://www.dropbox.com/s/pu7c3mzd3ruz8ab/MyProjects.zip

Any concrete suggestion in solving my issue would be greatly appreciated!

Thank you in advance!

--
Matteo
Re: Stereotypes and multi-valued attributes [message #1060527 is a reply to message #1060364] Sun, 26 May 2013 08:48 Go to previous message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 162
Registered: July 2009
Senior Member
Hi Matteo,

The problem is that the return type of method .getValue() is java.lang.Object which is mapped to OclAny type.

QVTo is based on OCL 2.0 implementation which states that:
"All types in the UML model and the primitive types in the OCL standard library comply with the type OclAny.
Conceptually, OclAny behaves as a supertype for all the types except for the OCL pre-defined collection types."

Despite the fact that .getValue() returns List object for multivalued attribute OCL implementation internally coerces this List into single object (specifically OCL implementation fetches and returns the first element from the list).
More over due to specification it is impossible to convert OclAny type to Collection type (by means of .oclAsType() call).

Btw, current OCL 2.3.1 specification states that:
"All types in the UML model and the primitive and collection types in the OCL standard library conforms to the type
OclAny. Conceptually, OclAny behaves as a supertype for all the types."
However OCL implementation which is used by QVTo doesn't support that.


There are two ways to overcome the problem.

1. Provide Java blackbox library methods .getMultivalue() / .setMultivalue which operate with collections.

2. Use extended syntax of .getValue() / .setValue() that is supported by UML.

For example, to fetch second element from the multivalued attribute one should write the following call:
var v : Integer := myElem.getValue(MyStereo, "mvAttrib[1]").oclAsType(Integer);


For example, to set third element to the multivalued attribute one should write the following call:
myElem.setValue(MyStereo, "mvAttrib[2]", 11);

or
myElem.setValue(MyStereo, "mvAttrib[2]", "11");


UML also supports syntax for association navigation by means of '::' separator in attribute name. For example (in case the 'mvAttrib' is of type of Classifier):
myElem.setValue(MyStereo, "mvAttrib[2]::subAttrib[1]", 11);


Regards,
Sergey.
Previous Topic:Generalization relationship between stereotypes
Next Topic:how to use two target sources?
Goto Forum:
  


Current Time: Thu Dec 18 22:40:03 GMT 2014

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

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