Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Newbie: How to load an ecore model in code?
Newbie: How to load an ecore model in code? [message #416090] Thu, 17 January 2008 14:40 Go to next message
Jochen Wuttke is currently offline Jochen WuttkeFriend
Messages: 41
Registered: July 2009
Member
Hi,

I'm just getting started with EMF, so if this question has been answered
before just point me to the right place.


I'm trying to build a plug-in that processes Ecore models, looks for
annotations and patterns and stuff like that. For that I believe I need
to be able to access the model somehow. I was expecting to find some
sort of API that allows the loading of an ecore file and returns the
root package of the model, or something like that. So far I've been
unable to locate such an API. I tried working through the
org.eclipse.emf.importer stuff, but I don't really see what this is
doing and documentation is rather sparse.

Can anyone point me to the right place where to start looking or does
anyone even have example code?

Thanks
Jochen
Re: Newbie: How to load an ecore model in code? [message #416094 is a reply to message #416090] Thu, 17 January 2008 14:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000001090609090406060109
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jochen,

It should be as simple as this:

ResourceSet resourceSet = new ResourceSetImpl();
Resource ecoreResource =
resourceSet.getResource(<uri-of-*.ecore-resource>, true);
EPackage ePackage = (EPackage)ecoreResource.getContents().get(0);

If you're loading a resource form the work space, use
URI.createPlatformResourceURI(iFile.getFullPath().toString() , true), and
if it's a file system file, use URI.createFileURI(new
File(<path>).getAbsolutePath()).

Looking at what EcoreEditor does to load a model and then let you edit
it shows it in a fancier context...


Jochen wrote:
> Hi,
>
> I'm just getting started with EMF, so if this question has been
> answered before just point me to the right place.
>
>
> I'm trying to build a plug-in that processes Ecore models, looks for
> annotations and patterns and stuff like that. For that I believe I
> need to be able to access the model somehow. I was expecting to find
> some sort of API that allows the loading of an ecore file and returns
> the root package of the model, or something like that. So far I've
> been unable to locate such an API. I tried working through the
> org.eclipse.emf.importer stuff, but I don't really see what this is
> doing and documentation is rather sparse.
>
> Can anyone point me to the right place where to start looking or does
> anyone even have example code?
>
> Thanks
> Jochen


--------------000001090609090406060109
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jochen,<br>
<br>
It should be as simple as this:<br>
<blockquote>&nbsp; ResourceSet resourceSet = new ResourceSetImpl();<br>
&nbsp; Resource ecoreResource =
resourceSet.getResource(&lt;uri-of-*.ecore-resource& gt;, true);<br>
&nbsp; EPackage ePackage = (EPackage)ecoreResource.getContents().get(0);<br>
</blockquote>
If you're loading a resource form the work space, use
URI.createPlatformResourceURI(iFile.getFullPath().toString() , true),
and if it's a file system file, use URI.createFileURI(new
File(&lt;path&gt;).getAbsolutePath()).<br>
<br>
Looking at what EcoreEditor does to load a model and then let you edit
it shows it in a fancier context...<br>
<br>
<br>
Jochen wrote:
<blockquote cite="mid:fmnpdr$meu$1@build.eclipse.org" type="cite">Hi,
<br>
<br>
I'm just getting started with EMF, so if this question has been
answered before just point me to the right place.
<br>
<br>
<br>
I'm trying to build a plug-in that processes Ecore models, looks for
annotations and patterns and stuff like that. For that I believe I need
to be able to access the model somehow. I was expecting to find some
sort of API that allows the loading of an ecore file and returns the
root package of the model, or something like that. So far I've been
unable to locate such an API. I tried working through the
org.eclipse.emf.importer stuff, but I don't really see what this is
doing and documentation is rather sparse.
<br>
<br>
Can anyone point me to the right place where to start looking or does
anyone even have example code?
<br>
<br>
Thanks
<br>
Jochen
<br>
</blockquote>
<br>
</body>
</html>

--------------000001090609090406060109--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Newbie: How to load an ecore model in code? [message #416095 is a reply to message #416094] Thu, 17 January 2008 15:35 Go to previous message
Jochen Wuttke is currently offline Jochen WuttkeFriend
Messages: 41
Registered: July 2009
Member
Ed Merks wrote:

Thanks, this got me going...


> It should be as simple as this:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource ecoreResource =
> resourceSet.getResource(<uri-of-*.ecore-resource>, true);
> EPackage ePackage = (EPackage)ecoreResource.getContents().get(0);
>
> If you're loading a resource form the work space, use
> URI.createPlatformResourceURI(iFile.getFullPath().toString() , true), and
> if it's a file system file, use URI.createFileURI(new
> File(<path>).getAbsolutePath()).
>
> Looking at what EcoreEditor does to load a model and then let you edit
> it shows it in a fancier context...
Previous Topic:Add multiple RectangleFigure in a Figure.
Next Topic:Odd CCE in Delete command
Goto Forum:
  


Current Time: Sat Apr 27 04:42:02 GMT 2024

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

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

Back to the top