|
Re: Create additional resource on file open [message #1002270 is a reply to message #1002250] |
Fri, 18 January 2013 09:39 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03161 seconds