Given a model, EMF can automatically generate Java source code-the source allows you to create, query, update, serialize, drag, validate, and track changes to your model instances. EMF provides a set of effective reflection APIs and allows you to work with a dynamic (not generated) model.
First, the introduction
The Eclipse Modeling Framework (EMF) is a Java open source framework and code generation tool for building tools and other applications based on a structured model. While the Eclipse platform provides a strong integration framework at the user interface and file level, EMF strengthens this capability to achieve good granularity of data sharing between tools and applications.
Similar to other Java binding frameworks, such as JAXB or XMLBeans, given a model, EMF can generate Java source code-it allows you to create, query, update, drag, and serialize instances of your model. Although most Java binding frameworks support only one model class, such as the XML Schema, EMF supports generating code from XML schemas, UML class diagrams (Rational Rose or UML2), and annotated Java interfaces. In addition to the model code, EMF can generate a complete application-it includes a customizable editor.
The EMF generated code has a built-in change notification mechanism and supports cross document references. EMF provides a reflection API to access your model instances and allows you to create models dynamically. EMF supports model constraint checksums. EMF provides a powerful code generation tool to support the regeneration of the model and to merge using code written by the user.
In this article, we will explain what EMF is and analyze its basic framework.
EMF is the first implementation of an object Management group (OMG) Meta object Device (MOF) specification, which provides a standardized meta model for object-oriented analysis and design. For a long time, EMF has been used to implement a large number of tools and thus evolve into a Java implementation of a core subset of an effective MOF API.
The class MOF core element model (a model model) in EMF is called Ecore. In the implementation of the current MOF 2.0, there is a subset of a similar MOF model, called the Essential MOF (EMOF), which is now independent. There are small, especially naming differences between Ecore and emof, so EMF can transparently read and write serialized emof, allowing for standard exchange of data between tools.
EMF has been widely used today. For example, EMF is used to implement open source XML Schema Infoset model (XSD), Service data Objects (SDO), UML2, and Web Tools platform (WTP) engineering on Eclipse. In addition, EMF is also used in commercial products such as Omondo ECLIPSEUML and IBM Rational and WebSphere products.
Second, Ecore and reflection APIs
A key interface in EMF is Eobject, which is conceptually equivalent to Java.lang.Object. All modeling objects, whether generated or not, implement this interface in order to provide the following important features:
• Java-like Object.getclass (), by using the Eclass () method, you can retrieve the metadata of an instance, which is its eclass.
• On any EMF modeling object, you can use the Reflection API (Eget (), ESet ()) to access its data. This is conceptually equivalent to the Java Java.lang.reflect.Method.invoke () method, albeit more efficient.
• From any instance object, you can get its container (parent) by using the Econtainer () method.
· Eobject also expands the notifier, which allows you to monitor all changes in the object's data.
To find out more about EMF and Ecore, read the online overview or purchase the Eclipse Modeling Framework (EMF). The EMF Web site provides several files to describe how to use EMF to generate Java code from an XML Schema or UML diagram.
I'll describe an example that uses Ecore to create a simple corporate model, and then use the dynamic EMF to create, serialize, and drag instances of this model. If you want to continue reading and you are already an eclipse user, download and install the EMF 2.1 SDK or any available newer version of the download site in EMF. If not, you can also download a stand-alone package that includes an EMF jar file that does not have any dependencies on eclipse and can be used in a stand-alone application.