Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to pass a java variable to OCL statement?
How to pass a java variable to OCL statement? [message #1063179] Wed, 12 June 2013 10:31 Go to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Hi there,

// set OCL context classifier
helper.setContext(ModelPackage.Literals.DEVICE);

Constraint invariant = helper.createInvariant("Module.allInstances()->size()<=6 ");

Query eval = ocl.createQuery(invariant);

validation = (Boolean) eval.evaluate(device);


A device has a set of modules. This is an example to validate a device object for the maximum number of modules. In here "Module.allInstances()->size()<=6 " is OCL syntax.

Problem:

Is it possible to define 6 in a java variable and call it in here?

such as,

int maxModules=6;
Constraint invariant = helper.createInvariant("Module.allInstances()->size()<=maxModules ");

I know this is not right.

How to pass a java variable to OCL statement?

Thanks in advance!
K

[Updated on: Wed, 12 June 2013 10:32]

Report message to a moderator

Re: How to pass a java variable to OCL statement? [message #1063180 is a reply to message #1063179] Wed, 12 June 2013 10:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Hi

Passing a variable to an invariant is a very wrong way of looking at things.

You may of course referebce properties within invraiants, so if you
arrange for your 'variable' to be in a suitable property you can use it.

Regards

Ed Willink


On 12/06/2013 15:31, Kosala Yapa wrote:
> Hi there,
>
> // set OCL context classifier
> helper.setContext(ModelPackage.Literals.DEVICE);
>
> Constraint invariant =
> helper.createInvariant("Module.allInstances()->size()<=6 ");
>
> Query eval = ocl.createQuery(invariant);
>
> validation = (Boolean) eval.evaluate(device);
>
>
> A device has a set of modules. This is an example to validate a device
> object for number of modules. In here
> "Module.allInstances()->size()<=6 " is OCL syntax.
>
> Problem:
>
> Is it possible to define 6 in a java variable and call it in here?
>
> such as,
>
> int maxModules=6;
> Constraint invariant =
> helper.createInvariant("Module.allInstances()->size()<=maxModules ");
>
> I know this is not right.
> How to pass a java variable to OCL statement?
>
> Thanks in advance!
> K
Re: How to pass a java variable to OCL statement? [message #1063197 is a reply to message #1063180] Wed, 12 June 2013 11:20 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
TX Ed.

What do you mean properties in here?

Cheers,
Re: How to pass a java variable to OCL statement? [message #1063200 is a reply to message #1063197] Wed, 12 June 2013 11:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
HI

A Package contains Classes and a Class contains Properties/Operations.

Regards

Ed Willink


On 12/06/2013 16:20, Kosala Yapa wrote:
> TX Ed.
>
> What do you mean properties in here?
> Cheers,
Re: How to pass a java variable to OCL statement? [message #1063426 is a reply to message #1063200] Thu, 13 June 2013 03:18 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
TX.

if TorderNumber is a property in the class you define invariant, then invariant could be,

Constraint invariant = helper.createInvariant("HeadModule.allInstances()->exists(m:HeadModule|m.orderNumber=TorderNumber )");

Is that you mean?
I know, the above invariant cannot be right.




IMO, you probably meant property is a field in the model.
Of course, if TorderNumber is a field in the model, yes can access that in an invariant, but that is not my requirement.


My requirement is, Passing a java variable/constant (which is not in the model) to OCL invariant.
Is this possible in OCL?


Cheers,
K

[Updated on: Thu, 13 June 2013 05:08]

Report message to a moderator

Re: How to pass a java variable to OCL statement? [message #1063498 is a reply to message #1063426] Thu, 13 June 2013 06:11 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Yes

On 13/06/2013 08:18, Kosala Yapa wrote:
> TX.
>
> if maxModules is a property, then invariant could be,
>
>
> Constraint invariant =
> helper.createInvariant("Module.allInstances()->size()<= maxModules ");
>
> Is that you mean?
>
> Cheers,
> K
>
Previous Topic:OCL closure works properly with Interactive OCL, not Interactive Xtext OCL
Next Topic:[Announce] Eclipse OCL 4.1.0 (Kepler) RC4 is available.
Goto Forum:
  


Current Time: Mon Jul 28 22:37:10 EDT 2014

Powered by FUDForum. Page generated in 0.02612 seconds