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());
	 	System.out.println(fileURI);
		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");
				}
				results.append("\n");
				// using a match processor
		} else {
			System.out.println("bleh");
		} 
	} 
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: 182
Registered: October 2014
Senior Member
Hello

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);

Regards
Laurent


Laurent Fasani - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/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: 7655
Registered: July 2009
Senior Member
Hi

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

Regrads

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


Current Time: Sat Apr 20 03:51:49 GMT 2024

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

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

Back to the top