I’m starting a serie of blog post describing a framework each week, so enjoy reading!
The first framework i’ll speak about is Eclipse EMF.
EMF aims to bridge the gap between raw code and modelized one (generated from a data model model representation).
It’s a very visual technology because you manipulate models (trees or diagrams) to define your future Java code (I think that my next blogposts, for example on Maven will be far less sexy).
So graphically defining a metamodel using the ecore meta-meta model (the domain object you’ll manipulate, or your classes if you prefer) you’ll be then able to round trip between Java code generation and customization.
EMF modelization is based on multiple concepts:
- The ResourceSet: this is a set of Resources
- Resource: a resource is a set of coherent model objects and packages: formerly an xmi (xml) file containing the definition of your model
- Package: a set of model objects
- Model Object: formely a Java class: can have references to other model objects, have attributes, visibility: it’s contained by a resource or an other model object
- Containment: As EMF sees the world as an xmi, a model object MUST be contained by an other or the resource
The generated code is done in a clean way, you’ll be able to generate 3 eclipse plugins starting from a model definition:
The model plugin
The model plugin contains your domains classes.
These classes are generated as a kind of Java beans, sending notifications each time a change is done on the object instance.
The model plugin also contains a factory to create object instances and a Package class referencing all the metamodel classes, references and attributes.
The edit plugin
This plugin contains adapters that will give the Images, getText, property source content, etc of model classes
The editor plugin
It will contain a basic Eclipse tree editor and menus to be able to manipulate your domain objects
You can now create a new ecore file on the ‘model’ folder (your model objects definition)
Right click on your genmodel root node, and generate model, edit and editor code.
In order to test the result, we’ve to create a new Eclipse run configuration:
EMF do’s and don’ts
EMF reference book