Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Evaluating pivot OCL programmatically
Evaluating pivot OCL programmatically [message #1710720] Thu, 08 October 2015 16:02
Jens Bürger is currently offline Jens BürgerFriend
Messages: 40
Registered: October 2012
Member
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?
Previous Topic:Eclipse Issue with Editor
Next Topic:Announce: Additional Luna maintenance release
Goto Forum:
  


Current Time: Thu Oct 19 20:24:37 GMT 2017

Powered by FUDForum. Page generated in 0.01863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software