Difference between revisions of "OCL/OCLinEcore"

From Eclipsepedia

< OCL
Jump to: navigation, search
m
Line 1: Line 1:
This page describes functionality available when EMF 2.6.0M4 or later and MDT/OCL 3.0.0M6 or later are installed within Eclipse.
+
This page describes functionality available in the Helios (Eclipse 3.6) release.
 +
 
 +
The description of the Ecore representation is followed by a brief example of the editor.
 +
 
 +
A tutorial introducing OCL and its integration with Ecore forms part of the OCL
 +
Developer Guide accompanying the OCL release and is available online at
 +
[http://help.eclipse.org/helios/index.jsp OCL Developer Guide].
 +
 
 +
[If you are reading this before Helios is released, the EMF functionality became
 +
available in EMF 2.6.0M4, the OCL integration in MDT/OCL 3.0.0M6, the OCLinEcore
 +
editor in 3.0.0M7 and the tutorial in 3.0.0RC3.]
  
 
==Ecore Representation==
 
==Ecore Representation==
Line 129: Line 139:
 
Note that preconditions and postconditions are ignored by MDT/OCL 3.0.0.
 
Note that preconditions and postconditions are ignored by MDT/OCL 3.0.0.
  
==OCL in Ecore Editor==
+
==OCLinEcore Editor==
  
 
The Sample Ecore Editor is convenient for maintaining a couple of OCL constraints, but it has distinct limitations as an Integrated OCL Development Environment:
 
The Sample Ecore Editor is convenient for maintaining a couple of OCL constraints, but it has distinct limitations as an Integrated OCL Development Environment:
Line 136: Line 146:
 
* syntactic and semantic errors in the OCL are not detected.
 
* syntactic and semantic errors in the OCL are not detected.
  
The OCL in Ecore Editor overcomes these limitations. The Editor is(starting at M7) available for use with MDT/OCL 3.0.0 by activating the MDT/OCL 3.0.0 Examples functionality.  
+
The OCLinEcore Editor overcomes these limitations. The Editor is (starting at M7) available for use with MDT/OCL 3.0.0 by activating the MDT/OCL 3.0.0 Examples functionality.  
  
: As of the MDT/OCL 3.0.0M7 release, the Examples functionality may be installed directly using Install New Software from MDT/OCL Update site [http://download.eclipse.org/modeling/mdt/ocl/3_0/updates/milestones/ MDT/OCL Update site] or indirectly after downloading [http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/3.0.0/S201005040447/mdt-ocl-Update-3.0.0M7.zip mdt-ocl-Update-3.0.0M7.zip]. Everything that is required should be downloaded automatically.
+
: As of the MDT/OCL 3.0.0RC3 release, the Examples functionality may be installed directly using Help->Install New Software from the http://download.eclipse.org/releases/helios site; Select the OCL Examples and Editors Feature from the Modeling category.
  
With the OCL in Ecore Editor installed, you may select the Ecore file in a Navigator (Resource Explorer, Package Explorer,...) and invoke Open With->OCL in Ecore Editor from the context dependent right button menu. The display should show  
+
With the OCLinEcore Editor installed, you may select the Ecore file in a Navigator (Resource Explorer, Package Explorer,...) and invoke Open With->OCLinEcore Editor from the context dependent right button menu. The display should show  
  
 
[[image:OCLinEcore.png]]
 
[[image:OCLinEcore.png]]
  
The above display is the unchanged result of opening Company.ecore. As can be seen, there is a useful amount of pretty printing, but clearly more is till required. This is work in progress. As soon as you type any character (an M6 Xtext feature) validation occurs and the above then shows 12 errors. These will be fixed before RC1.
+
The above display is the unchanged result of opening Company.ecore. As can be seen, there is a useful amount of pretty printing, but clearly more is still required. This is work in progress.
  
 
This OCL Document may be edited with the aid of syntax and semantic validation and completion suggestions.
 
This OCL Document may be edited with the aid of syntax and semantic validation and completion suggestions.

Revision as of 06:01, 5 June 2010

This page describes functionality available in the Helios (Eclipse 3.6) release.

The description of the Ecore representation is followed by a brief example of the editor.

A tutorial introducing OCL and its integration with Ecore forms part of the OCL Developer Guide accompanying the OCL release and is available online at OCL Developer Guide.

[If you are reading this before Helios is released, the EMF functionality became available in EMF 2.6.0M4, the OCL integration in MDT/OCL 3.0.0M6, the OCLinEcore editor in 3.0.0M7 and the tutorial in 3.0.0RC3.]

Contents

Ecore Representation

The OCL in Ecore annotations can be maintained directly using the Sample Ecore Editor. An example is shown below.

Example OCL in Ecore Annotations

The relevant annotations (a purple dumbbell with a paperclip) may be added by selecting New Child->EAnnotation and then New Child->Details Entry.

EPackage configuration

The embedded OCL becomes active when the appropriate delegate functionality is specified. In practice all three functionalities should be specified. This specification provides EMF with the required configuration information to access the extended functionality provided by these delegates.

Setting Delegate

The setting delegate functionality enables OCL expressions to define initial or derived value of an EStructuralFeature. Thus when eGet(CompanyPackage.Literals.COMPANY__SIZE) or Company.getSize() is invoked the OCL expression is evaluated to provide the value. In an OCL context, the corresponding eSet or setSize is not applicable.

The setting delegate is specified by an EPackage EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore"
Key = "settingDelegates"
Value = "http://www.eclipse.org/emf/2002/Ecore/OCL"

The delegate value matches an org.eclipse.emf.ecore.setting_delegate extension point usage in the org.eclipse.ocl.ecore plug-in that provides the delegate functionality. Multiple comma-separated delegates may be specified.

Invocation Delegate

The invocation delegate functionality enables OCL expressions to define the body of an EOperation. Thus when eInvoke(CompanyPackage.Literals.EMPLOYEE__REPORTS_TO) or Employee.reportsTo() is invoked the OCL expression is evaluated to provide the value.

The invocation delegate is specified by an EPackage EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore"
Key = "invocationDelegates"
Value = "http://www.eclipse.org/emf/2002/Ecore/OCL"

The delegate value matches an org.eclipse.emf.ecore.invocation_delegate extension point usage in the org.eclipse.ocl.ecore plug-in that provides the delegate functionality. Multiple comma-separated delegates may be specified.

Note: When generating the java classes from your genmodel, remember to set the genmodel option 'Operation Reflection' to true

Validation Delegate

The validation delegate functionality enables OCL expressions to define one or more invariants of an EClassifier. Thus when the EValidator is activated to validate the classifier, the OCL expressions are evaluated.

The validation delegate is specified by an EPackage EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore"
Key = "validationDelegates"
Value = "http://www.eclipse.org/emf/2002/Ecore/OCL"

The delegate value matches an org.eclipse.emf.ecore.validation_delegate extension point usage in the org.eclipse.ocl.ecore plug-in that provides the delegate functionality. Multiple comma-separated delegates may be specified.

EClassifier invariants

Ecore provides two different representation for an OCL invaraint that refines the behavior of an EClassifier. One representation exposes the invariant as part of the EClassifier API.

Each non-API invariant is represented as an EAnnotation for the named OCL-invariant constraint and an EAnnotation to enumerate the invariant names. This form of OCL invariant is called a constraint in Ecore documentation. The invariant does not contribute to the EClassifier API.

Each API invariant is represented by an EOperation for the named OCL-invariant constraint, with an EAnnotation to define the operation body. This form of OCL invariant is called an invariant in Ecore documentation. The EOperation contributes to the EClassifier API allowing it to be invoked by application code; perhaps for incremental re-evaluation of invariants.

non-API invariant

The example shows the specification of the body for the Employee mustHaveName invariant equivalent to the following OCL Document snippet.

context Employee
inv mustHaveName:
not name.oclIsUndefined()

The body is specified by an EClassifier EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore/OCL"
Key = "mustHaveName"
Value = ...the OCL expression...

and an EClassifier EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore"
Key = "constraints"
Value = space-separated list of invariant names

API invariant

The example partially shows the specification of the body for the Employee noManagerImpliesDirectReports invariant equivalent to the following OCL Document snippet.

context Employee
inv noManagerImpliesDirectReports:
manager.oclIsUndefined() implies directReports->size() > 0

There is no need for any EClassifier EAnnotation. The invariant body should be specified as an EOperation body.

The EOperation must have an EBoolean return, and two parameters of type EDiagnosticChain and EMap<EjavaObject, EJavaObject>.

EStructuralFeature initial and derived values

The example shows the specification of a derived value for the Company::size EStructuralFeature equivalent to the following OCL Document snippet.

context Company::size : CompanySizeKind
derive:
let table : Set(Tuple(range : Sequence(Integer), size : CompanySizeKind)) =
    Set{
	Tuple{range=Sequence{0..49}, size=CompanySizeKind::small},
        Tuple{range=Sequence{50..999}, size=CompanySizeKind::medium},
        Tuple{range=Sequence{1000..1000000}, size=CompanySizeKind::large}}
    in table->any(range->includes(employees->size())).size

The derived value is specified by an EStructuralFeature EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore/OCL"
Key = "derivation"
Value = ...the OCL expression...

An initial value may be similarly specified with:
Source = "http://www.eclipse.org/emf/2002/Ecore/OCL"
Key = "initial"
Value = ...the OCL expression...

EOperation bodies, preconditions and postconditions

The example shows the specification of the body for the Employee::reportsTo(Employee) EOperation equivalent to the following OCL Document snippet.

context Employee::reportsTo(manager : Employee) : Boolean
body:self.reportingChain->includes(manager)

The body is specified by an EOperation EAnnotation with:
Source = "http://www.eclipse.org/emf/2002/Ecore/OCL"
Key = "body"
Value = ...the OCL expression...

A precondition or postcondition may be similarly specified using "precondition" or "postcondition" as the Key.

Note that preconditions and postconditions are ignored by MDT/OCL 3.0.0.

OCLinEcore Editor

The Sample Ecore Editor is convenient for maintaining a couple of OCL constraints, but it has distinct limitations as an Integrated OCL Development Environment:

  • maintenance of the EAnnotations needs care.
  • the OCL expression is difficult to read in the Properties View.
  • syntactic and semantic errors in the OCL are not detected.

The OCLinEcore Editor overcomes these limitations. The Editor is (starting at M7) available for use with MDT/OCL 3.0.0 by activating the MDT/OCL 3.0.0 Examples functionality.

As of the MDT/OCL 3.0.0RC3 release, the Examples functionality may be installed directly using Help->Install New Software from the http://download.eclipse.org/releases/helios site; Select the OCL Examples and Editors Feature from the Modeling category.

With the OCLinEcore Editor installed, you may select the Ecore file in a Navigator (Resource Explorer, Package Explorer,...) and invoke Open With->OCLinEcore Editor from the context dependent right button menu. The display should show

OCLinEcore.png

The above display is the unchanged result of opening Company.ecore. As can be seen, there is a useful amount of pretty printing, but clearly more is still required. This is work in progress.

This OCL Document may be edited with the aid of syntax and semantic validation and completion suggestions.

Whitespace and OCL comments within and surrounding the OCL expressions are persisted in the Ecore EAnnotations.

The OCLinEcore uses strict OMG syntax for OCL expressions and an extrapolation of that to the surrounding Ecore. A full write up is TBD. The surrounding syntax of the example editor is open to debate and may change once the editor ceases to be an example in the release after Helios.