Exercise: Define a new EMF model and create Java code from it #
See the YouTube playlist for all videos.
3.1. Project and initial model creation #
- Create a new project called
de.vogella.emf.webpage.model
via File > New Project… > Ecore Modeling Project.
- This should open a visual editor for creating EMF models.
Open the Properties view via the menu Window > Show View > Other… > Properties. This view allows you to modify the attributes of your model elements.
Click on Class and click into the editor to create a new class. Create the
Web
,Webpage
,Category
andArticle
EClasses.
- Use the Attribute node to add the attribute called name to each class. This attribute should have the
EString
type. You can set the name under Properties > Semantic > Name and the type under Properties > Semantic > EType.
- Add the title, description and keywords attributes to the Web and Webpage model elements.
- We want to use the data type calendar in our model. Select
Datatype
and drag it into your model. Assign the name Calendar to it. Usejava.util.Calendar
as type parameter.
Add a new Attribute called created to
Article
and use your new type.Under Relation select either Reference or Composition and create an arrow similar to the next picture.
- Make sure the upper bound is set to "-1" (* on the user interface) and that the
Containment
property is selected. In caseContainment
is not selected, you will not be able to add children toWeb
in the editor.
- Create these compositions from Web to Webpage, from Webpage to Category, and from Category to Article.
3.2. View Ecore diagram #
- Close the diagram and open the webpage.ecore file. The result should look like the following screenshot.
3.3. Set the package #
- Open the webpage.genmodel and select the Webpage node. Set the base package property to
de.vogella.emf.webpage.model
.