Learning the basics of the Eclipse Modeling Framework (EMF).
The EMF project is a modeling framework and code generation facility for building tools and other applications based on a structured data model. From a model specification described in XMI, EMF provides tools and runtime support to produce a set of Java classes for the model, along with a set of adapter classes that enable viewing and command-based editing of the model, and a basic editor.
https://eclipse.org/modeling/emf/
Learning goals for todays exercise:
- Learn how to generate code using EMF.
- Understand how use constraints.
- Understand how to use containment / container and regular relations in EMF.
- Learn how to instantiate your models in EMF and by Java code.
Prerequisites
- You need Eclipse Modeling Tools. Installation guidelines.
Part #1: Modelling a library.
To get a modelling kickstart, we will start using an existing domain model from a library. This model consists of the following main concepts:
Do the following to get started with this example model in your Eclipse environment:
- Go into "File > New > Example... > Eclipse Modeling Framework > Extended Library Model Example"
- Select "org.eclipse.emf.examples.library" and press "Finish".
- Double click on the extlibrary.ecore file, and you will see an editor with a hierarchical breakdown of the domain model.
Part #2: Relations
Find examples of containment / container and regular relations in the model.
Part #3: Extending the model
Use the model editor to add a new BookCategory. Hint: right-click on BookCategory > New Child... > Select EEnum Literal
Fill out "Literal", "Name" and "Value" properties for our new category.
Remember to save our ecore file, after the new category is added.
Part #4: Generating Java Code
First we want to validate our ecore model.
Right click on the root element and select "Validate"