Newbie / General

Questions in this section are directed at those that are new to the MDT OCL component and are interested in finding out how to begin working with it.

What is MDT OCL?

MDT OCL provides a parser and interpreter for OCL constraints and
expressions on any EMF-based metamodel. By that is meant any
metamodel whose meta-metamodel is Ecore, and which (in being a metamodel)
provides an EMF importer to create GenModels that generate a Java
implementation.

So far, the Eclipse Modeling Project has two such metamodels: Ecore and UML
(Ecore being its own meta-metamodel). Hence, the OCL component provides an
OCL binding for each of these metamodels. OCL can parse constraints in
either Ecore or UML models, and can evaluate them on the instances of Java
classes generated from these models.

In terms of the OMG's modeling "stack", then, we have in the Eclipse
Modeling Project

Does OCL 1.x work with J2SE 1.4?

OCL Formulation

This section answers common problems in the formulation of OCL expressions that achieve some specific aim. More often than not, these are matters of OCL-the-language, not specific in any way to the MDT implementation.

How do I combine collections of different types?

If you have two or more collections of distinct element types and want to combine them into a single collection, it is not as simple as just unioning them or casting the collections to a common type. In the OCL 2.0 specification, the collection types do not conform to OclAny, so they do not have the oclAsType operation. Also, the semantics of generic type parameters in collections are undefined, so that it is not clear whether, for example, Set(T) has only union(Set(T)) or also union(Set(S)) where S is any supertype of T.

which works because Set(S) has an operation union(Set(S)) that accepts arguments of type Set(A) and Set(B) because of the rules of conformance of collection types.

OCL Code Generation

How do I generate code from OCL constraints in Ecore?

As of EMF 2.6.0M4 and MDT/OCL 3.0.0M6 EClassifier invariants, EOperation bodies and
EStructuralFeature initial or derived values may be specified using OCL expressions embedded
as Ecore annotations within an Ecore meta-model. These expressions may be evaluated either after
genmodel has been used to convert your model to Java, or directly using the dynamic
capabilities of EMF.