You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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:

  1. Go into "File > New > Example... > Eclipse Modeling Framework > Extended Library Model Example"
  2. Select "org.eclipse.emf.examples.library" and press "Finish".
  3. 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"

When the model validates successfully, we can generate Java code from it. Properties describing what code to generate is described in a separate .genmodel file. By double clicking on the extlibrary.genmodel file you will see the following in the Properties View:

To generate Java code for our library model, right click on the root element in the editor for the .genmodel file and select Generate Model Code.

 

 

 

 

  • No labels