Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

...

of this step-by-step guideline and exercise:

  • Learn how to generate code using EMF.
  • 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:

...

  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: Concepts and Relations

  1. Find examples of EClasses and EDataTypes
  2. Find examples of containment / container and ordinary relations in the model.
  3. Try to find features properties such as:
    1. multiplicity – lower and upper bound
    2. changeable – allows being set (using setter)
    3. derived – computed from other values 
    4. transient – should not be stored in external resource
    5. volatile – should not need to be stored in memory
    6. order – not used in practice, but good to know if order is important


Part #3: Extending the model

Use the model editor to add a new BookCategory. Hint: right-click on BookCategory > New Child... > Select EEnum Literal

...

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.

...

By double clicking on the BookCategory.java file you see a enum implementation where Computer Science (the modification we made to the domain model) is added as a literal object:

 

Part #5 Instantiating from Java

Now, with Java code for our domain model automatically generated, it is time to learn how to use and instantiate the model.

...

Note how you use the EXTLibraryFactory.eINSTANCE to create java objects.

 

Part #6 Instantiating from an Editor

With the ecore model we have for the library domain, we can also use EMF to generate an editor that we can use for instantiation.

...