- Tech know how online

Eclipse modelling framework (EMF)

The Eclipse Modelling Framework (EMF) is an open source framework that can generate Java program code based on structured models. The central component in this framework is the code generation engine, which was developed by the Eclipse Foundation as a plug-in for the open source platform Eclipse. A relevant subproject of EMF is Java Emitter Templates (JET), a tool that supports the generation of different text artifacts like SQL, Java, XML or text in general. One of the initiators of EMF was IBM, who provided the core of Rational Rose to the project.

Development phases of Eclipse Modelling Framework (EMF)

The original goal was to implement the Meta Object Facility (MOF), but this turned out to be too complex during development. Therefore, EMF is considered to be an implementation of a subset of MOF, also called Essential MOF (EMOF). The metamodel of EMF is called Ecore. EMF uses the XML Metadata Interchange (XMI) format to define models. The model itself can be created from XML schema, Java code with annotations, UML diagrams or a special tree editor provided by Eclipse. Furthermore, functionalities such as persistence or validation of models are offered. In addition, EMF can be used to generate JUnit code, which can be used to test the generated Java program code. By using EMF, parts of the source code can be generated automatically, thus reducing time-consuming typing and possible errors. An advantage of EMF is also the good integration into Eclipse, so that the interaction with other Eclipse projects - for example in the generation of UI components or with regard to the Eclipse Graphical Modelling Framework (GMF) - is possible without further effort.

The Object Management Group (OMG) defines with the Model Driven Architecture (MDA) a closed procedure for the development of software based on models. EMF enables the model-driven development of Eclipse plug-ins, Java or even rich client platforms (RCP). The models of MDA consist of a set of UML diagrams such as class diagrams or state diagrams. EMF maps part of MDA and represents the part of UML that describes class diagram s. These can be in different notations, so the following options can be used to create a model in EMF:

  • An XMI document is created directly using an XML or text editor.
  • An XMI document is exported from a modeling tool such as Rational Rose or similar.
  • The model can be created from Java interfaces annotated with modeling properties.
  • XML Schema can be used to specify the format of the serialization of the model.
If this results in changes to the structure of the model, these can be applied back to the model from within the Java code - this feature is also known as round-tripping.

The Metamodel of (EMF)

The EMF metamodel is called ecore and is very close to the Meta Object Facility (MOF) of the OMG. Here, the MOF specification defines an abstract language as well as a framework to generate and manage metamodels independent of a particular technology. Thus, EMF is an implementation of part of the MOF specification. Like MOF, ecore defines itself recursively, so that an endless number of meta-levels are excluded by definition. Ecore is modeled on Essential MOF (EMOF) and differs only slightly in this respect, so EMF can read and write EMOF notations transparently. In addition to the ecore metamodel, EMF also integrates the following components:

  • Java Emitter Templates (JET) a tools for generating different output - SQL, Java, XML, Text ...- following the syntax of Java Server Pages (JSP),
  • JMerge for controlling modifications to models and the generated classes,
  • A reference implementation of Service Data Objects (SDO), a specification of a vendor-independent framework for unified data access.
The easiest way to generate a model, is to use annotated Java interfaces, because then neither a special tool nor knowledge of UML or XML is needed. The model is first defined with the Java interfaces and then imported into EMF, so that an EMF model is available as a result. The Java structure code and an Eclipse editor for the instances of the model are then generated from the EMF model. The editor generated in this way provides a basis for creating your own editors. Necessary prerequisites are the Eclipse SDK and the EMF SDK, both of which are available at the link below. The update of the individual models is done automatically by Eclipse - at the latest when a change is saved. Furthermore, EMF offers a number of additional functionalities such as the ReflectionAPI - this allows read and write access to the models. The registration of so-called EventListeners on EMF objects enables their automatic notification in case of changes to attributes or references. The EMF CommandStack is used to store all changes to the model, so that they can be undone or repeated without any effort. In addition, the serialization of the model can be adapted to the respective requirements.

EMF is thus a powerful tool for realizing model-driven software development with little equipment. Models can be created without much effort and corresponding code can be generated without using further complex tools. Thus, the approaches of modeling and programming are combined advantageously.

Informationen zum Artikel
Englisch: Eclipse modelling framework - EMF
Updated at: 28.10.2013
#Words: 1412