|
Re: "a registered resource factory is needed" outside the generated editor [message #377407 is a reply to message #377406] |
Thu, 01 May 2003 18:35 |
Eclipse User |
|
|
|
Originally posted by: shu.us.ibm.com
Chris,
You need to register resource factory.
You can use call
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put
to register resource factory.
And this is sample codes for xmi format file which is using
XMIResource interface.
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put
("*", <--- your file extension
new XMIResourceFactoryImpl() <--- the class to resource factory
{
public Resource createResource(URI uri)
{
XMIResource xmiResource = new XMIResourceImpl(uri);
return xmiResource;
}
});
You can provide your own resource factory class and resource class to
handle
your own file (if it is not xmi or xml file).
For more infomation, please refer to EMF users guide, session 3.4.2 and
3.4.3.
Regards,
Shu
Chris Wege wrote:
> I have an EMF model which is running perfectly in the generated editor.
> Now I want to load the model from a file in some code outside of the
> generated editor. I get the exception below. For loading the file I
> perform the steps as in the generated editor (see below).
> How do I register the required resource factory?
> Thanks for any hints,
> Chris
> === code snippet starts here ===
> List factories = new ArrayList();
> factories.add(new ResourceItemProviderAdapterFactory());
> factories.add(new ModelItemProviderAdapterFactory());
> adapterFactory = new ComposedAdapterFactory(factories);
> BasicCommandStack commandStack = new BasicCommandStack();
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack);
> String inputFile = "f:/workspace/eva/Releases13.model";
> Resource resource = editingDomain.loadResource
> (URI.createFileURI(inputFile).toString());
> === code snippet ends here ===
> === console output starts here ===
> java.lang.RuntimeException: Cannot create a resource for
> 'file:/f:/workspace/eva/Releases13.model'; a registered resource factory
> is needed
> at
>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:282)
> at
>
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.load Resource(AdapterFactoryEditingDomain.java:284)
> at eva.fs.tests.AllTests.loadFile(AllTests.java:202)
> at eva.fs.tests.AllTests.buildEd(AllTests.java:162)
> at eva.fs.tests.EvaEditionTest.setUp(EvaEditionTest.java:24)
> at junit.framework.TestCase.runBare(TestCase.java:125)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:386)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:270)
> at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:161)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05713 seconds