Documentation

This tutorial present a basic overview of the capabilities of the Ecore graphical editor through a simple example. We are going to explain in details the different steps necessary to define a metamodel. The example consists of defining the metamodel of a FamilyTree : it could be used then to modelize a Family.

Prerequisites: we assume that you have minimum knowledge of the EMF project and of the terminology that is used with the Ecore metamodel.

1. Creation of the Diagram file

First, you have to create a new Ecore diagram. Use the creation wizard (" Right Click > New > Ecore Diagram ") and name your file "familytree".

newFamilyTreeDiagram

Then an empty diagram is created : the model is composed of a single EPackage model object called "familytree" too. By default the EPackage properties are set, but we advise you to fill them with the following values :

rootEPackageProperties

2. Create the EClass model objects and their properties

To create an EClass, select the corresponding tool in the Palette to activate it, and click on the editing window at the specified location. You will have to do this to create the five EClass that compose our metamodel :

2.1. FamilyTree


  1. This represent the root model object of a FamilyTree model. We will define only one feature to identify the family name of the familytree.
  2. Create an EAttribute inside the FamilyTree EClass and set the following properties :
    • name : name
    • EType : EString

2.2. Person

This is an abstract EClass. This is mainly used to aggregate the Man or Woman that composed our FamilyTree, and group their common properties.

personIsAbstract
  1. Then, we will define a few features that will be used later during the edition of a such familytree model.
  2. Create an EAttribute and set the following properties :
    • name : firstName
    • EType : EString
  3. Create an EAttribute and set the following properties :
    • name : lastName
    • EType : EString
  4. Create an EAttribute and set the following properties :
    • name : birthYear
    • EType : EInt
  5. Create an EAttribute and set the following properties :
    • name : deathYear
    • EType : EInt
personAttributes

2.3. Wedding

An object that will represent a matrimony between a man and a woman.

2.4. Man

An object that will represent an man of the familytree.

2.5. Woman

An object that will represent an woman of the familytree.

3. Creation of the Connections

3.1. The containment EReferences

In our model, we have two containment EReferences to create. Use the "EReference" connection tool in the Palette to create a simple EReference.

containmentReferences
  1. Create an EReference between the FamilyTree and the Person and set the following properties :
    • name : persons
    • lowerBound : 1
    • upperBound : -1. The '-1' value is used for the upper bound to indicate an 'unbounded' value.
    • containment : true containmentProperty
  2. Create an EReference between the FamilyTree and the Wedding and set the following properties :
    • name : weddings
    • upperBound : -1
    • containment : true boundsEReference

3.2. The Inheritace link

Let's define an Inheritance link between the Man and Woman model objects with the super EClass Person. Use the "Inheritance" connection tool in the Palette to create those Inheritance links. The 'ESuperType' property of the source model object is automatically updated.

inheritanceLinks

3.3. The other references

Let's now define the four remaining EReferences.

otherEReferences
A wedding is celebrated between a woman and a man.
  1. Create an EReference between the Wedding and the Woman and set the following properties :
    • name : wife
    • lowerBound : 1
  2. Create an EReference between the Wedding and the Man and set the following properties :
    • name : husband
    • lowerBound : 1
In a familytree, we have to define relationships between the children and their parents. In our metamodel, we choose to modelize that through a connection between a Person and a Wedding. So we have to create a two-way EReference :
  1. Create an EReference between the Wedding and the Person and set the following properties :
    • name : children
    • upperBound : -1
  2. Create an EReference between the Person and the Wedding and set the following properties :
    • name : parents
    • EOpposite : reference the 'children' EReference previously created. eOppositeReference

Here is an overview of the metamodel we have modelized : familyTreeOverview

Summary

As you have seen, using the Ecore graphical editor is quite intuitive (on condition that you are enough familiar with the Ecore metamodel) and much more effective than the default tree structure editor provided by EMF. This tutorial is not complete yet, as we have not see in detail the creation of EAnnotations, EDataTypes, EEnum and EOperations... but you will probably guess how it works, and the tutorial is probably going to evolve with the Ecore graphical editor ...

________________________________________

By Jacques LESCOT, Anyware Technologies.

August, 29 2006