Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Load an ecore file programmatically
Load an ecore file programmatically [message #1754121] Tue, 14 February 2017 15:54 Go to next message
Fa Za is currently offline Fa ZaFriend
Messages: 235
Registered: March 2010
Senior Member
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 17:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29385
Registered: July 2009
Senior Member
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 10:11 Go to previous messageGo to next message
Fa Za is currently offline Fa ZaFriend
Messages: 235
Registered: March 2010
Senior Member
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 10:13 Go to previous messageGo to next message
Fa Za is currently offline Fa ZaFriend
Messages: 235
Registered: March 2010
Senior Member
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 10:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29385
Registered: July 2009
Senior Member
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...
Previous Topic:Unable to set an attribute as primary key
Next Topic:Very high loading times of models with ID feature
Goto Forum:
  


Current Time: Wed Jun 20 04:15:00 GMT 2018

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

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

Back to the top