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
model/Tutorial.ecore - a small Library meta-model
model/Tutorial.xmi - an even smaller Library model
model/Tutorial.genmodel - a gebnerator for Java code
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
navigates from the implicit self (a Book)
via the library
to its loans which it searches
to select those loans that satisfy the predicate
loaned book is equal to the self Book
the size (number) of loans is computed
and compared to the number of copies of the self Book
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
navigates from self, the Book b2 selection
to its loans, using Book::loans which is a derived property defined in OCL
for each of the loans, the iterator variable, aLoan, is assigned to the loan and
the body, aLoan.member is evaluated to return the member making the loan
the resulting members are collected to return a collection result
the result is displayed on three lines in the results panel
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
an Xtext editor that embeds OCL directly in Ecore models to provide programmed enrichment
execution of OCL while validating a model using conventional Ecore tooling
an interactive Console for custom OCL evaluations
execution of a derived property defined in OCL
the ability of OCL to express operations on multi-elements compactly
the ability to debug OCL execution and browse data
You have not
written any Java code
generated any plugins
needed to start an additional Eclipse session
Please follow the tutorials, examples and reference material for further information.