Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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] Sat, 30 July 2022 00:53 Go to next message
Thoybur Rohman is currently offline Thoybur RohmanFriend
Messages: 2
Registered: July 2022
Junior Member
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 13:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 22:38 Go to previous message
Thoybur Rohman is currently offline Thoybur RohmanFriend
Messages: 2
Registered: July 2022
Junior Member
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: Thu Apr 25 15:29:41 GMT 2024

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

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

Back to the top