Skip to main content


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 08:48 Go to next message
Alex G is currently offline Alex GFriend
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 09:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
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.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF] Configure code generation to respect existing modelpackage indexes
Next Topic:Enumerator to EEnum navigation
Goto Forum:
  


Current Time: Fri Apr 26 13:48:28 GMT 2024

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

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

Back to the top