Jump to: navigation, search

Difference between revisions of "OCL/FAQ"

(What is MDT OCL 3.0 update site?)
Line 43: Line 43:
The OCL Abstract Syntax Model is, itself, actually a metamodel sitting at the M2 level.
The OCL Abstract Syntax Model is, itself, actually a metamodel sitting at the M2 level.
=== What is MDT OCL 3.0 update site? ===
=== What is MDT OCL 3.0 update site URL? ===

Revision as of 23:35, 21 June 2010

In addition to the FAQ below, see also the OCL Developer Guide documentation included in the OCL SDK.

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

OCL's relation to the OMG modeling stack
Modeling Level Artifacts OCL's Role
M3 Ecore This is the metamodel for the OCL Abstract Syntax Model
M2 Ecore, UML OCL's generic AST model binds to these metamodels
M1 *.ecore and *.uml models OCL parses constraints on these models
generated Java code
M0 instances of generated Java classes OCL evaluates constraints on these objects
dynamic EMF objects

The OCL Abstract Syntax Model is, itself, actually a metamodel sitting at the M2 level.

What is MDT OCL 3.0 update site URL?


Does OCL 1.x work with J2SE 1.4?

Because OCL extends EMF's Ecore, OCL's dependencies are the same as those of EMF.

1.0 2.2 1.4.2
1.1 2.3 1.5
1.2 2.4 1.5
1.3 2.5 1.5
3.0 2.6 1.5

See also EMF 2.3 JVM Requirements.

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.

Instead, one must do something like:

-- given types A, B conforming to S but neither of
-- A nor B conforming to the other
context S
def: union(a : Set(A), b : Set(B)) : Set(S) =
    let s : Set(S) = Set{} in s->union(a)->union(b)

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.

How do I invoke methods such as eContainer(), eContents(), eGet()?

These methods are EObject methods, so you need to declare that your meta-model extends EObject. Therefore you need to initialize your environment with the following ParsingOption declaration prior to parsing.


(Prior to EMF 2.5.0M4 this declaration was not necessary if your meta-model explicitly inherited from an Ecore class such as EModelElement or EObject.)

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.

See MDT/OCLinEcore

How do I generate code from OCL constraints in UML?

See http://www.eclipse.org/modeling/mdt/uml2/docs/presentations/EclipseCon2008_LongTalk_NewFeaturesOfUML2_files/frame.htm.

OCL Editor

How do I install an editor for OCL?

An editor for OCL has been developed as part of the M2M/QVT Declarative project. This is being migrated to form part of the MDT/OCL project in the Helios release.

It is hoped that the relevant Update Sites will facilitate installation soon.

To use this editor now follow the following installation steps.

Eclipse 3.5 base

You require Eclipse 3.5 or later with EMF (Core), EMF Transaction and EMF Validation. If you already have these you may skip the install Eclipse step.

Install the Eclipse 3.5 including the modeling packages.

Download e.g. http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR1/eclipse-modeling-galileo-SR1-incubation-win32.zip and unzip.

Get OCL Editor Project Set File

Start Eclipse, Open the CVS Resource Perspective.

Create a New Repository Location for Host: dev.eclipse.org Repository Path: /cvsroot/modeling User: anonymous Password: Connection type: pserver



and invoke Check Out the psf Folder from the right button menu.

Import OCL Editor Project Set

In the Project Explorer

Select psf/ocl-editor.psf

and invoke Import Project Set...

specifying anonymous when asked for a CVS account and passwoes.

Build OCL Editor Examples

Optionally (to make the OCL examples work)



and invoke Run As->Ant Build from the right bitton menu.

This should successfully create two OCL zips (refresh the project to see them) although it will fail when creating further QVTd zips.

Invoke OCL Editor

Start a nested Eclipse by selecting some project and invoking Run As->Eclipse Application.

To see how the Editor works and get an example configuration

Invoke New->Project->Examples->QVT Projects->Royal and Loyal Example

Open org.eclipse.qvt.declarative.examples.ocl.royalandloyal/oclsrc/Royal and Loyal/Royal and Loyal.ocl.

Create OCL Editor Project

An empty prototype project may be created by

Invoke New->Project->Examples->QVT Projects->Empty OCL Project

The important characteristics of this project are that:

The Java build path specifies 'oclsrc' and 'oclbin' folders.

The QVTd Model Registry Nature is set enabling the Model Registry Property Page to define models that contribute to the OCL 'package' path.

The QVTd OCL Nature is set enabling compliation of the OCL src to an OCL bin AST.