Skip to main content



      Home
Home » Modeling » EMF » a registered resource factory is needed" outside the generated editor(a registered resource factory is needed - Will not read ???)
a registered resource factory is needed" outside the generated editor [message #1854061] Fri, 29 July 2022 20:53 Go to next message
Eclipse UserFriend
Here is my snipped of code for my loader as it would not read any file outside of files inside the folder

public class EMFModelLoad {
public RootPIM load(String file) {
// Initialise the model
PIMPackage.eINSTANCE.eClass();

// Register the XMI resource factory for the .website extension
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("PIM", new XMIResourceFactoryImpl());

// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
resSet.setResourceFactoryRegistry(reg);
// resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("PIM", new
// XMLResourceFactoryImpl());
Resource resource = resSet.getResource(URI.createURI(file), true);


RootPIM pimRoot = (RootPIM) resource.getContents().get(0);
// return pimRoot;
return pimRoot;

}

}


------------------------CONSOLE LOG --------------------
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'c:\test\TrainTicket.PIM'; a registered resource factory is needed
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
at EMFModelLoad.load(EMFModelLoad.java:30)
at main.main(main.java:29)
Re: a registered resource factory is needed" outside the generated editor [message #1854105 is a reply to message #1854061] Mon, 01 August 2022 09:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi

(Ed Merks usually answers this one very promptly. Pending his better response...)

URI.createURI is ok for creating a direct naming representation of e.g. an nsURI. It is not often appropriate for an accessible URI.

You probably want createFileURI standalone or createPlatformResourceURI within the IDE.

That said, your configuration and use of the global registry is unusual, but superficially looks ok and shouldn't lead to the message you observe.

If changing createURI makes no difference then it's time for the debugger. Perhaps you are not using the correct level of the global registry.

Regards

Ed Willink
Re: a registered resource factory is needed" outside the generated editor [message #1854115 is a reply to message #1854105] Mon, 01 August 2022 18:38 Go to previous message
Eclipse UserFriend
Thank you for your reply i have fixed the code by using

Resource resource = resSet.getResource(URI.createFileURI(file), true);

This helped so much

Many Thanks
Previous Topic:Fomratting won't work correctly when save xtext resource programmatically AbstractFormatter2
Next Topic:Derived Attributes are validated
Goto Forum:
  


Current Time: Fri Jul 04 20:33:30 EDT 2025

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

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

Back to the top