Get the query result from OCL Java API in the format of XText OCL result [message #1836778] |
Wed, 13 January 2021 13:35  |
Eclipse User |
|
|
|
Hi,
I am using the OCL Java API to evaluate a query programmatically.
For instance, for the following query
self.ownedElements->select(o|o.oclIsKindOf(ForkDecision))
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,
Faezeh
|
|
|
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 14:02  |
Eclipse User |
|
|
|
Hi
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.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03168 seconds