Java Reference
In-Depth Information
* The body of the generated method for a Java initializer can be provided in
the model. Later, we'll need to set the GenJavaExpressionProvider element's
injectExpressionBody property to true in our generator model for the fol-
lowing code to appear in our output. Note the use of fully qualified class names,
which the generator cleans up.
org.eclipse.oocore.Reference opposite =
org.eclipse.oocore.OocorePackage.eINSTANCE.getOocoreFactory()
.createReference();
opposite.setOpposite(self);
opposite.setBidirectional(true);
opposite.setType(self.getOwner());
opposite.setName(self.getOwner().getName().toLowerCase());
((org.eclipse.oocore.Class)
self.getType()).getFeatures().add(opposite);
return opposite;
For our Association element, we set a constraint based on the
aggregation property to distinguish these links from our Aggregation links.
We also initialize the aggregation property to false , set the bidirectional
property to true , and create the opposite end Reference using the injected
Java code above; after that, we set the name of the reference to the name of the
opposite. An important side effect of using an Association to create an oppo-
site Reference in this case is that we won't get a duplicate link drawn, as would
be the case if we specified a Reference type for the link. The reason is that no
link mapping is defined for a plain Reference .
As you can tell, the links in the color modeling diagram remove a lot of the
underlying complexity present in the domain model. Features are initialized to
values that limit the range of modeling capabilities, keeping it simple for the
Practitioner. We can expose more functionality in the future, but for now we will
create bidirectional links and allow for only the specificity of target cardinality.
Our Association class is not as powerful as what the UML provides, but that's
not the point of this diagram.
TIP
Feature initialization occurs in the order of listing, so if an initialization of a
feature depends on another feature being initialized first, be sure to list
them in the proper order.
 
Search WWH ::




Custom Search