Using the Eclipse Modeling Framework (EMF) Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Access to models generated with the Eclipse Modeling Framework is easy in Groovy with the help of Groovy Beans and GPath.

As an example we use the EMF tutorial. This model contains three classes Book, Writer and Library and an enumeration BookCategory. From this model EMF generates Java code. There are two special classes: a package class and a factory class. We need the package class for reading the model. We have to instantiate it and load a file with data as following.

Now we are able to query the model using standard Groovy. For example

prints out all books. We can print out all the books with less than 240 pages with the following statement.

All the objects in an EMF model are constructed with methods from a factory (LibraryFactory in this example). The Groovy EMF Builder provides an interface for constructing models and model elements. It takes an EMF factory as an argument. In the following snippet three objects are created in the model: a Library, a Writer and a Book.

The braces indicate the containment relationships writers and books of the class Library.

See the homepage of the Groovy EMF Builder for further details.



Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs.

  By  -  pages  -  views  - last modified