Skip to main content



      Home
Home » Modeling » EMF » How to get a Resource in a project
How to get a Resource in a project [message #1062638] Mon, 10 June 2013 04:30 Go to next message
Eclipse UserFriend
Hi all Smile

I have a org.eclipse.core.resources.IProject and I want to get (with a URI) a org.eclipse.emf.ecore.resource.Resource contained into it, how can I do?

I saw that to retrieve a Resource starting from another one there's this method into the utility class EcoreUtil2:

public static Resource getResource(Resource context, String uri)


but what about if I have to start from a project?


Thanks in advance,
Marco
Re: How to get a Resource in a project [message #1062640 is a reply to message #1062638] Mon, 10 June 2013 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Macro,

Comments below.

On 10/06/2013 10:30 AM, Marco Naddeo wrote:
> Hi all :)
>
> I have a org.eclipse.core.resources.IProject and I want to get (with a
> URI) a org.eclipse.emf.ecore.resource.Resource contained into it, how
> can I do?
http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_map_between_an_EMF_Resource_and_an_Eclipse_IFile.3F
>
> I saw that to retrieve a Resource starting from another one there's
> this method into the utility class EcoreUtil2:
>
> public static Resource getResource(Resource context, String uri)
>
> but what about if I have to start from a project?
>
>
> Thanks in advance,
> Marco
Re: How to get a Resource in a project [message #1062658 is a reply to message #1062640] Mon, 10 June 2013 05:46 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your answer Ed, but I need some extra explanation. Smile

I'm using Xtext and in my MyDSLImportUriGlobalScopeProvider, I want to make import URIs relative to the project (not to the current resource).

I get an import URI with this line of code:

String importUriString = getImportUriResolver().apply(object);


import that, as said, is relative to the project root. So, if the project structure is:

MyProject
->MyFolderA
  ->MyFile1.dsl
->MyFolderB
  ->MyFile2.dsl


if I want to import MyFile2.dsl into MyFile1.dsl, I'll write:

import "MyFolderB/MyFile2.dsl"


and so the importUriString will be "MyFolderB/MyFile2.dsl".

If I correctly understood, I have to construct an absolute URI and then use it with the EcoreUtil2 method getResource(Resource, String). Am I right?

I tried something as:

URI importUri = URI.createPlatformResourceURI("/"+projectName+"/"+importUriString, true);
Resource importedResource = EcoreUtil2.getResource(resource, importUriString);


but I obtain a null Resource. Could you please help me to understand where I am wrong?


Marco
Re: How to get a Resource in a project [message #1062667 is a reply to message #1062658] Mon, 10 June 2013 06:08 Go to previous message
Eclipse UserFriend
Marco,

Comments below.

On 10/06/2013 11:46 AM, Marco Naddeo wrote:
> Thanks for your answer Ed, but I need some extra explanation. :)
>
> I'm using Xtext and in my MyDSLImportUriGlobalScopeProvider, I want to
> make import URIs relative to the project (not to the current resource).
That's an Xtext question.
>
> I get an import URI with this line of code:
>
> String importUriString = getImportUriResolver().apply(object);
>
> import that, as said, is relative to the project root. So, if the
> project structure is:
>
>
> MyProject
> ->MyFolderA
> ->MyFile1.dsl
> ->MyFolderB
> ->MyFile2.dsl
>
> if I want to import MyFile2.dsl into MyFile1.dsl, I'll write:
>
> import "MyFolderB/MyFile2.dsl"
>
> and so the importUriString will be "MyFolderB/MyFile2.dsl".
>
> If I correctly understood, I have to construct an absolute URI and
> then use it with the EcoreUtil2 method getResource(Resource, String).
> Am I right?
>
> I tried something as:
>
>
> URI importUri =
> URI.createPlatformResourceURI("/"+projectName+"/"+importUriString, true);
> Resource importedResource = EcoreUtil2.getResource(resource,
> importUriString);
>
>
> but I obtain a null Resource.
These are all Xtext questions, but my impression is that this utility
method wants a relative URI. If you have an absolute URI, you can just
use ResourceSet.getResource (and can obtain the resource set from
resource.getResourceSet()).
> Could you please help me to understand where I am wrong?
>
>
> Marco
>
Previous Topic:[CDO] An history view?
Next Topic:genmodel - root packages problem
Goto Forum:
  


Current Time: Thu Jul 31 02:42:35 EDT 2025

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

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

Back to the top