Showing posts with label EMF. Show all posts
Showing posts with label EMF. Show all posts

Friday, February 17, 2012

First Eclipse Modeling Framework (EMF) example - 3

In the previous article we've created a domain model for a Library Management System, and we've generated a set of corresponding Java classes, by using Eclipse Modeling Framework (EMF).

Now, we're going to test those classes through a new Eclipse project, which references the one with the generated classes.

So, we now create a new plug-in project:
                                     File --> Create --> New --> Project... --> Plug-in Project.


And, in folder src, we create a new class with a stub for method main:


And we create, in method main(), a few lines of code:

package javaUsingEMFModel.LibrarySystem;

import org.eclipse.emf.ecore.*;
import LibraryModel.*;
import LibraryModel.impl.*;
import LibraryModel.util.*;

public class MainClass {
    public static void main(String[] args) {

// Inicialize the LibraryModelPackageImpl
        LibraryModelPackageImpl.init();

        LibraryModelFactory factory = LibraryModelFactory.eINSTANCE;
       
        // Create a new Book
        Book book = factory.createBook();

        // Give a title to the book
        book.setTitle("Os Lusiadas");
       
        // Create an Author, and define his/her name and surname
        Author author1 = factory.createAuthor();
        author1.setName("Luis");
        author1.setSurname("Camoes");
       
        // Add that author as an author of the previously created book
        book.getAuthors().add(author1);
       
       
        System.out.println(book.getTitle());
    }
}

This is only the beginning. Now you should create instances of the remaining classes, inter-relate them, and query its attribute values and the values of the relation attributes.

Related articles:
        - First Eclipse Modeling Framework (EMF) example - 1
        - First Eclipse Modeling Framework (EMF) example - 2




Thursday, February 16, 2012

First Eclipse Modeling Framework (EMF) example - 2

In the previous article we started exploring Eclipse EMF. In this article we will build a domain model (persistent data model) of a small library management system.

To start, let us create a new project:

        - select File --> New --> Project
        - Then, in the opening window, select Eclipse Modeling Framework --> Empty EMF Project



Let's name our project testemf.

Then, in folder model, use the mouse's right button,



and select New --> Other. A new window opens:



Here, select EcoreTools --> Ecore Diagram. The goal is to create a domain model by using the UML class diagram editor.

Creating the Ecore Diagram is a nice way of creating an Ecore model, instance of the Ecore metamodel. We can, then, understand this as the creation of a DSL (Domain Specific Language). Let us name our DSL as LibraryModel.

Tuesday, February 14, 2012

First Eclipse Modeling Framework (EMF) example - 1

Eclipse is an IDE (Interactive Development Environment) that allows the development of programs in different programming languages. Some characteristics of Eclipse are the use of the Standard Widget Toolkit (SWT) as graphics library, instead of Swing, the plugin oriented way of programming, and its extensibility, there existing lots of projects that extend Eclipse in diverse directions.
One of those directions is model-driven-development, and the subsequent code generation from models. Eclipse Modeling Framework (EMF) project is a modeling environment and code generation functionality that enables the construction of tools and other software applications based on a structured data model (domain model). From a domain model specified in XMI, or in another supported format, EMF provides tools and runtime support for the production of Java classes that implement the model, and a set of adapter classes that allow editting and viewing the model through Java code, and a basic model editor.