Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Cannot create a resource
Cannot create a resource [message #910337] Sun, 09 September 2012 09:53 Go to next message
Vishnu Jakhoria is currently offline Vishnu JakhoriaFriend
Messages: 2
Registered: September 2012
Junior Member
I am using EMF in a standalone application. I am getting the following error:


java.lang.RuntimeException: Cannot create a resource for 'file:/C:/Vishnu/Work/runtime-Rule_test/testRule/xsd/CreditCard.xsd'; a registered resource factory is needed
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
at com.sap.server.TestMain.main(TestMain.java:63)



CODE:

private static List<XSDSchema> loadXSDSchema() throws FileNotFoundException
{
List<XSDSchema> schemas=new ArrayList<XSDSchema>();
//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
try {
Resource resource = resourceSet.getResource(URI.createFileURI("C:/Vishnu/Work/runtime-Rule_test/testRule/xsd/CreditCard.xsd", true);
if(resource instanceof XSDResourceImpl)
{
XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
// The contents of the resource is the root XSDSchema object
schemas.add(xsdResource.getSchema());
}
}catch(Exception e){
e.printStackTrace();
}
return schemas;
}


Can someone please help me on this. I am completely new to EMF and any help in this issue will be helpful.Thank you.
Re: Cannot create a resource [message #910344 is a reply to message #910337] Sun, 09 September 2012 10:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
You'll want to add this<br>
<blockquote>resourceSet.getURIConverter().getResourceFactoryRegistry().getExtensionToFactoryMap().put("xsd",
new XSDResourceFactoryImpl());  <br>
</blockquote>
Or do this, but only in a stand alone application, not when running
as a plugin:<br>
<blockquote>Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd",
new XSDResourceFactoryImpl());<br>
</blockquote>
You shouldn't need to cast to XSDResourceImpl; you can do
resource.getContents().get(0) and test if that's an XSDSchema.<br>
<br>
<br>
<div class="moz-cite-prefix">On 09/09/2012 11:53 AM, Vishnu Jakhoria
wrote:<br>
</div>
<blockquote cite="mid:k2hove$hsk$1@xxxxxxxxe.org" type="cite">I
am using EMF in a standalone application. I am getting the
following error: <br>
<br>
java.lang.RuntimeException: Cannot create a resource for
'<a class="moz-txt-link-freetext" href="file:/C:/Vishnu/Work/runtime-Rule_test/testRule/xsd/CreditCard.xsd">file:/C:/Vishnu/Work/runtime-Rule_test/testRule/xsd/CreditCard.xsd</a>';
a registered resource factory is needed
<br>
    at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)<br>
    at com.sap.server.TestMain.main(TestMain.java:63)
<br>
<br>
<br>
<br>
CODE:
<br>
<br>
private static List&lt;XSDSchema&gt; loadXSDSchema() throws
FileNotFoundException
<br>
    {
<br>
        List&lt;XSDSchema&gt; schemas=new
ArrayList&lt;XSDSchema&gt;();
<br>
       
//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml",
new XMLResourceFactoryImpl());
<br>
       
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
new XMLResourceFactoryImpl());
<br>
        ResourceSet resourceSet = new ResourceSetImpl();
<br>
        try {
<br>
                Resource resource =
resourceSet.getResource(URI.createFileURI("C:/Vishnu/Work/runtime-Rule_test/testRule/xsd/CreditCard.xsd",
true);                 if(resource instanceof XSDResourceImpl)
<br>
                {
<br>
                    XSDResourceImpl xsdResource =
(XSDResourceImpl) resource;
<br>
                    // The contents of the resource is the root
XSDSchema object
<br>
                    schemas.add(xsdResource.getSchema());
<br>
                }
<br>
            }catch(Exception e){
<br>
                e.printStackTrace();
<br>
        }
<br>
        return schemas;
<br>
    }
<br>
<br>
<br>
Can someone please help me on this. I am completely new to EMF and
any help in this issue will be helpful.Thank you.
<br>
</blockquote>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Cannot create a resource [message #910368 is a reply to message #910344] Sun, 09 September 2012 12:06 Go to previous message
Vishnu Jakhoria is currently offline Vishnu JakhoriaFriend
Messages: 2
Registered: September 2012
Junior Member
Thank you so much Ed Merks. It worked... Smile
I replaced Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
new XMLResourceFactoryImpl())
; with Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", new XSDResourceFactoryImpl());

Thanks,
Vishnu
Previous Topic:[CDO] Cannot commit UML stereotype instances
Next Topic:Find instances of an EClass
Goto Forum:
  


Current Time: Thu Apr 25 08:21:36 GMT 2024

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

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

Back to the top