Skip to content

0. Concept

Timur Sağlam edited this page Aug 18, 2017 · 12 revisions

The Concept

With the Eclipse Modeling Framework, it is possible to generate Java code from Ecore metamodels. This generated code follows specific patterns. For example, it distinguishes between interface and implementation for every type. It also contains additional functionality like an object persistence management mechanism or a model change notifier system similar to the observer design pattern. Many tools rely on these specific patterns of the generated code and therefore can only be used with Java code that contains these patterns, which usually is code generated from Ecore metamodels. These tools, which rely on the Ecore functionality, cannot be used with arbitrary Java code. It is possible to model arbitrary Java code manually as an Ecore metamodel, generate the model code from that metamodel and then copy the implementation details into the model code. After that, the tools can be used with the model code. However, this process is not only very time-consuming but also API-breaking. A better idea would be to integrate the previously mentioned Ecore functionality into the existing Java code. This would allow the use of such tools on the Java code. This project implements an approach for the automatic integration of Ecore functionality into arbitrary Java code. This approach is called Ecorification.

Ecorification

The Ecorification has the goal to integrate Ecore functionality into Java code while preserving all of its original functionality. Preserving the original functionality of the Java code requires retaining the interfaces which are offered by the modules of the code and also retaining all internal functionality of the code. That means the product of the Ecorification is the original code, enriched with the desired Ecore functionality. This code then can be used with Ecore-dependent tools. The basic idea of the Ecorification is to find an Ecore representation of the Java code. This representation is used to integrate its Ecore functionality into the Java code. The Ecore representation is obtained by creating an Ecore metamodel that represents the Java code as closely as possible. We use the Eclipse Modeling Framework to generate Ecore model code from the Ecore metamodel. That generated Ecore model code has similarities with the original Java code because we specifically created the Ecore metamodel as similar as possible to the Java code. In contrast, the model code also shows some differences when compared to the original Java code, because of the specific patterns of Ecore model code in general. As a result, the model code contains the desired Ecore functionality, which is its most important feature. We now use the similarities of the original Java code and the generated model code to interlace both codes. This can be achieved by utilizing the separation of interface and implementation to mount the original code into the super relation hierarchy of the model code. The combination of both codes then contains the implementation details of the original code and the Ecore functionality of the model code. This way, the Java Code Ecorification allows the integration of Ecore functionality.

Ecore Metamodel Reverse Engineering

Because the Ecorification relies on an Ecore representation of the Java code, there is a need for a reverse engineering process that can automatically generate such an Ecore representation from any arbitrary Java code. The Eclipse Modeling Framework does not offer such a process. As a result, we implemented an approach for reverse engineering Ecore metamodels from Java code (see EcoreMetamodelExtraction). This approach allows generating Ecore metamodels from any arbitrary Java code. These extracted metamodels can be used to generate model code. At the core of the approach is a mapping from elements of the implicit Java metamodel to elements of the Ecore meta-metamodel. The implicit Java metamodel is a metamodel, which the Java language implicitly defines because Java code follows a structure defined by the Java Language Specification. This mapping defines how Ecore metamodel elements are extracted from Java code. We define the mapping for a higher metalevel to allow its application to any instances of the metalevel. For example, the mapping from the Java class to the Ecore metaclass EClass can be applied for any class.

The Base Pattern

To achieve the integration of Ecore functionality into Java code, the original Java code will be interlaced with the generated model code of an Ecore metamodel that was extracted from the original Java code. The model code and the original code will be connected with wrapper classes. The process of the Java code Ecorification can be split up into four steps: First, generating an Ecore representation of the original Java code. The Ecore representation consists of two parts: An Ecore metamodel and its generated model code. Second, generating the integration code, which will allow interlacing the original Java code and the generated Ecore model code. Third, adapting the original Java code to allow interlacing the adapted code and the Ecore model code with the help of the integration code. Fourth and last combining all three codes into the ecorified code, which contains the implementation details of the original code and the Ecore functionality of the model code.

The Ecorification Process

After the ecorification we distinguish Java code from three different sources:

  • Origin code: Describes the edited classes of the original Java code.
  • Ecore code: Describes the Java code that was generated from the Ecore metamodel that was extracted from the original code.
  • Integration code: Describes the Java code that is used to connect the origin code and the Ecore code

To ecorify Java code, an Ecore metamodel will be extracted from the original code. The metamodel is then used to generate the Ecore code. For every class in the original code, there is now an interface and a class inheriting from EObject in the Ecore code. Then, the integration code will be generated. For every class in the original code, there will be a wrapper class that implements the correlating interface in the Ecore code. It delegates all Ecore functionality to the correlating implementation class in the Ecore code. The original classes will now be edited to inherit from the correlating wrapper classes. These classes form the origin code.

This Ecorification pattern is depicted for one class in the following diagram:

Depiction of the Ecorificaton

For more information see "Automatic Integration of Ecore Functionality into Java Code".

Clone this wiki locally