Over a million developers have joined DZone.

From Persistency Questions To EMF …

DZone 's Guide to

From Persistency Questions To EMF …

· Java Zone ·
Free Resource

This week I finally decided to step in EMF. 2 years after starting Eclipse development …. French people will say here “Mieux vaut tard que jamais

Here is the story …

In a custom view built on top of Draw2D  providing embedded C profiling informations to the user we decided to add filtering capabilities. Thus we added a filtering button opening a dialog letting the user choose the elements he wants to filter.

Quickly we got the following interfaces and associated implementation:

public interface Filter {

public String getName();

public boolean isFiltered(Object element);

public interface TypeFilter extends Filter {

public void addType(String type);

public boolean removeType(String type);

We easily implemented filtering management using these interfaces . Then came the need to save user defined filters across Eclipse launches.

Saving these filters in our plugin directory inside the workspace (/workspace/.metadata/plugins/my.plugin.id) came immediately in our minds but HOW …. ????

  1. Using Eclipse preferences store ?? Impossible our filters are composed of a name attribute (type String) and a liste of types attribute (type List<String>)  and preferences store can only stor informations of type “key=value”.
  2. Using XML ?? Nice solution but …. needs to reinvent the wheel in order to convert our filter data structure into XML and to get back our data structure from this XML.
  3. Using EMF ?? Yes of course, among a lot features it’s here for that !!!!

I took up my sleeves and less than 1 hour after our filters was persisted across Eclipse instances !!!!

Here is the way I proceeded (mainly following EMF book) :

  1. Annotation of previously described Java interfaces
  2. Generation of model classes
  3. Persistence of these generated classes using EMF API (Ressource)
  4. Well done EMF !!!

This experience introduced me smoothly to EMF and avoided me to waste time on XML parsing/writing with in Java. I certainly should have used EMF before … I’ll try to use it more in the future in order to really understand all the benefits it can bring.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}