Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Loading Resource file
Loading Resource file [message #1805856] Thu, 25 April 2019 15:34 Go to next message
Andrius S is currently offline Andrius SFriend
Messages: 1
Registered: April 2019
Junior Member
Hello, we are trying to create a resource from DSL, to run VIATRA query engine and get the matched patterns. We are getting the error: " Cannot create a resource for 'file:/test.mydsl'; a registered resource factory is needed. What is missing?

		File modelPath = new File( "test.mydsl");
	 	URI fileURI = URI.createFileURI(modelPath.getAbsolutePath());
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml", new ResourceFactoryImpl());
	 	Resource r = new ResourceFactoryImpl().createResource(fileURI);
		ResourceSet resourceSet = new ResourceSetImpl();
		r = resourceSet.getResource(fileURI, true);
//		Resource resource = resourceSet.getResource(fileURI, true);
		final StringBuilder results = new StringBuilder();
		if (r != null) {
				ViatraQueryEngine engine = ViatraQueryEngine.on(new EMFScope(r));
				Matcher matcher = Matcher.on(engine);
				Collection<viatra.Assets.Match> matches = matcher.getAllMatches();
				for (IPatternMatch match : matches) {
					results.append(match.prettyPrint()+"; ");
				if(matches.size() == 0) {
					results.append("Empty match set");
				// using a match processor
		} else {
Re: Loading Resource file [message #1805880 is a reply to message #1805856] Fri, 26 April 2019 11:58 Go to previous messageGo to next message
Laurent Fasani is currently offline Laurent FasaniFriend
Messages: 173
Registered: October 2014
Senior Member

First you have to register your file extension:
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(<your file extension>, new XMIResourceFactoryImpl());
You can use XMIResourceFactoryImpl if you don't have your own factory.
In your case <your file extension>= "mydsl"

Then when creating the resource from a ResourceSet, EMF will find the factory from the Registry
So you just have to write the code below

ResourceSetImpl rs = new ResourceSetImpl();
Resource r = rs.createResource(fileURI);


Laurent Fasani - Obeo
Need training or professional services for Sirius?
Re: Loading Resource file [message #1805884 is a reply to message #1805880] Fri, 26 April 2019 12:48 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6840
Registered: July 2009
Senior Member

If *.mydsl is an Xtext DSL you should invoke MyDSLStandaloneSetup.doSetUp() to do the injector-based factory registration.


Ed Willink
Previous Topic:Programmatically exporting image from aird in stand-alone situation
Next Topic:Style customization not working
Goto Forum:

Current Time: Mon Sep 21 13:01:20 GMT 2020

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

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

Back to the top