Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Accessing EMF model through java
Accessing EMF model through java [message #502666] Wed, 09 December 2009 10:49 Go to next message
RJ is currently offline RJFriend
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 #502679 is a reply to message #502666] Wed, 09 December 2009 11:47 Go to previous messageGo to next message
Tim Usaty is currently offline Tim UsatyFriend
Messages: 4
Registered: December 2009
Junior Member
Hi, RJ


I've had a similar problem.

Try this:

EPackage.Registry.INSTANCE.put(
   WebsitePackage.eNS_URI,
   WebsitePackage.INSTANCE);


after the line:
MFDMetaInstPackage.eINSTANCE.eClass();

[Updated on: Wed, 09 December 2009 11:55]

Report message to a moderator

Re: Accessing EMF model through java [message #502681 is a reply to message #502679] Wed, 09 December 2009 12:00 Go to previous messageGo to next message
RJ is currently offline RJFriend
Messages: 19
Registered: October 2009
Location: Eindhoven, The Netherland...
Junior Member
Thanks, that did the trick Very Happy

only had to add
import org.eclipse.emf.ecore.EPackage.Registry; 

to my imports,

thanks again
Re: Accessing EMF model through java [message #502728 is a reply to message #502666] Wed, 09 December 2009 14:54 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
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?
Previous Topic:[Teneo] updates E_Version column
Next Topic:[CDO] Walking the graph of a revision
Goto Forum:
  


Current Time: Tue Nov 12 17:10:11 GMT 2019

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

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

Back to the top