RSS

Search Engine

Thursday, July 22, 2010

Using the model code

6.1. Overview

The generated model code is standard Java code and can be used as such. The following demonstrates how you create objects based on the generated code.

6.2. Example

Create a new plugin project "sawan.modi.emf.webpage.usingmodel". Add the following dependency to your "plugin.xml".

  • org.eclipse.emf.ecore
  • sawan.modi.emf.webpage.model

Create the following class.

   
package sawan.modi.emf.webpage.usingmodel;

import sawan.modi.emf.webpage.model.webpage.MyWeb;
import sawan.modi.emf.webpage.model.webpage.Webpage;
import sawan.modi.emf.webpage.model.webpage.WebpageFactory;
import sawan.modi.emf.webpage.model.webpage.impl.WebpagePackageImpl;

public class UsingEMFModel {
public static void main(String[] args) {
WebpagePackageImpl.init();
// Retrieve the default factory singleton
WebpageFactory factory = WebpageFactory .eINSTANCE;
// Create an instance of myWeb
MyWeb myWeb = factory.createMyWeb();
myWeb.setName("Hallo");
myWeb.setDescription("This is a description");
// Create a page
Webpage webpage = factory.createWebpage();
webpage.setTitle("This is a title");
// Add the page to myWeb
myWeb.getPages().add(webpage);
// and so on, and so on
// as you can see the EMF model can be (more or less) used as standard Java


}
}

0 comments:

Post a Comment