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 org.eclipse.ocl.examples.project.oclinecoretutorial. It contains

Select model/Tutorial.ecore and use the right button to invoke Open With->OCLinEcore 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.

Expand the root element and then select the Library lib element and use the right button menu to invoke Validate. You should get a pop-up reporting problems during Validation. Click 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 OCL->Show Xtext OCL Console from the context menu. 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 can step through execution using the OCL debugger. In the Console View type PageUp to restore the earlier text entry, then with Book b2 still selected in the editor, click the debug icon in the Console tool bar. The debugger should open automatically, but if it doesn’t, use Window->Show View->Debug from the Eclipse menu bar. The Variables View shows model elemnt values. Click F5 or Step Into a few times to progress execution.

You have now seen

You have not

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