Java Reference
In-Depth Information
When regenerating code, the JMerge component is used to prevent overwrit-
ing user modifications. Generated Java code is annotated with @generated
javadoc style tags to identify it and distinguish it from user code. Removing the
tag or adding NOT after the tag ensures that JMerge will not overwrite the mod-
ified code. Typically, using @generated NOT is preferred because it allows the
Toolsmith to identify code that was generated and modified, as opposed to newly
added code. Note that not all code benefits from merging. Specifically,
plugin.xml and MANIFEST.MF files need to be deleted before an update can
occur.
3.2.4 Applying OCL
Many opportunities arise for using OCL in EMF models. Class constraints,
method bodies, and derived feature implementations can all be provided using
MDT OCL and EMF dynamic templates. The approach of using OCL and cus-
tom templates in this topic comes from an Eclipse Corner article [44] and has
been modified only slightly to conform to a similar approach taken to leverage
OCL added to models in QVT, as discussed in Section 6.5.6, “Leveraging OCL
in EMF Models.” The templates are generic and can easily be added to any proj-
ect that needs to provide OCL-based implementations in its generated model
code. It is also worth noting that GMF uses OCL extensively in its models,
employing an EMF Validator to maintain the integrity of its models.
To add an OCL expression to a model element, we begin by adding a nor-
mal EAnnotation. For the Source property, enter http://www.eclipse.org/
2007/OCL . This URI allows our custom templates and QVT engine to recognize
this annotation as OCL, where it can expect to find Details Entry children of
type constraint , derive , or body . Note that the original article [44] used
http://www.eclipse.org/ocl/examples/OCL as the URI.
Depending on the context, add the appropriate Key (EMF constraint key,
derive , or body ) to a child Details Entry of the EAnnotation and specify
the OCL in the Value property. For invariant constraints, the OCL annotations
complement the normal EMF constraint annotations by providing implementa-
tion for the validation framework to enforce constraints.
TIP
To test your OCL, it's helpful to use the Interactive OCL Console with a
dynamic instance of your model, as discussed in Section 1.5.4, “Object
Constraint Language.” Be sure to select the proper model element for the
expression, as well as the proper metalevel in the console.
 
Search WWH ::




Custom Search