RSS

Search Engine

Thursday, July 22, 2010

Generating the domain classes

4.1. Generating Java code

You have created two models, the Ecore and the Genmodel model.

Once your model definition is complete you can generate Java code from it. Right-click on the root node of the genmodel and select "Generate Model Code".

This will create the Java implementation of the EMF model in the current project.

4.2. Review the generated code

The generated code will consists out of the following:

  • model -- Interfaces and the Factory to create the Java classes

  • model.impl -- Concrete implementation of the interfaces defined in model

  • model.util -- The AdapterFactory

The central factory has methods for creating all defined objects via createObjectName() methods.

For each attribute the generated interface and its implementation contains getter and (if allowed in the model definition) setter methods.

Each interface extends the base interface EObject. EObject is the base of every EMF class and is the EMF equivalent of java.lang.Object. EObject and its corresponding implementation class EObjectImpl provide a lightweight base class that lets the generated interfaces and classes participate in the EMF notification and persistence frameworks.

Each setter has also a generated notification to observers of the model. This mean that other object can attach them to the model and react to changes in the model.

Every generated method is tagged with @generated. If you want to manually adjust the method you want to prevent that EMF overwrites the method during the next generation run you have to remove this tag.

0 comments:

Post a Comment