ITWissen.info - Tech know how online

Eclipse modelling framework (EMF)

The Eclipse Modeling 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 with whose support the generation of different text artifacts such as SQL, Java, XML or generally text is possible. One of the initiators of EMF was IBM, which 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, so that time-consuming typing and possible errors are reduced. 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.

With the Model Driven Architecture( MDA), the Object Management Group ( OMG) defines a closed procedure for developing 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 diagrams. 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 serialization of the model.

If there are any changes to the structure of the model, they can be applied back to the model from the Java code - this feature is also known as roundtrip.

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 specific technology. Thus EMF is an implementation of a part of the MOF specification. Like MOF, ecore defines itself recursively, so an endless number of meta-levels are excluded by definition. Ecore is based 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 tool 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 Reflection API - 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 to realize model-driven software development with little equipment. Without great effort, models can be created and corresponding code can be generated without the use of further complex tools. Thus, the approaches of modeling and programming are combined advantageously.

Informations:
Englisch: Eclipse modelling framework - EMF
Updated at: 28.10.2013
#Words: 860
Links: Eclipse, enhanced metafile (WMF) (EMF), framework, Java, program
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024