Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Performing queries in KDM with OCL
Performing queries in KDM with OCL [message #1748398] Tue, 22 November 2016 18:01 Go to next message
Daniel San Martín is currently offline Daniel San MartínFriend
Messages: 21
Registered: October 2012
Junior Member
Hello,

I want to generate java code from a KDM model (ECore type) with xtend. I can do that with this method in xtext project.

 override doGenerate(Resource resource, IFileSystemAccess fsa) 


Nevertheless, the KDM model has an hierarchical structure so I cannot access to certain elements of the model, for example ClassUnits elements.

I thought to use this line:

 for (ClassUnit classUnit : resource.contents.filter(typeof(ClassUnit))) 


but returns null. Thus, I think to performs queries over the model. I think the best solution is to use OCL but i have some problems to setup it in my plugin.
My idea is to perform the query by using resource variable because it contains the model, but I do not how to do this.

I tried some codes from eclipse help

 private OCL ocl;
	private  OCLHelper<EClassifier, ?, ?, Constraint> helper;


then,
 
this.ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
	this.helper = ocl.createOCLHelper();


I have problem with this.. I tried with EcorePackage.eINSTANCE but does not work..
 
helper.setContext(....);


How can I run OCL queries by taking into account my resources variable with the model in memory?

Thanks,

Daniel
Re: Performing queries in KDM with OCL [message #1748399 is a reply to message #1748398] Tue, 22 November 2016 18:12 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5431
Registered: July 2009
Senior Member
Hi

If you are already using Xtend, I cannot really recommend that you add non-trivial complexity to your project by using OCL as well. You should really identify why you cannot solve the problem with Xtend, or more simply just Java. You seem to be running away from a 2-hour debugging problem by introducing a 2-week familiarization/releng problem.

Of course, if you need OCL for other reasons, ignore the criticism above. You may find it helpful to use OCLinEcore to enrich your metamodel internally or Complete OCL externally. Read the tutorials. Whichever, I would recommend the new PIvot-based OCL that amongst many other improvements avoids the needs for long Java template parameter lists.

Regards

Ed Willink



Previous Topic:How should max,min handle null case ?
Next Topic:choosing "Property::CompatibleDefaultExpression" for programmatically defined pivot types
Goto Forum:
  


Current Time: Fri Oct 20 16:27:17 GMT 2017

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

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