Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » File Not Found error on loading calling getResource
File Not Found error on loading calling getResource [message #868167] Tue, 01 May 2012 17:28 Go to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there,
This problem may have a very easy solution and I am just missing it. I have dug around a bit but have not found any pertinent information.

I am getting a FileNotFoundException on trying to load get a resource from a file.
I am using the Graphiti framework to create diagrams. I separate my diagram from my model files. What I am trying to do is gather a collection of diagrams to one of which I will associate a model element.

The stack trace I am getting is:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.io.FileNotFoundException: /egsc_test3/src/diagrams/Test47.diagram (No such file or directory)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at utils.FileUtil.getDiagramFromFile(FileUtil.java:88)
	at utils.FileUtil.getDiagrams(FileUtil.java:32)
	at features.EgsndiagramDrillDownGoalFeature.getDiagrams(EgsndiagramDrillDownGoalFeature.java:60)
	at org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.getLinkedDiagrams(AbstractDrillDownFeature.java:183)
	at org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.canExecute(AbstractDrillDownFeature.java:150)
	at features.EgsndiagramDrillDownGoalFeature.canExecute(EgsndiagramDrillDownGoalFeature.java:42)
	at org.eclipse.graphiti.ui.internal.action.CustomAction.isEnabled(CustomAction.java:51)
	at org.eclipse.jface.action.ActionContributionItem.update(ActionContributionItem.java:946)
	at org.eclipse.jface.action.ActionContributionItem.fill(ActionContributionItem.java:291)
....

Above, /egsc_test3 is the project. Test47.diagram is the diagram file I am trying to load.

The error is derived from this function (On the line marked ERROR FROM HERE):
	private static Diagram getDiagramFromFile(IFile file, ResourceSet resourceSet) {
		// Get the URI of the model file.
		final URI resourceURI = getFileURI(file, resourceSet);

		// Demand load the resource for this file.
		Resource resource;
		try {
			resource = resourceSet.getResource(resourceURI, true); // ERROR FROM HERE
			if (resource != null) {
				// does resource contain a diagram as root object?
				final EList<EObject> contents = resource.getContents();
				for (final EObject object : contents) {
					if (object instanceof Diagram) {
						return (Diagram) object;
					}
				}
			}
		} catch (final WrappedException e) {
			e.printStackTrace();
		}

		return null;
	}


I have tried both loading the model file (which has an extension ".egsn") and the diagram file (extension ".diagram"). Both derive the same result.

The resourceSet that is passed in at that point is empty. (But it is not clear to me that it needs to have any contents.)
The resourceURI contains:
File String: /egsc_test3/src/diagrams/Test47.diagram

The relative path is OK and is derived from searching the project resources, hence the file does exist.

Does anyone have any thoughts on why getResource might be throwing this exception?

Thanks in advance. If I can clarify anything or provide any extra information please feel free to ask.

All my best,
Joe
Re: File Not Found error on loading calling getResource [message #868394 is a reply to message #868167] Tue, 01 May 2012 22:08 Go to previous messageGo to next message
Tim Schaefer is currently offline Tim SchaeferFriend
Messages: 49
Registered: June 2011
Location: Marburg, Germany
Member
Hi,

I suppose your getFileURI method is wrong.
The URI you have doesn't look like a relative uri.
If the resource is in a project in your workspace you need a platform-resource URI.

URI.createPlatformResourceURI(file.getFullPath().toString(), true)

Regards,
Tim
Re: File Not Found error on loading calling getResource [message #868404 is a reply to message #868394] Tue, 01 May 2012 22:32 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thanks Tim.
That did the trick. Sorry it was not an EMF question at all.

Thanks again,
Joe
Re: File Not Found error on loading calling getResource [message #868512 is a reply to message #868167] Wed, 02 May 2012 05:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Josef,<br>
<br>
Comments below.<br>
<br>
On 01/05/2012 7:28 PM, Josef Pohl wrote:
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">Hi
there, This problem may have a very easy solution and I am just
missing it.  I have dug around a bit but have not found any
pertinent information. <br>
I am getting a FileNotFoundException on trying to load get a
resource from a file.
<br>
</blockquote>
No doubt because you're accessing the file system directly and the
file isn't there.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">I
am using the Graphiti framework to create diagrams.  I separate my
diagram from my model files.  What I am trying to do is gather a
collection of diagrams to one of which I will associate a model
element.  <br>
</blockquote>
Most likely you should be using URIs refer to the workspace...<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">The
stack trace I am getting is: <br>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
java.io.FileNotFoundException:
/egsc_test3/src/diagrams/Test47.diagram (No such file or
directory)
<br>
    at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)<br>
    at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)<br>
    at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)<br>
    at utils.FileUtil.getDiagramFromFile(FileUtil.java:88)
<br>
    at utils.FileUtil.getDiagrams(FileUtil.java:32)
<br>
    at
features.EgsndiagramDrillDownGoalFeature.getDiagrams(EgsndiagramDrillDownGoalFeature.java:60)<br>
    at
org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.getLinkedDiagrams(AbstractDrillDownFeature.java:183)<br>
    at
org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.canExecute(AbstractDrillDownFeature.java:150)<br>
    at
features.EgsndiagramDrillDownGoalFeature.canExecute(EgsndiagramDrillDownGoalFeature.java:42)<br>
    at
org.eclipse.graphiti.ui.internal.action.CustomAction.isEnabled(CustomAction.java:51)<br>
    at
org.eclipse.jface.action.ActionContributionItem.update(ActionContributionItem.java:946)<br>
    at
org.eclipse.jface.action.ActionContributionItem.fill(ActionContributionItem.java:291)<br>
...
<br>
<br>
Above, /egsc_test3 is the project.  Test47.diagram is the diagram
file I am trying to load.  <br>
The error is derived from this function (On the line marked ERROR
FROM HERE):
<br>
<br>
    private static Diagram getDiagramFromFile(IFile file,
ResourceSet resourceSet) {
<br>
        // Get the URI of the model file.
<br>
        final URI resourceURI = getFileURI(file, resourceSet);
<br>
</blockquote>
What does getFileURI do?  Anything like this?<br>
<blockquote><a style=""
href="http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_between_an_EMF_Resource_and_an_Eclipse_IFile.3F"><span
class="tocnumber">2.44</span> <span class="toctext">How do I
map between an EMF Resource and an Eclipse IFile?</span></a><br>
</blockquote>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
        // Demand load the resource for this file.
<br>
        Resource resource;
<br>
        try {
<br>
            resource = resourceSet.getResource(resourceURI, true);
// ERROR FROM HERE
<br>
            if (resource != null) {
<br>
                // does resource contain a diagram as root object?
<br>
                final EList&lt;EObject&gt; contents =
resource.getContents();
<br>
                for (final EObject object : contents) {
<br>
                    if (object instanceof Diagram) {
<br>
                        return (Diagram) object;
<br>
                    }
<br>
                }
<br>
            }
<br>
        } catch (final WrappedException e) {
<br>
            e.printStackTrace();
<br>
        }
<br>
<br>
        return null;
<br>
    }
<br>
<br>
<br>
I have tried both loading the model file (which has an extension
".egsn") and the diagram file (extension ".diagram"). Both derive
the same result.  <br>
The resourceSet that is passed in at that point is empty. (But it
is not clear to me that it needs to have any contents.)</blockquote>
It generally starts out empty.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
The resourceURI contains: File String:
/egsc_test3/src/diagrams/Test47.diagram
<br>
</blockquote>
So you're not using platform:/resource/&lt;project-name&gt; as you
should.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
The relative path is OK and is derived from searching the project
resources, hence the file does exist. <br>
</blockquote>
But not at that location in the file system.  You should be sure to
always use an absolute URI, i.e., one with a scheme such as file:,
platform:, or http:<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">Does
anyone have any thoughts on why getResource might be throwing this
exception?
<br>
<br>
Thanks in advance.  If I can clarify anything or provide any extra
information please feel free to ask.
<br>
</blockquote>
I'm sure reading the FAQ link above will clarify the situation.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
All my best,
<br>
Joe
<br>
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: File Not Found error on loading calling getResource [message #869021 is a reply to message #868512] Wed, 02 May 2012 21:29 Go to previous message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thanks for the link Ed. I passed through the FAQ but I guess I was looking for a solution to a different problem. Thanks for clarifying the issue.

Joe
Previous Topic:Problem with org.eclipse.emf.example.databinding.project in juno
Next Topic:Texo: problem with GroupFeatureGroup
Goto Forum:
  


Current Time: Thu Sep 19 10:57:41 GMT 2024

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

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

Back to the top