Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Load ecore metamodel in eclipse runtime
Load ecore metamodel in eclipse runtime [message #1436798] Fri, 03 October 2014 12:25 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hey all,

maybe it is stupid question but I would like to load the Ecore.ecore metamodell to
a resourceset which is used by an editor. The editor is running in a runtime eclipse instance. Here is the way I did it:

//register the package
EcorePackage.eINSTANCE.eClass();
EPackage.Registry.INSTANCE.put(EcoreFactory.eINSTANCE.getEPackage().getNsURI(), EcoreFactory.eINSTANCE.getEPackage());
//get the uri
URI ecoreUri = URI.createURI(EcoreFactory.eINSTANCE.getEPackage().getNsURI(), true);
//get the resource
Resource ecoreResource = xtextResourceSet.getResource(ecoreUri, true);
try {
//load it
ecoreResource.load(null);
} catch (IOException e) {
e.printStackTrace();
		}


This works, but only if the Ecore.ecore file is inside the runtime workspace. Otherwise the the metamodel is can't be found.

What am I doing wrong?
Criticism is welcome!

~Alex


Re: Load ecore metamodel in eclipse runtime [message #1436816 is a reply to message #1436798] Fri, 03 October 2014 12:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
Registered: July 2009
Senior Member
Alexander,

Comments below.

On 03/10/2014 2:25 PM, Alexander R wrote:
> Hey all,
>
> maybe it is stupid question but I would like to load the Ecore.ecore
> metamodell to
> a resourceset which is used by an editor.
Hmm...
> The editor is running in a runtime eclipse instance. Here is the way I
> did it:
>
>
> //register the package
> EcorePackage.eINSTANCE.eClass();
This isn't necessary in an Eclipse environment.
> EPackage.Registry.INSTANCE.put(EcoreFactory.eINSTANCE.getEPackage().getNsURI(),
This is just EcorePackage.eNS_URI
> EcoreFactory.eINSTANCE.getEPackage());
This is just EcorePackage.eINSTANCE.

This too is redundant in an Eclipse environment.
> //get the uri
> URI ecoreUri =
> URI.createURI(EcoreFactory.eINSTANCE.getEPackage().getNsURI(), true);
> //get the resource
> Resource ecoreResource = xtextResourceSet.getResource(ecoreUri, true);
This will just return the resource already in the package registry.
I.e., the same as EcorePackage.eINSTANCE.eResource().
> try {
> //load it
> ecoreResource.load(null);
It's already loaded, so this will do nothing.
> } catch (IOException e) {
> e.printStackTrace();
> }
>
>
> This works, but only if the Ecore.ecore file is inside the runtime
> workspace. Otherwise the the metamodel is can't be found.
Perhaps you want to be loading using the URI
"platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore"; that will
load the development time instance of Ecore. Note that the Ecore editor
does

resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));

before loading any models...
>
> What am I doing wrong?
> Criticism is welcome!
>
> ~Alex
>
>
>
Re: Load ecore metamodel in eclipse runtime [message #1438568 is a reply to message #1436816] Mon, 06 October 2014 08:03 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 03/10/2014 14:53, Ed Merks wrote:

>
> resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
>

One of the harder to understand things in the runtime. Whenever I
stumble over this I need to think and read thrice what it actually does.
Maybe we could create like a table to illustrate this better and put it
in the doc or the wiki? Somehow like this:

In Workspace In Platform Loads
platform:plugin yes no WS
platform:plugin yes yes WS
....


Would people find that useful?
Felix
Previous Topic:NullPointerException during code-generation from UML Profile
Next Topic:[Xcore] Basic Question
Goto Forum:
  


Current Time: Tue Nov 12 13:29:36 GMT 2019

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

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

Back to the top