You'll need the documentation here. (Warning: you may find parts of this document (though I hope not the parts you'll use in this lab!) out of date. I mention this not just to complain, but to draw to your attention something that is quite an important factor relevant to this course: although we have the understanding to do some quite magical things with models these days, the effort required to keep the magic working and its documentation up to date is considerable, and not always available...)
You are welcome to work individually or in small groups, as you prefer - but as always, if you work in a group, make sure you all understand everything done.
Note: You can either use the papyrus version of Eclipse, or the modelling edition: it shouldn't matter much today. I was using the modelling edition as I wrote the lab.
Think of ecore as a metamodel for a very simplified fragment of UML. It corresponds roughly to (part of) MOF which has been mentioned. Don't worry about the tutorial assuming you are familiar with EMF models! You may find the copy/paste links in the PDF don't work; I include the text here for convenience, and include a few notes, so follow both here and in the tutorial document.
Say Yes if you're asked whether you want to convert your Tutorial project into an OCL project.
Have a look at the various editors available for your Tutorial.ecore model! You'll probably find the syntax provided by the OCLinEcore editor the most usable, but do understand the interchangeability...
First part:
import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/' ; package tutorial : tut = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial' { class Library { attribute name : String; property books#library : Book[*] { composes }; property loans : Loan[*] { composes }; property members#library : Member[*] { composes }; } class Book { attribute name : String; attribute copies : Integer; property library#books : Library[?]; } class Member { attribute name : String; property library#members : Library[?]; } class Loan { property book : Book[?]; property member : Member[?]; attribute date : ecore::EDate[?]; } }Remark: it's off the path of this lab, but you might like to experiment with the ecore tools and get them to generate a diagrammatic presentation of tutorial.ecore for you. (I have several diagram generation options on my right click menu, but I also have a lot of modelling software installed in my Eclipse; you may need to try installing ecore tools.)
4.1.6 Create Dynamic Instance I found I didn't, in fact, have that option on the context sensitive menu from the OCLinEcore editor - but I did from the other other editors. (There's a lesson about tooling there, too...)
Next bit:
invariant SufficientCopies: library.loans->select(book=self)->size() <= copies;(though you might find it instructive to type that one, and experiment with how far the content assist (that you get with Control-Space) helps. You'll find it sometimes gives up with an error message beginning "no viable alternative"...) NB if you select and then Control-Shift-F, it will tidy up formatting.
When you get to the OCL Console section, I found that only the instructions starting "Alternatively" at the bottom of p106 work: use those!
property loans : Loan[*] {derived, volatile} { derivation : library.loans->select(book=self); }
operation isAvailable() : Boolean[?] { body: loans->size() < copies; }And finally:
invariant AtMostTwoLoans : loans->size() <= 2; invariant UniqueLoans : loans->isUnique(book); property loans : Loan[*] { derived, volatile } { derivation : library.loans->select(member=self); } property books : Book[*] { derived, volatile, !unique} { derivation : loans->collect(book); }Before you start the section Generating Java Code, fix the validation errors you just discovered, and revalidate - it should, and probably does, make you very uncomfortable to go on while Eclipse is showing red crosses!
Do explore the code you get when you generate model code, and feel free to play with nearby capabilities - the tutorial itself is only scratching the surface of what this tooling can do.
perdita@inf.ed.ac.uk
)
Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk Please contact our webadmin with any comments or corrections. Logging and Cookies Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh |