Skip to main content



      Home
Home » Modeling » EMF » Resolve eProxy with custom URI
Resolve eProxy with custom URI [message #1738196] Mon, 18 July 2016 01:48 Go to next message
Eclipse UserFriend
Hi guys,

I have a model which is saved as XMI file. This model contains cross references to other resources. The cross references are saved using just the ID of the EObject (one of the property is set as an ID). When the editor is opened I am searching for object with specified ID in all resources which are in current resourceSet and I am changing URI from ID to the default one with path to the resource and ID as fragment. In editor it works ok. But I have problem with Clean/Build. In editor it works because I have used custom resource factory with XMLResource.OPTION_URI_HANDLER for load and save.
But when Clean/Build is called then no load is triggered so my URIs are not mapped. Is there any way to map my URIs before Clean/Build so I can customize them and later they can be easily resolved?

Thanks for help
Re: Resolve eProxy with custom URI [message #1738319 is a reply to message #1738196] Tue, 19 July 2016 00:26 Go to previous messageGo to next message
Eclipse UserFriend
Adam,

Comments below.


On 18.07.2016 22:54, Adam Bialas wrote:
> Hi guys,
>
> I have a model which is saved as XMI file. This model contains cross
> references to other resources. The cross references are saved using
> just the ID of the EObject (one of the property is set as an ID). When
> the editor is opened I am searching for object with specified ID in
> all resources which are in current resourceSet and I am changing URI
> from ID to the default one with path to the resource and ID as
> fragment. In editor it works ok. But I have problem with Clean/Build.
So something is happening during a build. Did you implement a build
participant?
> In editor it works because I have used custom resource factory with
> XMLResource.OPTION_URI_HANDLER for load and save. But when Clean/Build
> is called then no load is triggered so my URIs are not mapped.
I assuming something is loading your resources, but I have no idea what
that might be. EMF itself doesn't do anything during a build.
> Is there any way to map my URIs before Clean/Build so I can customize
> them and later they can be easily resolved?
It sounds like you'd need to customize the builder with the same logic
as you're using in your editor.
>
> Thanks for help
Re: Resolve eProxy with custom URI [message #1738356 is a reply to message #1738319] Tue, 19 July 2016 05:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

No - I do not have implemented my BuilderParticipant. I am using XtextBuilder and it uses XtextResourceSetProvider to get the correct resourceSet instance. It returns SynchronizedXtextResourceSet which initializes URI handler to XtextPlatformResourceURIHandler (in method initializeDefaultLoadOptions()). I wanted to use here my custom URI handler but I cannot inject my own IResourceSetProvider to XtextBuilder.

Adam
Re: Resolve eProxy with custom URI [message #1738366 is a reply to message #1738356] Tue, 19 July 2016 05:58 Go to previous messageGo to next message
Eclipse UserFriend
Adam,

I see. So best would be if the editor itself wasn't customized at all
but that all customized behavior was implemented in the resource itself.

You said "In editor it works because I have used custom resource factory
with XMLResource.OPTION_URI_HANDLER for load and save. But when
Clean/Build is called then no load is triggered so my URIs are not
mapped." Why is this only used in the editor? Or more specifically,
why isn't this option added by your XyzResourceFactoryImpl?


On 19.07.2016 11:14, Adam Bialas wrote:
> Hi Ed,
>
> No - I do not have implemented my BuilderParticipant. I am using
> XtextBuilder and it uses XtextResourceSetProvider to get the correct
> resourceSet instance. It returns SynchronizedXtextResourceSet which
> initializes URI handler to XtextPlatformResourceURIHandler (in method
> initializeDefaultLoadOptions()). I wanted to use here my custom URI
> handler but I cannot inject my own IResourceSetProvider to XtextBuilder.
>
> Adam
Re: Resolve eProxy with custom URI [message #1738371 is a reply to message #1738366] Tue, 19 July 2016 06:15 Go to previous messageGo to next message
Eclipse UserFriend
I have my custom ResourceFactoryImpl and on method createResource(URI uri) I am registering my custom URI handler.

@Override
public Resource createResource(URI uri) {
final XMLResource result = new XMIResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER, new CustomURIHandler(result));
result.getDefaultLoadOptions().put(XMLResource.OPTION_URI_HANDLER, new CustomURIHandler(result));
}

This works perfectly on editor because in editor I am using ResourceSetImp (not XtextResourceSet which is used during clean/build).
But XtextResourceSet overrides my URI handler. That's why I want to provide my custom resourceSetProvider to XtextBuilder but I cannot handle it.

Adam
Re: Resolve eProxy with custom URI [message #1738383 is a reply to message #1738371] Tue, 19 July 2016 07:19 Go to previous messageGo to next message
Eclipse UserFriend
Adam,

You could try specializing the
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(InputStream,
Map<?, ?>) method to force your handler to be used while loading.


On 19.07.2016 12:15, Adam Bialas wrote:
> I have my custom ResourceFactoryImpl and on method createResource(URI
> uri) I am registering my custom URI handler.
>
> @Override
> public Resource createResource(URI uri) {
> final XMLResource result = new XMIResourceImpl(uri);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER, new
> CustomURIHandler(result));
> result.getDefaultLoadOptions().put(XMLResource.OPTION_URI_HANDLER, new
> CustomURIHandler(result));
> }
>
> This works perfectly on editor because in editor I am using
> ResourceSetImp (not XtextResourceSet which is used during clean/build).
> But XtextResourceSet overrides my URI handler. That's why I want to
> provide my custom resourceSetProvider to XtextBuilder but I cannot
> handle it.
>
> Adam
Re: Resolve eProxy with custom URI [message #1738499 is a reply to message #1738383] Wed, 20 July 2016 07:14 Go to previous message
Eclipse UserFriend
Ed,

Your solution works as expected. I have fixed my resource factory and added lines:

 @Override
    public Resource createResource(URI uri) {
        final XMLResource result = new XMIResourceImpl(uri) {
            @Override
            public void load(Map<?, ?> options) throws IOException {
                Map<Object, Object> overridenOptions = new HashMap<>();
                if (options != null) {
                    overridenOptions.putAll(options);
                }
                overridenOptions.put(XMLResource.OPTION_URI_HANDLER, new CustomURIHandler(this));
                super.load(overridenOptions);
            }
            return result;
        };
}


Thank you for your help!

Adam

[Updated on: Wed, 20 July 2016 07:15] by Moderator

Previous Topic:[Xcore] Default value of a DataType
Next Topic:Constraining Cardinality in EMF
Goto Forum:
  


Current Time: Tue Jul 08 11:43:46 EDT 2025

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

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

Back to the top