Java Reference
In-Depth Information
To invoke the provided OCL at runtime, you must use custom JET templates
for your domain model. The generated code retrieves the OCL statement from
the model element and invokes it, evaluating the result. An alternative to this is
to generate a Java implementation of the OCL during generation and avoid
invoking the OCL interpreter at runtime.
The referenced article covers the details of the custom templates, so they are
not covered here. Also, the templates are included in the topic's sample projects
and are touched upon during the development of the sample projects. For now,
we take a look at just the derived feature implementation, both before and after
using the OCL with a custom template approach. First, consider the default gen-
erated code for a derived reference—in this case, the rootTopics reference from
the MapImpl class in our mindmap example.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<Topic> getRootTopics() {
// TODO : implement this method to return the 'Root Topics'
// reference list
// Ensure that you remove @generated or mark it @generated NOT
// The list is expected to implement
// org.eclipse.emf.ecore.util.InternalEList and
// org.eclipse.emf.ecore.EStructuralFeature.Setting
// so it's likely that an appropriate subclass of
// org.eclipse.emf.ecore.util.EcoreEList should be used.
throw new UnsupportedOperationException();
}
Let's add the following OCL statement to the derived feature using the pre-
vious convention. Here we see the annotation within the mindmap.ecore model
in its native XMI serialization. Note that this OCL statement could be simplified
by using the parent eOpposite relationship on our Topic's subtopics reference,
which was added to facilitate the diagram definition of Section 4.3.5, “Subtopic
Figure.”
<eStructuralFeatures xsi:type="ecore:EReference"
name="rootTopics" upperBound="-1" eType="#//Topic" volatile="true"
transient="true" derived="true">
<eAnnotations source="http://www.eclipse.org/2007/OCL">
<details key="derive"
value="let topics : Set(mindmap::Topic) = self.elements->
select(oclIsKindOf(mindmap::Topic))->
collect(oclAsType(mindmap::Topic))->asSet() in
Search WWH ::




Custom Search