OCL in UMLAUT
The Object Constraint Language (OCL) in Umlaut
Introduction
The UMLAUT tool supports Design-by-Contract when modeling a software system by allowing the designer to specify constraints on models with the Object Constraint Language (OCL).
Some tools such as checking that Ocl constraints are syntaxically correct, automatically generating Eiffel code from constraints, or evaluating constraints are provided in Umlaut.
After loading a model into Umlaut, the first time you call a function relying on the OCL, UMLAUT automatically search for a package named UML_OCL in your model. If one exists, it it used for all OCL operations. If there is no such package, UMLAUT automatically creates one.
Note
It is strongly recommended that you use the provided UML_OCL package and do not modify it in the current release, as UMLAUT supposes it is compliant with the current OCL standard. This limitation will soon be removed.
All the examples given here are based on the basic Bank Account example.
Any number of constraints may be attached to an element in a model.
A Constraint being itself a model-element, it may also have its own constraints.
Constraints are represented in browsers by an icon (this is the standard UML notation for Constraint), if no icon is available for the language in which the constraint is written. Otherwise, the icon specific to the language is used.
In the current release, the following icons are available:
Icons used for Constraints
Language used for the constraint body | Icon used in browsers
|
eiffel |
|
ocl |
|
others |
|
To edit the list of constraints attached to a model element, do the following:
- Open the edit menu attached to the model element (right-click on the element in either the browser or one of its graphical views),
- Click on the Constraint button in the top compartment of the Edit window. This opens up a new dialog Constraints Editor with the list of constraints attached to the element being edited.
- Add creates a new constraint, and attaches it to the element,
- Del removes a selected constraint,
- Edit opens up an editor for the selected constraint (see Editing a Constraint).
To edit a Constraint, just right-click on one of its view. It opens up an editor for the constraint.
A Constraint has two important fields :
- the language field, which specifies the language in which the constraint is written. Some usual options are provided, such as Ocl, Eiffel or Java, but others may be added as well by editing the combo box field,
- the body field, which specifies the constraint itself. It is an expression written with the language specified in field language.
Other tools using constraints and OCL are available in Umlaut.
You access these tools by right-clicking on a Constraint. This opens up a new menu with all OCL tools available.
- syntax checking : you can check if a constraint expressed in OCL is syntaxically correct by selecting the Parse option in the OCL menu. A dialog pops up on the screen and informs you about the result of the parsing. If it proceeded without any error, the constraint is shown in a formatted way, to ease its reading. Otherwise, a meaningful error message is shown.
- eiffel code generation : code fragments in Eiffel may be automatically generated from the body of an Ocl constraint. Select the To Eiffel option in the OCL menu. A pop up shows the result (a fragment of Eiffel code).