Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Get the query result from OCL Java API in the format of XText OCL result
Get the query result from OCL Java API in the format of XText OCL result [message #1836778] Wed, 13 January 2021 18:35 Go to next message
Faezeh Khorram is currently offline Faezeh KhorramFriend
Messages: 9
Registered: June 2020
Junior Member

I am using the OCL Java API to evaluate a query programmatically.
For instance, for the following query

the retrieved result is:
[org.imt.bpmn.impl.ForkDecisionImpl@7106e80e (label: is employee level junior?)]

which uses the java class names for the identification of the retrieved objects.

However, when I try to evaluate the same query using XText OCL, the result is in another format that is more readable:
Microflow promoteEmployee::Fork Decision is employee level junior?

The question is: how can I get the query evaluation result using Java API in the second format?

Best regards,
Re: Get the query result from OCL Java API in the format of XText OCL result [message #1836780 is a reply to message #1836778] Wed, 13 January 2021 19:02 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7663
Registered: July 2009
Senior Member

EMF, whose APIs underpin Eclipse OCL, has a variety of display strategies. The commonest is the auto-generated toString() that gives the result that you find unsatisfactory. You can fix this by manually re-implementing the toString() methods. For the built-in Eclipse OCL models I redirect these all via super to a ToStringVisitor that exploits an auto-generated extensible Visitor framework..

EMF also provides the SubstitutionLabelProvider which helps format an EObject for the EValidator. This is often better.

To make the Sample Ecore Editor more satisfactory, genmodel uses some heuristics to pick a 'name'/'id'/ID/EString attribute as the name of an EObject.

Eclipse OCL extends the SubstitutionLabelProvider with a LabelSubstitutionLabelProvider that redirects to a registry of ILabelGenerator that can be defined by the org.eclipse.ocl.pivot.label_generator extension point. The org.eclipse.ocl.pivot.internal.labels.EObjectLabelGenerator is perhaps what is giving you a pleasanter read. It will use an ID attribute if one is declared. Rather than manually implementing toString, you can register ILabelGenerator classes for your model classes.


Ed Willink

Previous Topic:run OCL on models programmatically
Next Topic:Missing Javadoc
Goto Forum:

Current Time: Sun Jul 14 20:24:03 GMT 2024

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

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

Back to the top