Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Shorten oclAsType and obtain all instances
Shorten oclAsType and obtain all instances [message #527759] Fri, 16 April 2010 11:54 Go to next message
Micha  is currently offline Micha Friend
Messages: 2
Registered: April 2010
Junior Member
Hello,

I'm new to OCL and I've been running into two problems. At the moment I'm working with Topcased which seems to be running alright.

First of all, when I use the 'select' operation I have to use the 'oclAsType' operation to continue with the retrieved collection.
For instance, lets say I'm looking at an object 'Company' which has different 'workfloors': 'shop' and 'storage'. If I want to see which products are in the storage I'll have to type something like:

context Company:

self.workfloors->select(oclIsTypeOf(Storage)).oclAsType(Storage).products

Is there perhaps some way I can leave the 'oclAsType(Storage)' out of this function? Because in some bigger constraints it makes it very chaotic. And in my opinion I've already stated that I'm using the object 'Storage' since I've only selected those. But right now in Topcased atleast I can't seem to use the '.products' operation if I don't declare that my selection is oclAsType(Storage).

And a second issue I'm having is whether there is a way to obtain all instances of a model with a single operation. For example I'd like to get a collection with all names of all classes. Do I really have to work through the entire model and retrieve every name or is there a shortcut to do this?

Thanks in advance, I hope the problems are clear enough like this.

Greetings,
Micha
Re: Shorten oclAsType and obtain all instances [message #527771 is a reply to message #527759] Fri, 16 April 2010 12:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi Micha

> self.workfloors->select(oclIsTypeOf(Storage)).oclAsType(Storage).products
>
> Is there perhaps some way I can leave the 'oclAsType(Storage)' out of
> this function?

You're right. It would be good to have a better shorthand. But if you
were writing Java you would have (more than) the following two tests

if (x instanceof Storage)
((Storage)x)...

Seems like we could very easily have

self.workfloors->selectAsType(Storage).products

https://bugs.eclipse.org/bugs/show_bug.cgi?id=309459 raised to remind
us to do something about it.

>
> And a second issue I'm having is whether there is a way to obtain all
> instances of a model with a single operation. For example I'd like to
> get a collection with all names of all classes. Do I really have to work
> through the entire model and retrieve every name or is there a shortcut
> to do this?

The Classifier::allInstances function does exactly this. However because
it does a full model traversal allInstances() is strongly discouraged.

You may find the new closure() iterator enables you to traverse your
whole model more intelligently.

Regards

Ed Willink
Re: Shorten oclAsType and obtain all instances [message #527772 is a reply to message #527759] Fri, 16 April 2010 12:18 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1638
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040801010103080109050107
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Micha,

As far as your first issue is concerned (forced oclAsType after a
"select(oclIsKindOf(...))"), this is a problem I discussed a good while
ago when Christian Damus was the lead OCL commiter. His answer can be
read on
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.o cl/msg01881.html
..

IIRC, base point was that the OCL specification explicitely states the
return type of the select operation, thus preventing dynamic casting
even if the select's expression ends in "oclIsKindOf" (Don't get me
wrong, I'd be all for deviating from the spec on this, but doubt it will
be done).

As for the second, you could use the "allInstances" operation. To keep
your example, here is how you'd get a set with the names of all your
classes :

Class.allInstances().name

Laurent Goubet
Obeo

Micha wrote:
> Hello,
>
> I'm new to OCL and I've been running into two problems. At the moment
> I'm working with Topcased which seems to be running alright.
>
> First of all, when I use the 'select' operation I have to use the
> 'oclAsType' operation to continue with the retrieved collection.
> For instance, lets say I'm looking at an object 'Company' which has
> different 'workfloors': 'shop' and 'storage'. If I want to see which
> products are in the storage I'll have to type something like:
>
> context Company:
>
> self.workfloors->select(oclIsTypeOf(Storage)).oclAsType(Storage).products
>
> Is there perhaps some way I can leave the 'oclAsType(Storage)' out of
> this function? Because in some bigger constraints it makes it very
> chaotic. And in my opinion I've already stated that I'm using the object
> 'Storage' since I've only selected those. But right now in Topcased
> atleast I can't seem to use the '.products' operation if I don't declare
> that my selection is oclAsType(Storage).
>
> And a second issue I'm having is whether there is a way to obtain all
> instances of a model with a single operation. For example I'd like to
> get a collection with all names of all classes. Do I really have to work
> through the entire model and retrieve every name or is there a shortcut
> to do this?
>
> Thanks in advance, I hope the problems are clear enough like this.
>
> Greetings,
> Micha


--------------040801010103080109050107
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040801010103080109050107--
Re: Shorten oclAsType and obtain all instances [message #528439 is a reply to message #527759] Tue, 20 April 2010 14:24 Go to previous message
Micha  is currently offline Micha Friend
Messages: 2
Registered: April 2010
Junior Member
Thanks very much for the quick replies, this really helps with my progress Smile!

I'll be taking a good look at the allInstances() and closure() operations.

Greetings,
Micha
Previous Topic:Parse an OCL String without any Kind Information
Next Topic:OMG's OCL specification
Goto Forum:
  


Current Time: Fri Nov 28 09:07:57 GMT 2014

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

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