| |
| h2(#TargetMetamodels). 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":#AdvancedMetamodelBindings that allows |
| additional EMF-based metamodels to be plugged in. |
| |
| bq.. |
| The direct and indirect coupling of the Ecore and UML2 meta-models to Ecore makes exact compliance with the OMG specification very difficult, particularly in the area of reflection. Eclipse OCL is therefore migrating to a new potentially 100% OMG compliant Pivot metamodel that hides the differencess between OMG's UML and EMOF and Eclipse's UML and Ecore. The Pivot binding is described in the "Pivot Programmers Guide":#PivotProgrammersGuide. |
| p. |
| The OCL API implements support for different target metamodels via the "@EnvironmentFactory@":http://download.eclipse.org/ocl/javadoc/6.3.0/org/eclipse/ocl/EnvironmentFactory.html interface. An implementation of this interface binds the metamodel's metaclasses to the generic type parameters of the "@OCL@":http://download.eclipse.org/ocl/javadoc/6.3.0/org/eclipse/ocl/OCL.html class. The metamodel-specific "@Environment@":http://download.eclipse.org/ocl/javadoc/6.3.0/org/eclipse/ocl/Environment.html 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. |
| |
| h3. 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@":http://download.eclipse.org/ocl/javadoc/6.3.0/org/eclipse/ocl/ecore/EcoreEnvironmentFactory.html 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: |
| |
| table{border:1px solid black}. |
| |_. Capability|_. Parse|_. Evaluate| |
| |Classifier invariant constraints|Y|Y| |
| |Operation precondition and postcondition constraints and body conditions|Y|N| |
| |Property constraints (initial-value and derivation)|Y|Y*| |
| |Attribute and operation definitions (def: expressions)|Y|Y| |
| |Package context declaration|Y|n/a| |
| |Basic values and types, mapped from the standard EDataTypes to OCL's primitive types|Y|Y| |
| |Collection types|Y|Y| |
| |Navigation of attributes and references|Y|Y| |
| |Operation invocation|Y|Y| |
| |Iteration expressions (all standard iterators)|Y|Y| |
| |Let expressions|Y|Y| |
| |If expressions|Y|Y| |
| |Tuples|Y|Y| |
| |Message expressions, including unspecified values|Y|N| |
| |Operations predefined by OCL: allInstances()|Y|Y| |
| |Operations predefined by OCL: oclIsKindOf(), oclIsTypeOf(), oclAsType()|Y|Y| |
| |Operations predefined by OCL: oclIsNew()|Y|N| |
| |@pre expressions|Y|N| |
| |\3. * derivation only| |
| *Ecore metamodel capability matrix* |
| |
| 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: |
| |
| * @Constraint@: the model of an OCL constraint (when the @language@ is OCL) |
| * @CallOperationAction@: used in the model of message expressions |
| * @SendSignalAction@: used in the model of message expressions |
| * @ExpressionInOCL@: it is this metaclass's general class @OpaqueExpression@ that Ecore does not define. It is elided in the Ecore binding |
| * @State@: Ecore provides no behavior modeling capabilities. The Ecore binding simply substitutes @EObject@ |
| |
| 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. |
| |
| h3. 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@":http://download.eclipse.org/ocl/javadoc/6.3.0/org/eclipse/ocl/uml/UMLEnvironmentFactory.html 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: |
| |
| table{border:1px solid black}. |
| |_. Capability|_. Parse|_. Evaluate| |
| |Classifier invariant constraints|Y|Y| |
| |Operation precondition and postcondition constraints and body conditions|Y|N| |
| |Property constraints (initial-value and derivation)|Y|Y*| |
| |Attribute and operation definitions (def: expressions)|Y|Y| |
| |Package context declaration|Y|n/a| |
| |Basic values and types|Y|Y+| |
| |Collection types|Y|Y| |
| |Operation invocation|Y|Y-| |
| |Navigation of attributes and references|Y|Y| |
| |Navigation of non-navigable association ends (including those that are owned by the association)|Y|Y| |
| |Qualified association end navigation|Y|Y=| |
| |Navigation to association classes, including source qualifiers|Y|Y=| |
| |Iteration expressions (all standard iterators)|Y|Y| |
| |Let expressions|Y|Y| |
| |If expressions|Y|Y| |
| |Tuples|Y|Y| |
| |Message expressions, including unspecified values|Y|N| |
| |Operations predefined by OCL: allInstances()|Y|Y| |
| |Operations predefined by OCL: oclIsKindOf(), oclIsTypeOf(), oclAsType()|Y|Y| |
| |Operations predefined by OCL: oclIsInState()|Y|N| |
| |Operations predefined by OCL: oclIsNew()|Y|N| |
| |@pre expressions|Y|N| |
| |\3. * derivation only| |
| |\3. + OCL defines the Real primitive type that is missing from UML, but not a LiteralReal| |
| |\3. - with InstanceSpecifications, only where body constraints are defined| |
| |\3. = only with InstanceSpecifications| |
| *UML metamodel capability matrix* |
| |
| 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 |
| @Profile@ s to @EPackage@ s. |
| 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. |