What is the allInstances counterpart for Associations in OCL? [message #1417748] |
Sat, 06 September 2014 00:30 |
|
Hi,
How can I access all instances of an association with an OCL expression.
Suppose I have an association name in a variable named refName, which is the name of an association from class A to class B. For a given instance of A (say a) how can I access the value of refName which would be apparently SET(B)?
Note that refName is not the name of the association, but a variable which its value is the name of the association!
Thanks
[Updated on: Sat, 06 September 2014 00:40] Report message to a moderator
|
|
|
|
Re: What is the allInstances counterpart for Associations in OCL? [message #1419188 is a reply to message #1418648] |
Mon, 08 September 2014 08:16 |
Felix Dorner Messages: 295 Registered: March 2012 |
Senior Member |
|
|
I have once designed (tried at least :p) a language in which this was
possible. Associations were first-class objects, so you could iterate
over their contents (with support for n-ary associations, not just
binary), allInstances was also supported.
The prototype generated Java from UML + OpaqueExpressions
But I think the OP wants actually something different, something as:
let x='refName' in self.$x
On 07/09/2014 13:35, Ed Willink wrote:
> Hi
>
> The exposition of Associations in the OCL specification is poor.
>
> The support for Associations in Eclipse OCL is therefore a bit suspect.
>
> In principle you might hope that an Association named A_from_to could be
> accessed as A_from_to::allInstances().
>
> In practice I doubt that it will work, certainly not using the
> pivot-based OCL where the overhead of Associations is optimized away
> (unless they are explicitly required).
>
> I recommend that you use allInstances on the more restrictive of the end
> types and work with the corresponding source/target.
>
> Regards
>
> Ed Willink
>
>
>
> On 06/09/2014 01:30, Hamid Qartal wrote:
>> Hi,
>>
>> I would like to know how can I access all instances of an association in
>> OCL expression.
>>
>> Suppose I have an association name in a variable named refName, which is
>> the name of an association from class A to class B. For a given instance
>> of A (say a) how can I access the value of refName which would be
>> apparently SET(B)?
>>
>> Note that refName is not the name of the association, but the variable
>> which its value is the name of association!
>>
>> Thanks
>
|
|
|
Re: What is the allInstances counterpart for Associations in OCL? [message #1419374 is a reply to message #1419188] |
Mon, 08 September 2014 14:01 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
[Back on list; really irritating that Thunderbird replies off-list by
default.]
Using reflective properties needs some OCL counterpart of EMF's eGet().
With templated types it may be possible to achieve some type safety with
an oclGet(), but it is something I have not given a great deal of
thought to.
Regards
Ed Willink
On 08/09/2014 09:53, Felix Dorner wrote:
> And then, how can one use the result of that to use it to navigate
from an instance?
>
> -----Original Message-----
> From: Ed Willink [mailto:ed@xxxxxxxx.uk]
> Sent: lundi 8 septembre 2014 10:48
> To: Felix Dorner
> Subject: Re: What is the allInstances counterpart for Associations in
OCL?
>
>
> Hi
>
> OCL 2.5 is likely to have optional support for reflection so you
should be able to do
>
> let x='refName' in
> self.oclType().ownedTypes->selectByKind(Association)->select(name = x)
>
> if you want to use a reflective solution.
>
> Regards
>
> Ed Willink
>
> On 08/09/2014 09:16, Felix Dorner wrote:
>>
>> I have once designed (tried at least :p) a language in which this was
>> possible. Associations were first-class objects, so you could iterate
>> over their contents (with support for n-ary associations, not just
>> binary), allInstances was also supported.
>> The prototype generated Java from UML + OpaqueExpressions
>>
>> But I think the OP wants actually something different, something as:
>>
>> let x='refName' in self.$x
>>
>>
>>
>> On 07/09/2014 13:35, Ed Willink wrote:
>>> Hi
>>>
>>> The exposition of Associations in the OCL specification is poor.
>>>
>>> The support for Associations in Eclipse OCL is therefore a bit suspect.
>
>>>
>>> In principle you might hope that an Association named A_from_to could
>>> be accessed as A_from_to::allInstances().
>>>
>>> In practice I doubt that it will work, certainly not using the
>>> pivot-based OCL where the overhead of Associations is optimized away
>>> (unless they are explicitly required).
>>>
>>> I recommend that you use allInstances on the more restrictive of the
>>> end types and work with the corresponding source/target.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>>
>>> On 06/09/2014 01:30, Hamid Qartal wrote:
>>>> Hi,
>>>>
>>>> I would like to know how can I access all instances of an
>>>> association in OCL expression.
>>>>
>>>> Suppose I have an association name in a variable named refName,
>>>> which is the name of an association from class A to class B. For a
>>>> given instance of A (say a) how can I access the value of refName
>>>> which would be apparently SET(B)?
>>>>
>>>> Note that refName is not the name of the association, but the
>>>> variable which its value is the name of association!
>>>>
>>>> Thanks
>>>
>>
>
>
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2014.0.4765 / Virus Database: 4015/8173 - Release Date: 09/08/14
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03048 seconds