Skip to main content



      Home
Home » Eclipse Projects » Sirius » Loading Resource file
Loading Resource file [message #1805856] Thu, 25 April 2019 11:34 Go to next message
Eclipse UserFriend
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 07:58 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Loading Resource file [message #1805884 is a reply to message #1805880] Fri, 26 April 2019 08:48 Go to previous message
Eclipse UserFriend
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: Thu Jul 10 10:18:27 EDT 2025

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

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

Back to the top