Jump to: navigation, search

EMF/Deriving EMF Models

Revision as of 23:23, 3 September 2006 by Paul.socialphysics.org (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In accordance with the EMF FAQ, EMF models can be created in memory, leveraging the reflective side of EMF.

Firstly, we need to select which EMF package is going to provide containment for our custom classes. There are multiple options, and we are going to examine two of them. The first option is to try and extend one of the existing EMF packages, such as the one contained within org.eclipse.etf.ecore.context.persistence. This is not a very good idea, because that package uses a namespace which potentially differs from the namespace we would like to assign to our custom classes. Therefore, the second viable option, which is recommended in this essay, is to create a custom EMF package. This is done with the following code:

EPackage pkg = EcoreFactory.eINSTANCE.createEPackage();

After creating this package, we must assign its namespace URI. Assigning the name and the namespace prefix is optional, but in favor of keeping the code clean and comprehensible, we would like to set those optional attributes just as well.