How to pass a java variable to OCL statement? [message #1063179] |
Wed, 12 June 2013 14:31 |
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 14:32] Report message to a moderator
|
|
|
|
|
|
Re: How to pass a java variable to OCL statement? [message #1063426 is a reply to message #1063200] |
Thu, 13 June 2013 07:18 |
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 09:08] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03017 seconds