I'm working on a java application that takes as input a set of valid models and a set of invalid models, OCL constraints are generated automatically, my objective is to check if the models are violating the constraints or no.
I found on this topic an answer but the parameters aren't very clear.
Does anyone know what should I make instead of "EXTLibraryPackage.Literals.LIBRARY"
// create an OCL helper object OCLHelper helper = ocl.createOCLHelper();
// set the OCL context classifier
helper.setContext(EXTLibraryPackage.Literals.LIBRARY);
Constraint invariant = helper.createInvariant(
"books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");
OCLExpression<EClassifier> query = helper.createQuery(
"books->collect(b : Book | b.category)->asSet()");
OCL defines expressions upon models for which you must provide the metamodel so that OCL understands your type system. EXTLibraryPackage.Literals.LIBRARY is a reference to the genmodeled Package at the root of the EXTLibrary example.
To reuse the same style you should genmodel your models and reference the corresponding EPackages.
However using OCL programmatically in this way is far from the only or best way. If you have models then you can load your model in the Sample Ecore Editor and validate there. See the Validation aspects of the Eclipse OCL Documentation. You may even convert your OCL to Java to avoid the costs of executing OCL in an interpreter.