GMF

  1. GMF Troubleshooting
  2. GMF Troubleshooting 2
  3. GMF Troubleshooting 3
  4. GMF Troubleshooting 4
  5. GMF Troubleshooting 5
  6. GMF Troubleshooting 6
  7. GMF Troubleshooting 7
  8. GMF Troubleshooting 8
  9. GMF Troubleshooting 9
  10. GMF Troubleshooting 10

org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.net.MalformedURLException: unknown protocol: c

This exception can appear when trying to create a URI of the wrong type (the ‘c’ is from ‘c:/foo/bar.txt’):

IFile target = project.getFile("bar.txt");
ResourceSet resSet = new ResourceSetImpl();
Resource res = resSet.getResource(URI.createURI(target.getLocation().toString()), true);

The solution is to use createFileURI instead:

Resource res = resSet.getResource(URI.createFileURI(target.getLocation().toString()), true);


Converting from an IFile to an EMF resource in order to load a diagram file programatically

The code is strikingly similar to that above ;)

IFile target = project.getFile("EclipseTestCase.iaml");
ResourceSet resSet = new ResourceSetImpl();
Resource res = resSet.getResource(URI.createPlatformResourceURI(target.getFullPath().toString(), false), true);
IamlDiagramEditorUtil.openDiagram( res );

Note how it needs to use createPlatformResourceURI(): This is because openDiagram() can only load project-relative paths.

You can see this code implemented in the Eclipse IAML plugin. Also see converting a Resource back into an IFile.