Getting Started

Getting Started

For a very quick demonstration of OCL, you may follow this very abbreviated version of the OCLinEcore tutorial, where you can find Installation instructions. Once you have the OCL Examples and Editors feature installed you may follow these instructions to get an insight into the capabilities of OCL and the Eclipse OCL tooling.

Invoke File->New->Project... then select Examples then OCL (Object Constraint Language) Plugins then OCLinEcore Tutorial and Finish to create a small example project called OCLinEcoreTutorial. It contains

Select model/Tutorial.ecore and use the right button to invoke Open With->OCLinEcore (Ecore) Editor. This gives you a textual view of the Ecore file with embedded OCL invariants such as the Book constraint

invariant SufficientCopies:
  library.loans->select((book = self))->size() <= copies;

This invariant is named SufficientCopies. It

The invariant is satisfied if it evaluates true; i.e. if the number of loans is less than or equal to the number of copies.

You can see this invariant at work, by selecting model/Tutorial.xmi and using the right button to invoke Open With->Sample Reflective Ecore Model Editor. This gives you a tree view of a small library model.

Select the “Library lib” element and use the right button menu to invoke Validate. You should get a pop-up reporting problems during Validation. Select Details and you will see that one of the problems is with the SufficientCopies invariant we have just looked at. If you browse the Properties View for model/Tutorial.xmi, you can verify that there are three loans but only two copies for the offending Book.

You may evaluate custom OCL queries interactively. From the editor for Tutorial.xmi, invoke Show Xtext OCL Console. Select “Book b2” in the editor, then in the bottom line of the console enter the OCL expression loans.member and then Enter. The results are shown in the panel and identify that all three loans are by “Member m3”.

The expression loans.member is an abbreviated form of self.loans->collect(aLoan : Loan | aLoan.member) and demonstrates OCL’s ability to perform many useful navigations over multi-element properties. The expression

You have now seen

You have not

Please follow the tutorials, examples and reference material for further information.