Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OCL/OCLinEcore

< OCL
Revision as of 12:08, 27 February 2010 by Ed.willink.me.uk (Talk | contribs) (Property initial and derived values)

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 = "invocation Delegates"
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.

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 = "validation Delegates"
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.

Classifier invariants

Property 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

Operation bodies, preconditions and postconditions

Back to the top