2

I am trying to use OCL conditions based on a ecore user model. My first question is whether it is even possible to use OCL conditions in this context or not. So in my special case the user is able to create an own model with its own tasks, sequence flows, variables and so on. The user is also able to define his own OCL conditions in the runtime. So far so good.

A simple example: I would like to create a condition that verifies whether the value of the variable of the user model xy > 5. My problem is that i want to evaluate the conditions on the user model itself, NOT the meta model of it. In every code snippet i've seen (like this below) the context of the OCLHelper was set on a meta model (Literals.LIBRARAY).

How can I use the OCL conditions for my purposes?

OCL ocl = OCL.newInstance(new PivotEnvironmentFactory());
OCLHelper helper = ocl.createOCLHelper(EXTLibraryPackage.Literals.LIBRARY);
ExpressionInOCL invariant = helper.createInvariant(
    "books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");
ExpressionInOCL query = helper.createQuery(
    "books->collect(b : Book | b.category)->asSet()");

// create a Query to evaluate our query expression
Query queryEval = ocl.createQuery(query);
// create another to check our constraint
Query constraintEval = ocl.createQuery(invariant);
Braveness
  • 49
  • 7

1 Answers1

0

If you want OCL in Ecore you will probably find that using the OCLinEcore editor makes life much easier.

The argument to createOCLHelper identifies your type system, i.e your metamodel. The constraints are checked on instances of these types. i.e your model.

Regards

Ed Willink

Ed Willink
  • 1,205
  • 7
  • 8