Accessing EMF model through java [message #502666] |
Wed, 09 December 2009 10:49 |
RJ Messages: 19 Registered: October 2009 Location: Eindhoven, The Netherland... |
Junior Member |
|
|
Hi,
I'm trying to access a model created in EMF through Java code, basically as done here, in Chapter 7.
However, when trying to load my model, I get the error:
Package with uri 'http://MFDMetaInst/2.0' not found.
This package is my metamodel, which is obviously not registered, and should be, before loading the model. So my question is, how do I do this?
I would assume that it should happen somewhere in this block, but I'm not exactly sure where and (most of all) how.
public MFD load(String loc) {
// Initialize the model
MFDMetaInstPackage.eINSTANCE.eClass();
// Register the XMI resource factory for the .mfdmetainst extension
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("mfdmetainst", new XMIResourceFactoryImpl());
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
// Get the resource
Resource resource = resSet.getResource(URI
.createURI(loc), true);
where the variable loc is a string with the location of the model to be loaded.
Could anyone help me out?
|
|
|
|
|
Re: Accessing EMF model through java [message #502728 is a reply to message #502666] |
Wed, 09 December 2009 14:54 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
RJ,
Is 'http://MFDMetaInst/2.0' the actual value of
MFDMetaInstPackage.eNS_URI? You can see where the exception is being
thrown and use the debugger to understand why a matching package isn't
found; I'd expect the package to be in the global package registry based
on the code you've shown...
RJ wrote:
> Hi,
>
> I'm trying to access a model created in EMF through Java code,
> basically as done
> http://www.vogella.de/articles/EclipseEMF/article.html, in Chapter 7.
>
> However, when trying to load my model, I get the error:
> Package with uri 'http://MFDMetaInst/2.0' not found.
> This package is my metamodel, which is obviously not registered, and
> should be, before loading the model. So my question is, how do I do this?
>
> I would assume that it should happen somewhere in this block, but I'm
> not exactly sure where and (most of all) how.
> public MFD load(String loc) {
> // Initialize the model
> MFDMetaInstPackage.eINSTANCE.eClass();
>
> // Register the XMI resource factory for the .mfdmetainst
> extension
> Resource.Factory.Registry reg =
> Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("mfdmetainst", new XMIResourceFactoryImpl());
>
> // Obtain a new resource set
> ResourceSet resSet = new ResourceSetImpl();
>
> // Get the resource
> Resource resource = resSet.getResource(URI
> .createURI(loc), true);
>
> where the variable loc is a string with the location of the model to
> be loaded.
>
> Could anyone help me out?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03160 seconds