Skip to main content



      Home
Home » Modeling » EMF » Load an ecore file programmatically
Load an ecore file programmatically [message #1754121] Tue, 14 February 2017 10:54 Go to next message
Eclipse UserFriend
I try to load an ecore file which already exists in the plugins folder (I see it in the "registered epackages view, yet)
I find this code in the forum
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// Create a resource set.
		ResourceSet resourceSet = new ResourceSetImpl();

		// Register the default resource factory -- only needed for stand-alone!
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
		"ecore", new EcoreResourceFactoryImpl());

		// Register the package -- only needed for stand-alone!
		EcorePackage ecorePackage = EcorePackage.eINSTANCE;

		// Get the URI of the model file.
		URI fileURI = URI.createPlatformPluginURI("platform:/plugin/org.eclipse.mymetamodel/model/MyMetaModel.ecore",false);

		// Demand load the resource for this file.
		Resource resource = resourceSet.getResource(fileURI, true);

		// Print the contents of the resource to System.out.
		try
		{
		resource.save(System.out, Collections.EMPTY_MAP);
		}
		catch (IOException e) {}
	}

but I have this error

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.net.MalformedURLException: unknown protocol: platform
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at faiez.test.odesign.LoadEmf.main(LoadEmf.java:32)
Caused by: java.net.MalformedURLException: unknown protocol: platform
	at java.net.URL.<init>(URL.java:600)
	at java.net.URL.<init>(URL.java:490)
	at java.net.URL.<init>(URL.java:439)
	at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:199)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1269)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	... 2 more



Any suggestions?

best regards
Re: Load an ecore file programmatically [message #1754141 is a reply to message #1754121] Tue, 14 February 2017 12:19 Go to previous messageGo to next message
Eclipse UserFriend
The platform protocol is registered by the Eclipse runtime so it doesn't work standalone. Why don't you just use the generated MyMetaModelPackage.eINSTANCE instead of trying to load it? If you must load it stand alone, using something like archive:file:/<file-system-location-of-jar>!/model/MyMetaModel.ecore. Or get a URL to it from the classpath.
Re: Load an ecore file programmatically [message #1754311 is a reply to message #1754141] Thu, 16 February 2017 05:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed!
I want to load the metamodel because I would like use it as a model (instance of Ecore.ecore) to do a model transformation.
Indeed, I want to search the efeatures, classifiers, etc. in the metamodel
Re: Load an ecore file programmatically [message #1754312 is a reply to message #1754311] Thu, 16 February 2017 05:13 Go to previous messageGo to next message
Eclipse UserFriend
I want to transform the metamodel something.ecore to another format
Re: Load an ecore file programmatically [message #1754315 is a reply to message #1754312] Thu, 16 February 2017 05:52 Go to previous messageGo to next message
Eclipse UserFriend
I see. If the generated model is present, perhaps you can use MyMetaModelPackage.eNS_URI as the URI so that the transformation technology loads (fetches from the package registry), the MyMetaModelPackage.eINSTANCE...
Re: Load an ecore file programmatically [message #1831701 is a reply to message #1754121] Wed, 26 August 2020 22:04 Go to previous message
Eclipse UserFriend
Hi, I am able to get your code to work if I change:

// Get the URI of the model file.
URI fileURI = URI.createPlatformPluginURI("platform:/plugin/org.eclipse.mymetamodel/model/MyMetaModel.ecore",false);


to:

// Get the URI of the model file.
URI fileURI = URI.createFileURI("/path/to/saved/file.ecore");


I hope that helps!
Previous Topic:EMF, GWT ELIST and serialisation
Next Topic:How to get enums per emf reflections?
Goto Forum:
  


Current Time: Tue Jul 08 08:36:55 EDT 2025

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

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

Back to the top