Skip navigation links

Package org.eclipse.ocl.uml

Implementation of an OCL binding for the UML metamodel.

See: Description

Package org.eclipse.ocl.uml Description

Implementation of an OCL binding for the UML metamodel.

Package Specification

This package defines an OCL environment implementation for the UML metamodel. Clients can use an UMLEnvironmentFactory in conjunction with the OCL class to parse and evaluated OCL constraints on UML models.

Clients may extend the environment implementation to support custom requirements, such as overriding the Environment.lookupOperation(C, java.lang.String, java.util.List<? extends org.eclipse.ocl.utilities.TypedElement<C>>) and EvaluationEnvironment.callOperation(O, int, java.lang.Object, java.lang.Object[]) methods to inject custom operations into existing metaclasses (to provide Java implementations, rather than defining additional operations using OCL).

OCL Parsing on Various Modeling Levels

The parser environments created by the UML environment factory support OCL expressions at both the metamodel (M2) and user model (M1) levels. For user model constraints, use the classifier in the model as the context classifier in invocations of th OCL or an OCLHelper created by it. For metamodel OCL (used, for example, to query the user model, itself) use the metaclass of any kind of element in the user model as the context classifier. A convenient way to obtain this metaclass is via the org.eclipse.ocl.uml.util.OCLUMLUtil#getMetaclass(org.eclipse.uml2.uml.Element) method.

Evaluation of OCL Expressions in the UML Environment

The UMLEvaluationEnvironment provides support for two implementations of M0 (run-time instance) models, depending on the kind of object provided as the evaluation context: org.eclipse.uml2.uml.InstanceSpecifications and EObjects. If the context object is an instance specification, then the extents of classes are considered to be the InstanceSpecifications in the model that reference them or their subclasses as classifiers. If the context object is an EObject, then the extents of classes are considered to be the EObjects in the resource set that reference EClasses corresponding to the UML model classes, as described below.

Evaluation on Instance Specifications

In the case of InstanceSpecifications, navigation of attributes, associations, and association classes is supported by interpretation of the values of slots and links (instance specifications of associations and association classes). The only operations that can be evaluated are those that are defined by the OCL Standard Library or via additional operation definition constraints, unless a client provides a subclass of the UMLEvaluationEnvironment with Java implementations of any required operations.

Evaluation on EObjects

In the case of EObjects, navigation of attributes and associations is supported by the EObject reflection API. Navigation of association classes is not available, as the UML2 code generation does not support them (EMF having no comparable concept). The operations that can be evaluated are those that are defined by the OCL Standard Library or via additional operation definition constraints, plus any that are generated (usually all) to the corresponding EClasses.

The evaluation of OCL on EObjects assumes that a corresponding Ecore representation of the UML model exists and can be found in EMF's package registry (either globally or at the ResourceSet level). This is the case for any UML model from which code was generated and for UML Profiles, which are associated with Ecore definitions. In the latter case, as well as the case of ad hoc UML-to-Ecore conversions using the org.eclipse.uml2.uml.util.UMLUtil API, the use of dynamic EObjects naturally restricts the availability of operations at evaluation time.

See Also:
OCL, UMLEnvironmentFactory, UMLEnvironment, UMLEvaluationEnvironment, org.eclipse.ocl.uml.util.OCLUMLUtil#getMetaclass(org.eclipse.uml2.uml.Element)
Skip navigation links

Copyright © 2005, 2018 IBM Corporation and others. All Rights Reserved.