Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How define an ocl expression on type of an object
How define an ocl expression on type of an object [message #837466] Thu, 05 April 2012 13:54 Go to next message
sohrab Missing name is currently offline sohrab Missing name
Messages: 17
Registered: November 2011
Junior Member
Hi,

I use interactive OCL console for validating dynamic instances of my ecore model. Can I write OCl expression that check type of some objects?

for example like this :

case 1) if 'name' is attribute of selected object

self.name.type='integer'
------------------------------
case 2) if 'values' is list of classes

self.values[1].type=self.values[2].type

thanks
Re: How define an ocl expression on type of an object [message #837475 is a reply to message #837466] Thu, 05 April 2012 14:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3840
Registered: July 2009
Senior Member
Hi

Yes. See oclIsTypeOf() and oclIsKindOf().

For the pivot-based implementation oclType() is fully reflective, so if
you really want to do string-based type checking you can do:
self.name.oclType().name = 'Integer'
and type literals are functional so you can do
self.name.oclType() = Integer
as well as
self.name.oclIsKindOf(Integer)

[1] is an association qualifier not list index. See at().

Regards

Ed Willink

On 05/04/2012 18:54, sohrab Mising name wrote:
> Hi,
>
> I use interactive OCL console for validating dynamic instances of my
> ecore model. Can I write OCl expression that check type of some objects?
>
> for example like this :
> case 1) if 'name' is attribute of selected object
>
> self.name.type='integer'
> ------------------------------
> case 2) if 'values' is list of classes
>
> self.values[1].type=self.values[2].type
>
> thanks
Re: How define an ocl expression on type of an object [message #837493 is a reply to message #837475] Thu, 05 April 2012 14:39 Go to previous messageGo to next message
sohrab Missing name is currently offline sohrab Missing name
Messages: 17
Registered: November 2011
Junior Member
Thanks Ed,

But I didn't use java primitive data types at all. I use often user defined classes. for example I write

'self.values.classes->at(1)=self.values.classes->at(2)'

'classes' is the List of EClass. This list contains some objects (same type, different name), and I want ocl checks when their types are different.
for example if type of all objects in the 'classes' is 'ejob', this expression returns false (but if it cheks type of objects, it should return true).

Thanks
Re: How define an ocl expression on type of an object [message #837503 is a reply to message #837493] Thu, 05 April 2012 14:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3840
Registered: July 2009
Senior Member
On 05/04/2012 19:39, sohrab Mising name wrote:
> Thanks Ed,
>
> But I didn't use java primitive data types at all. I use often user
> defined classes.

So replace Integer in my examples by YourClass.
> for example I write
>
> 'self.values.classes->at(1)=self.values.classes->at(2)'
>
> 'classes' is the List of EClass. This list contains some objects (same
> type, different name), and I want ocl checks when their types are
> different.
> for example if type of all objects in the 'classes' is 'ejob', this
> expression returns false (but if it cheks type of objects, it should
> return true).
So you need to use oclType()

Regards

Ed Willink
Re: How define an ocl expression on type of an object [message #837510 is a reply to message #837503] Thu, 05 April 2012 15:16 Go to previous messageGo to next message
sohrab Missing name is currently offline sohrab Missing name
Messages: 17
Registered: November 2011
Junior Member
Thanks Ed,

But in my problem, I don't know class names. Indeed my constraint should be independent of class names (I can't determine class names implicitly). for example 'ejob' can be other classes like 'etask'.

Is 'oclType()' supported for any object in OCL? (i.e. can I write this: "self.oclType()='ejob'")

It not works for my models ("self.values.classes->at(1).oclType()")!
Re: How define an ocl expression on type of an object [message #837522 is a reply to message #837510] Thu, 05 April 2012 15:31 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 3840
Registered: July 2009
Senior Member
Hi

As I wrote earlier oclType() is supported in a fully reflective fashion
the new pivot-based Eclipse OCL.

oclType() is not supported on the Ecore-based Eclipse OCL; where you may
find that eClass() works.

Regards

Ed Willink

On 05/04/2012 20:16, sohrab Mising name wrote:
> Thanks Ed,
>
> But in my problem, I don't know class names. Indeed my constraint
> should be independent of class names (I can't determine class names
> implicitly). for example 'ejob' can be other classes like 'etask'.
>
> Is 'oclType()' supported for any object in OCL? (i.e. can I write
> this: "self.oclType()='ejob'")
> It not works for my models ("self.values.classes->at(1).oclType()")!
Previous Topic:Multiple XMI Resources concurrently
Next Topic:Avoiding 'import' in CompleteOclEditor using OCL Registry?
Goto Forum:
  


Current Time: Wed Apr 16 16:14:02 EDT 2014

Powered by FUDForum. Page generated in 0.02288 seconds