Load ecore metamodel in eclipse runtime [message #1436798] |
Fri, 03 October 2014 08:25  |
Eclipse User |
|
|
|
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 08:53   |
Eclipse User |
|
|
|
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 04:03  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06959 seconds