Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Create additional resource on file open
Create additional resource on file open [message #1002250] Fri, 18 January 2013 03:48 Go to next message
Alex G is currently offline Alex G
Messages: 96
Registered: January 2012
Member
Hi!

If I open some model file with the Reflective Ecore Editor the EcoreEditor.createModelGen() creates a resource with some ResourceFactory and adds it to some ResourceSet.

I want to create an additional dummy resource
* by adding a segment to the uri of the file resource
and add it to the same resourceset (as above)
* while opening the file and
* without overwriting EcoreEditor (it shall be independent of the editor used).

For this reason I have overwritten the ResourceFactory and created there the appropriate dummy resource. Now I don't know how to add this resource to the resourceset in the factory. Or is there some better approach?

public Resource createResource(URI uri) {
	Resource resource = super.createResource(uri);
	
	// creating a dummy resource
	dummyURI = uri.appendSegment("dummy");
	dummyResource = super.createResource(dummyURI);
	
	System.out.println("dummyresource = " + getDummyResource()); // not null
	System.out.println("resource.getResourceSet() = " + resource.getResourceSet()); // this is null, since the resource has not beed added so far to the resourceset
	
	// dummyResource = resource.getResourceSet().createResource(dummyURI);
	return resource;
}

URI dummyURI;
Resource dummyResource;

public URI getDummyURI() {
	return dummyURI;
}

public Resource getDummyResource() {
	return dummyResource; // this becomes null, if called later (after file has been loaded)
}


There is an equivalent post on the TMF forum, but I think its more EMF-specific, therefore I apologize for this doubled post.
http://www.eclipse.org/forums/index.php/t/449552/



Best regards,
Alex.
Re: Create additional resource on file open [message #1002270 is a reply to message #1002250] Fri, 18 January 2013 04:39 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25746
Registered: July 2009
Senior Member
Alex,

Comments below.

On 18/01/2013 9:48 AM, Alex G wrote:
> Hi!
>
> If I open some model file with the Reflective Ecore Editor the
> EcoreEditor.createModelGen() creates a resource with some
> ResourceFactory and adds it to some ResourceSet.
>
> I want to create an additional dummy resource
> * by adding a segment to the uri of the file resource
> and add it to the same resourceset (as above)
> * while opening the file and
> * without overwriting EcoreEditor (it shall be independent of the
> editor used).
>
> For this reason I have overwritten the ResourceFactory and created
> there the appropriate dummy resource. Now I don't know how to add this
> resource to the resourceset in the factory. Or is there some better
> approach?
That doesn't really should like a good approach... The resource factory
doesn't know where the resource will be used.
>
>
> public Resource createResource(URI uri) {
> Resource resource = super.createResource(uri);
>
> // creating a dummy resource
> dummyURI = uri.appendSegment("dummy");
> dummyResource = super.createResource(dummyURI);
>
> System.out.println("dummyresource = " + getDummyResource()); //
> not null
> System.out.println("resource.getResourceSet() = " +
> resource.getResourceSet()); // this is null, since the resource has
> not beed added so far to the resourceset
>
> // dummyResource =
> resource.getResourceSet().createResource(dummyURI);
> return resource;
> }
>
> URI dummyURI;
> Resource dummyResource;
>
> public URI getDummyURI() {
> return dummyURI;
> }
>
> public Resource getDummyResource() {
> return dummyResource; // this becomes null, if called later (after
> file has been loaded)
> }
>
>
> There is an equivalent post on the TMF forum, but I think its more
> EMF-specific, therefore I apologize for this doubled post.
> http://www.eclipse.org/forums/index.php/t/449552/
In that post you talked about a linking service.

Perhaps it's better to explain the bigger picture of the problem you're
trying to solve, for which you believe something like this is a good
solution. There might be a better approach... E.g., it's probably much
better to infer this "dummy object" as part of the contents of your
Xtext resource. Or it might be better you have some type of library
resource that's loaded from your bundle (much like Xcore has an
XcoreLang.xcore library)...
>
>
>
> Best regards,
> Alex.
Previous Topic:[EMF] Configure code generation to respect existing modelpackage indexes
Next Topic:Enumerator to EEnum navigation
Goto Forum:
  


Current Time: Sat Apr 19 08:52:48 EDT 2014

Powered by FUDForum. Page generated in 0.04152 seconds