Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ECORE API example
ECORE API example [message #407673] Fri, 09 March 2007 16:56 Go to next message
Eclipse UserFriend
Originally posted by: bdberry.us.ibm.com

Hi,

Are there any examples of using ecore API to create an ecore model file
programmatically? Furthermore, can I automate the creation of the
genmodel and generate the code? I am working on a utility to
dynamically create models and corresponding code (model and editors).


Thanks.
Re: ECORE API example [message #407681 is a reply to message #407673] Sat, 10 March 2007 16:09 Go to previous messageGo to next message
Matthias Braeuer is currently offline Matthias BraeuerFriend
Messages: 6
Registered: July 2009
Junior Member
Brian,

> Are there any examples of using ecore API to create an ecore model file
> programmatically?

The EMF book has a detailled section on this topic (13.6 - Dynamic EMF).
Essentially, there is nothing special about creating Ecore models
dynamically. It's done as for any other EMF model, using the generated
Package and Factory classes.

For example:

EcoreFactory factory = EcoreFactory.eINSTANCE;
EcorePackage package = EcorePackage.eINSTANCE;

EClass libraryClass = factory.createEClass();
libraryClass.setName("Library");

EAttribute numBooksAttribute = factory.createEAttribute();
numBooksAttribute.setName("numBooks");
numBooksAttribute.setType(package.getEInteger());

libraryClass.getEAttributes().add(numBooksAttribute);

// ...


> Furthermore, can I automate the creation of the
> genmodel and generate the code?

A search on the newsgroup should give plenty of answers to this
question, e.g.:

http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 1057.html


Regards,
Matt
Re: ECORE API example [message #407684 is a reply to message #407681] Sat, 10 March 2007 18:05 Go to previous message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Brian

Besides the awesome pointers from Matt, you can also see several
examples of models built by hand on EMF's JUnit test. Here's an example
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/tes ts/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/d ynamic/SimpleModelTest.java?root=Tools_Project&view=mark up

Cheers,
Marcelo

Matthias Bräuer wrote:
> Brian,
>
>> Are there any examples of using ecore API to create an ecore model
>> file programmatically?
>
> The EMF book has a detailled section on this topic (13.6 - Dynamic EMF).
> Essentially, there is nothing special about creating Ecore models
> dynamically. It's done as for any other EMF model, using the generated
> Package and Factory classes.
>
> For example:
>
> EcoreFactory factory = EcoreFactory.eINSTANCE;
> EcorePackage package = EcorePackage.eINSTANCE;
>
> EClass libraryClass = factory.createEClass();
> libraryClass.setName("Library");
>
> EAttribute numBooksAttribute = factory.createEAttribute();
> numBooksAttribute.setName("numBooks");
> numBooksAttribute.setType(package.getEInteger());
>
> libraryClass.getEAttributes().add(numBooksAttribute);
>
> // ...
>
>
>> Furthermore, can I automate the creation of the genmodel and generate
>> the code?
>
> A search on the newsgroup should give plenty of answers to this
> question, e.g.:
>
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 1057.html
>
>
> Regards,
> Matt
Previous Topic:Listening to Model-Changes
Next Topic:ILightweightLabelDecorator stops working after a while
Goto Forum:
  


Current Time: Tue Apr 23 06:03:42 GMT 2024

Powered by FUDForum. Page generated in 0.03131 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top