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 |
Matteo M. Messages: 40 Registered: May 2012 |
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 |
Ed Willink Messages: 7669 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 #1060224 is a reply to message #1060216] |
Thu, 23 May 2013 15:15 |
Matteo M. Messages: 40 Registered: May 2012 |
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 |
Ed Willink Messages: 7669 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 |
Ed Willink Messages: 7669 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 #1060527 is a reply to message #1060364] |
Sun, 26 May 2013 08:48 |
Sergey Boyko Messages: 171 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.
|
|
|
Goto Forum:
Current Time: Sun Sep 15 20:08:15 GMT 2024
Powered by FUDForum. Page generated in 0.04787 seconds
|