Hello everyone,
as a kind of follow up to https://www.eclipse.org/forums/index.php/t/1068491/ I want to do the evaluations discussed there programmatically.
I have working code for evaluations using the old OCL implementation. But as I need to query stereotypes, I am requested to switch to the pivot implementation.
The old code looks like this:
EObject root=modelGraph().getRoots().get(0); // eGraph containing the UML model
EClass oclContext=modelGraph().getRoots().get(0).eClass()
String oclStatement="here goes my OCL statement";
OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
BooleanOCLCondition<EClassifier, EClass, EObject> condition = new BooleanOCLCondition<EClassifier, EClass, EObject>(
ocl.getEnvironment(),
oclStatement,
oclContext);
HashSet<EObject> result=(HashSet<EObject>) condition.evaluate(root);
After consulting the OCL documentation of Eclipse Mars, I adapted the example:
org.eclipse.ocl.pivot.utilities.OCL ocl=org.eclipse.ocl.pivot.utilities.OCL.newInstance();
org.eclipse.ocl.pivot.ExpressionInOCL query;
try {
query = ocl.createQuery(modelGraph().getRoots().get(0).eClass(),
"Transition.allInstances().extension_ensureRole->excluding(null).role");
org.eclipse.ocl.pivot.utilities.Query queryEval = ocl.createQuery(query);
Object t=queryEval.evaluateUnboxed(modelGraph().getRoots().get(0));
} catch (org.eclipse.ocl.pivot.utilities.ParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But the ocl.createQuery(...) call actually throws a
org.eclipse.ocl.pivot.utilities.SemanticException: The 'UML::Model' constraint is invalid: 'Transition.allInstances().extension_ensureRole->excluding(null).role'
1: Unresolved Property 'Set(UML::Transition[*|1])::extension_ensureRole'
at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:144)
...
I also tried instantiating ocl by passing on the existing resourceSet, but this makes no difference.
What am I missing?