Java Reference
In-Depth Information
will reuse this set of templates. Then return to Section 3.2.4 and configure the
mindmap.ecore
model to use OCL to implement the
rootTopics
feature.
We can leverage OCL in our model in additional places to provide an imple-
mentation and avoid having to modify our generated code. Let's begin by adding
a method that returns the full set of subtopics for a given
Topic
.
Finding All Subtopics
Currently, our model has a
subtopics
reference on each
Topic
, along with a
method,
allSubtopics()
, that is intended to return a list of all of a
Topic
's
subtopics—that is, its subtopics, all of their subtopics, and so on. All methods
declared in an Ecore model require an implementation to be provided, so we turn
to OCL, where the implementation of this method is trivial, thanks to the non-
standard
closure
iterator in MDT OCL:
self->closure(subtopics)
We need to add an
EAnnotation
to the method in our model with
Source
added to the annotation with the previous expression as its
Value
property and
with a
Key
value of
body
.
When we regenerate our model code, we can see that
our implementation is provided:
/**
* The parsed OCL expression for the body of the
* '{@link #allSubtopics <em>All Subtopics</em>}' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
@see
#allSubtopics
* @generated
*/
private static
OCLExpression<EClassifier> allSubtopicsBodyOCL;
private static final
String OCL_ANNOTATION_SOURCE =
"http://www.eclipse.org/2007/OCL";
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public
EList<Topic> allSubtopics() {
if
(allSubtopicsBodyOCL ==
null
) {
EOperation eOperation =
MindmapPackage.Literals.TOPIC.getEOperations().get(0);
OCL.Helper helper = OCL_ENV.createOCLHelper();
Search WWH ::
Custom Search