| Free tutorials for Java, Eclipse and Web programming |
Version 1.3
Copyright © 2007-2010 Lars Vogel
27.01.2010
| Revision History | ||
|---|---|---|
| Revision 0.1 - 0.4 | 12.08.2007 | Lars Vogel |
| Created, reworked and published | ||
| Revision 0.5 | 30.07.2008 | Lars Vogel |
| Updated to Eclipse 3.5, simplified article, added definition of data model. | ||
| Revision 0.6 | 01.08.2008 | Lars Vogel |
| Clean-up editor description | ||
| Revision 0.7 | 02.08.2008 | Lars Vogel |
| Moved Eclipse JET (Java Emitter Template) to own article http://www.vogella.de/articles/EclipseJET/article.html | ||
| Revision 0.8 | 25.11.2009 | Lars Vogel |
| Fixed typo | ||
| Revision 0.9 | 06.12.2009 | Lars Vogel |
| Improved reading and writing EMF models via code | ||
| Revision 1.0 | 17.01.2010 | Lars Vogel |
| added ecore tools, moved EMF models based on annotations to own article | ||
| Revision 1.1 | 20.01.2010 | Lars Vogel |
| Update chapter 5 with new model | ||
| Revision 1.2 | 21.01.2010 | Lars Vogel |
| Moved persistence and notifcation to own articles | ||
| Revision 1.3 | 27.01.2010 | Lars Vogel |
| Added infos on ecore and genmodel | ||
Table of Contents
A data model, sometimes also called domain model, represents the data you want to work with. For example if you write a program which is a online booking service you might model your domain model with objects like Person, Flight, Booking etc.
The general recommendation is to model your data model independent of the application logic. This approach lets usually to classes with almost no logic and a lot of properties, e.g. Person would have the properties "firstName", "lastName", "Address", etc.
Eclipse EMF can be used to model your domain model.
In general their is a distinction between the meta-model and the actual model. The meta-model describes the structure of possible instances of the model. A model is then the instance of this meta-model.
EMF uses XMI (XML Metadata Interchange) for the model definition.
This model definition can be defined / generated via:
A XMI document, using an XML or text editor
Java annotations
UML
XML Schema
Once the EMF model is specified you can generate the corresponding Java implementations classes from this model. EMF allows that you can edit / modify the generated code by hand. Even with hand-written code you can use EMF to re-generate the code if the model changes.
EMF is based on two meta-models; the Ecore and the Genmodel model.
The Ecore metamodel contains the information about the defined classes.
EClass: represents a class, with attributes and references * EAttribut
EAttribute: represents an attribute which has a name and a type
EReference: represents an assoziation between two classes
EDataType: represents the type of the attribute
The Genmodel contains additional information for the codegeneration, e.g. the path and file information. The genmodel contains also the control parameter how the coding should be generated.
The Ecore model shows a root object representing the whole model. This model has children which represents the packages, whose children represents the classes, while the children of the classes represents the attributes of these classes. EMF's meta model Ecore (roughly) corresponds to the EMOF (Essential MOF) subset of the MOF 2.0 standard.
EMF allows you to explicitly model your data model enhancing there fore the visibility and extensibility for the model.
EMF automatically provides notification functionality to the model in case of changes in the model happen.
Eclipse EMF helps to program against the interfaces instead of classes.
It is possible to regenerate the code from the model at any point in time.
Using the UML2 Tools project you can create an UML2 diagram out of your model. See Creating UML 2 diagrams with Eclipse UML2 Tools .