OCL Relationship to Metamodels

The OCL implementation provides support for models defined using either the Ecore or the UML metamodel (as implemented by the Eclipse EMF and UML2 projects), and an extensibility API that allows additional EMF-based metamodels to be plugged in.

The OCL API implements support for different target metamodels via the EnvironmentFactory interface. An implementation of this interface binds the metamodel's metaclasses to the generic type parameters of the OCL class. The metamodel-specific Environment implementation constructed by this factory implements the reflection capability required by OCL to discover the elements of the model being constrained and the relationships between them.

The Ecore Metamodel Binding

An OCL binding for the Ecore metamodel is provided by the org.eclipse.ocl.ecore plug-in. It is best suited to parsing and evaluating OCL constraints on Ecore models. Evaluation of constraints is supported on instances of the EMF-generated Java API (Ecore as the source for the genmodel) and on dynamic EObjects.

As is illustrated by most of the examples in this documentation, the Ecore binding is provided by the EcoreEnvironmentFactory class. By default, the Ecore environment uses the static EPackage registry to look up package names. It can also be supplied with an alternative package registry (for example, one local to a ResourceSet) but it will always use the static registry as a backup. Aside from the package registry, the Ecore environment factory maintains no state. So, when the shared registry is to be used, the static EcoreEnvironmentFactory.INSTANCE is most practical.

The Ecore binding for OCL provides the following capabilities, reflecting the subset of Ecore's modeling constructs with respect to UML:

Ecore metamodel capability matrix
CapabilityParseEvaluate
Classifier invariant constraintsYY
Operation precondition and postcondition constraints and body conditionsYN
Property constraints (initial-value and derivation)YY1
Attribute and operation definitions (def: expressions)YY
Package context declarationYn/a
Basic values and types, mapped from the standard EDataTypes to OCL's primitive typesYY
Collection typesYY
Navigation of attributes and referencesYY
Operation invocationYY
Iteration expressions (all standard iterators)YY
Let expressionsYY
If expressionsYY
TuplesYY
Message expressions, including unspecified valuesYN
Operations predefined by OCL: allInstances()YY
Operations predefined by OCL: oclIsKindOf(), oclIsTypeOf(), oclAsType()YY
Operations predefined by OCL: oclIsNew()YN
@pre expressionsYN
1 derivation only

Because Ecore does not define analogues of some of the UML metaclasses required by the OCL Abstract Syntax Model, the Ecore binding defines these on its behalf, in the platform:/plugin/org.eclipse.ocl.ecore/model/OCLEcore.ecore metamodel. These include:

For applications that work exclusively with the Ecore binding for OCL, the org.eclipse.ocl.ecore package defines a subclass of the OCL class that supplies all of the generic type parameter bindings to simplify typing (in the absence of type aliasing in Java). It also provides Ecore-specific convenience factory methods for the OCL, itself, and narrows the return type of the factory methods for the OCLHelper and Query interfaces. These specialized interfaces likewise supply the generic type parameter bindings for Ecore.

The UML Metamodel Binding

An OCL binding for the UML metamodel is provided by the org.eclipse.ocl.uml plug-in. It is best suited to parsing and evaluating OCL constraints on UML models. Evaluation of constraints is supported on instances of the UML2-generated Java API (UML as the source for the genmodel), on dynamic EObjects (using an Ecore model created by the UML-to-Ecore converter), and on InstanceSpecification elements in the UML model.

The UML binding is provided by the UMLEnvironmentFactory class. By default, the UML environment factory and all of the environment contexts that it creates use a private ResourceSet to look up the corresponding UML model(s) against which OCL constraints are parsed.

It is the client's responsibility to ensure that the UML model is loaded in the resource set used by the UML environment factory instance.

The UML environment factory can alternatively be initialized with a resource set of the client's choosing. Ordinarily, the UML environment uses its resource set's local EPackage registry to look up EMF-generated EPackage names corresponding to UML models. A custom package registry may be provided by the client if necessary.

The UML binding for OCL provides the following capabilities:

UML metamodel capability matrix
CapabilityParseEvaluate
Classifier invariant constraintsYY
Operation precondition and postcondition constraints and body conditionsYN
Property constraints (initial-value and derivation)YY1
Attribute and operation definitions (def: expressions)YY
Package context declarationYn/a
Basic values and typesYY2
Collection typesYY
Operation invocationYY3
Navigation of attributes and referencesYY
Navigation of non-navigable association ends (including those that are owned by the association)YY
Qualified association end navigationYY4
Navigation to association classes, including source qualifiersYY4
Iteration expressions (all standard iterators)YY
Let expressionsYY
If expressionsYY
TuplesYY
Message expressions, including unspecified valuesYN
Operations predefined by OCL: allInstances()YY
Operations predefined by OCL: oclIsKindOf(), oclIsTypeOf(), oclAsType()YY
Operations predefined by OCL: oclIsInState()YN
Operations predefined by OCL: oclIsNew()YN
@pre expressionsYN
1 derivation only
2 OCL defines the Real primitive type that is missing from UML, but not a LiteralReal
3 with InstanceSpecifications, only where body constraints are defined
4 only with InstanceSpecifications

A special case of the UML environment's support for dynamic EObjects, mentioned above, is stereotype applications. The Eclipse UML2 component uses dynamic EMF in the implementation of stereotype applications, by converting UML Profiles to EPackages. Constraints parsed in the context of a UML Stereotype can be evaluated on applications (instances) of that stereotype or on model elements to which the stereotype is applied. This applies only to UML models, themselves, as instances of the UML metamodel (stereotyping is only available in the UML metamodel).

For applications that work exclusively with the UML binding for OCL, the org.eclipse.ocl.uml package defines a subclass of the OCL class that supplies all of the generic type parameter bindings to simplify typing (in the absence of type aliasing in Java). It also provides UML-specific convenience factory methods for the OCL, itself, and narrows the return type of the factory methods for the OCLHelper and Query interfaces. These specialized interfaces likewise supply the generic type parameter bindings for UML.


Copyright (c) 2000, 2007 IBM Corporation and others. All Rights Reserved.