Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Hierarchy cast with oclAsType
Hierarchy cast with oclAsType [message #651426] Sun, 30 January 2011 20:17 Go to next message
Cristiano Gaviao is currently offline Cristiano GaviaoFriend
Messages: 253
Registered: July 2009
Senior Member
Hi, I'm learning OCL and I need a little help with my example.

I have 4 classes and 1 interface:
Partner (interface)

Person : Partner

Company : Partner
employees Employee[*]

Employee
person Person[1]

Job
partner Partner
responsible : Person

I need to constrain the Job class. When partner were <> null and were a Company so only its employees can be the Person responsible.
But f the partner where a Person, so only himself could be the responsible.

I've started by writing this at oclecore editor on Job:

invariant responsibleShouldBeEmployeeOrHimself:
if (responsible <> null and owner <> null and owner.oclIsTypeOf(Company)) then
owner.oclAsType(Company).employees -> exists(responsible)
else
false
endif;

well it wasn't a good try at all. builders raises a error: "Couldn't resolve reference to NamedElementCS 'employees'.

Could someone help build this constraint?

Thanks in advance

Cristiano
Re: Hierarchy cast with oclAsType [message #651454 is a reply to message #651426] Mon, 31 January 2011 06:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4189
Registered: July 2009
Senior Member
Hi Cristiano

The OCLinEcore editor was a rather rushed contribution to have some kind
of editor in the Helios release. It has significant limitations in its
semantic understnading. You have found one. This is fixed in the Indigo
release, for which M5 could be available tomorrow. Even though the
OCLinEcore editor's Xtext/ANTLR parser gives an error, the exprerssion
can still be used, since in the Helios release a different LPG parser is
actually used when compiling and validating, either in the Sample
Reflective Ecore Editor or OCL Console.

It is not a good idea to compare with null since you also need to
consider invalid.

You might find

invariant: responsible->notEmpty() and owner->notEmpty() and
owner.oclIsTypeOf(Company))
and owner.oclAsType(Company).employees -> exists(responsible);

a little clearer. The owner->notEmpty() should be redundant.

Legibility and diagnostic quality may justify naming partial invariants

invariant HasResponsibility: responsible->notEmpty();
invariant HasCompanyAsOwner: owner->notEmpty() and
owner.oclIsTypeOf(Company));
invariant HasResponsibleEnmployee: owner.oclAsType(Company).employees ->
exists(responsible);

Regards

Ed Willink

On 30/01/2011 20:17, Cristiano Gaviao wrote:
> Hi, I'm learning OCL and I need a little help with my example.
>
> I have 4 classes and 1 interface:
> Partner (interface)
>
> Person : Partner
>
> Company : Partner
> employees Employee[*]
>
> Employee
> person Person[1]
>
> Job partner Partner
> responsible : Person
>
> I need to constrain the Job class. When partner were <> null and were
> a Company so only its employees can be the Person responsible.
> But f the partner where a Person, so only himself could be the
> responsible.
>
> I've started by writing this at oclecore editor on Job:
>
> invariant responsibleShouldBeEmployeeOrHimself: if (responsible <>
> null and owner <> null and owner.oclIsTypeOf(Company)) then
> owner.oclAsType(Company).employees -> exists(responsible)
> else
> false
> endif;
>
> well it wasn't a good try at all. builders raises a error: "Couldn't
> resolve reference to NamedElementCS 'employees'.
>
> Could someone help build this constraint?
>
> Thanks in advance
>
> Cristiano
Re: Hierarchy cast with oclAsType [message #651885 is a reply to message #651454] Tue, 01 February 2011 21:36 Go to previous messageGo to next message
Cristiano Gaviao is currently offline Cristiano GaviaoFriend
Messages: 253
Registered: July 2009
Senior Member
Hi Ed,

Thanks for tips !! Very Happy

btw, do you know any link where could I learn more best practices on constructing ocl sentences?

good to know that new release is coming soon. I'm waiting it to test your tips.

But I did some tests today using helios and I was just thinking and would like to ask to you...:

Wondering if could be possible to use OCL to filter data that id show on combobox at generated editor ? I mean, could I use the inv HasResponsibleEnmployee to instead of constrain after I save the document, to "select" and restrict the instances to be shown ?

thanks a lot

Cristiano

Re: Hierarchy cast with oclAsType [message #652106 is a reply to message #651885] Wed, 02 February 2011 17:04 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4189
Registered: July 2009
Senior Member
Hi Cristiano

"Wondering if could be possible" ...

It's only software and a sensible idea so of course yes.

But. Interesting idea for future directions, as e4 increases the extent
to which information is modelled. It may be possible for OCL to be used
as a platform expression language.

Regards

Ed Willink


On 01/02/2011 21:36, Cristiano Gaviao wrote:
> Hi Ed,
>
> Thanks for tips !! :d
> btw, do you know any link where could I learn more best practices on
> constructing ocl sentences?
> good to know that new release is coming soon. I'm waiting it to test
> your tips.
>
> But I did some tests today using helios and I was just thinking and
> would like to ask to you...:
> Wondering if could be possible to use OCL to filter data that id show
> on combobox at generated editor ? I mean, could I use the inv
> HasResponsibleEnmployee to instead of constrain after I save the
> document, to "select" and restrict the instances to be shown ?
>
> thanks a lot
>
> Cristiano
>
>
Previous Topic:EclipseCon 2011 tutorial: Enrich Your Models With OCL
Next Topic:OCLs for abstract classes and children
Goto Forum:
  


Current Time: Mon Dec 22 17:49:21 GMT 2014

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

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