Skip to main content



      Home
Home » Modeling » EMF » Access an EMF package from the Ecore file.(Access an EMF package from the Ecore file.)
Access an EMF package from the Ecore file. [message #1070760] Thu, 18 July 2013 11:51 Go to next message
Eclipse UserFriend
Hello,

I am trying to access an EPackage from a file as the EMF Eclipse Modeling Framework Second Edition shows us on page 422. The twist is that I am trying to do it in a standalone environment (from a main() method). I'm tring to run the following in a main:


try
{
    File f = new File("C:/Users/awhelan/WDW.ecore");
    /*		 
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
                 .put("xml", new XMLResourceFactoryImpl());
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("com.blah", new EcoreResourceFactoryImpl());
    */
    URI fileURI = URI.createFileURI(f.getAbsolutePath());
    Resource resource = new XMIResourceFactoryImpl().createResource(fileURI);	    
    ResourceSet resourceSet = new ResourceSetImpl(); 
    Resource resource1 = resourceSet.getResource(fileURI, true);
    EPackage wdwPackage = (EPackage)resource1.getContents().get(0);
}catch(Exception e){
    e.printStackTrace();
}



The two commented out Resource.Factory.Registry... statements don't make a difference. The namespace URI of the Ecore file is nsURI="com.blah". I get the following exception trace when I try to run the above code in this standalone environment. Any ideas?

java.lang.RuntimeException: Cannot create a resource for 'file:/C:/Users/awhelan/WDW.ecore'; a registered resource factory is needed
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
at com.src.ewir.wdw.dynamicpackage.DynamicPackage.main(DynamicPackage.java:87)

[Updated on: Thu, 18 July 2013 11:55] by Moderator

Re: Access an EMF package from the Ecore file. [message #1070797 is a reply to message #1070760] Thu, 18 July 2013 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Andrew,

Comments below.

On 18/07/2013 5:51 PM, Andrew Whelan wrote:
> Hello,
>
> I am trying to access an Ecore from a file as the EMF Eclipse Modeling
> Framework Second Edition shows us on page 422. The twist is that I am
> trying to do it in a standalone environment (from a main() method).
> I'm tring to run the following in a main:
>
>
>
> try
> {
> File f = new File("C:/Users/awhelan/WDW.ecore");
> /*
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
> new XMLResourceFactoryImpl());
You're Ecore resources use "ecore" though, so do you register
EcoreResourceFactoryImpl for that?
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("com.blah",
> new EcoreResourceFactoryImpl());
What's this?
> */
> URI fileURI = URI.createFileURI(f.getAbsolutePath());
> Resource resource = new
> XMIResourceFactoryImpl().createResource(fileURI);
What's this for?
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource1 = resourceSet.getResource(fileURI, true);
> EPackage wdwPackage =
> (EPackage)resource1.getContents().get(0);
> }catch(Exception e){
> e.printStackTrace();
> }
>
>
>
> The two commented out Resource.Factory.Registry... statements don't
> make a difference.
Because you're not loading resources with those file extensions...
> The namespace URI of the Ecore file is nsURI="com.blah". jI get the
> following exception trace when I try to run the above code in this
> standalone environment. Any ideas?
>
> java.lang.RuntimeException: Cannot create a resource for
> 'file:/C:/Users/awhelan/WDW.ecore'; a registered resource factory is
> needed
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
> at
> com.src.ewir.wdw.dynamicpackage.DynamicPackage.main(DynamicPackage.java:87)
EcoreResourceFactoryImpl should be registered to handle "ecore" extension.
Re: Access an EMF package from the Ecore file. [message #1071190 is a reply to message #1070797] Fri, 19 July 2013 10:23 Go to previous message
Eclipse UserFriend
Thanks for your help.

The following loads without error.
File f = new File("C:/Users/awhelan/WDW.ecore");
URI fileURI = URI.createFileURI(f.getAbsolutePath());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl ());
			
ResourceSet resourceSet = new ResourceSetImpl(); 
Resource resource1 = resourceSet.getResource(fileURI, true);
EPackage wdwPackage = (EPackage)resource1.getContents().get(0);

Previous Topic:Upgrade of Xcore SDK produces strange errors
Next Topic:How to annotate HTML?
Goto Forum:
  


Current Time: Wed Jul 30 16:01:34 EDT 2025

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

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

Back to the top