Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom scheme for import URIs
Custom scheme for import URIs [message #640675] Mon, 22 November 2010 18:54 Go to next message
Michael Zeising is currently offline Michael ZeisingFriend
Messages: 11
Registered: March 2010
Junior Member
Hi there,

I'd like to turn round the import URI mechanism and use a custom URI scheme. Whenever I import a "custom:/a/b/c", I want some CustomHandler to handle the URI and return the Resource.

I've already tried my best and looked through the code but I couldn't find the right hook. Could you give me a hint on that?

Thanks,
Michael
Re: Custom scheme for import URIs [message #640701 is a reply to message #640675] Mon, 22 November 2010 20:43 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Add the URIHandler to ExtensibleURIConverter of your ResourceSet.
Xtext uses an org.eclipse.xtext.ui.resource.IResourceSetProvider to
obtain a resource set.
Note that you cannot easily change the resource set used in the index.

Sven

Am 11/22/10 7:54 PM, schrieb Michael Zeising:
> Hi there,
>
> I'd like to turn round the import URI mechanism and use a custom URI
> scheme. Whenever I import a "custom:/a/b/c", I want some CustomHandler
> to handle the URI and return the Resource.
>
> I've already tried my best and looked through the code but I couldn't
> find the right hook. Could you give me a hint on that?
>
> Thanks,
> Michael


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Custom scheme for import URIs [message #640790 is a reply to message #640701] Tue, 23 November 2010 08:03 Go to previous messageGo to next message
Michael Zeising is currently offline Michael ZeisingFriend
Messages: 11
Registered: March 2010
Junior Member
Is there a simpler way of registering my URIHandler than to extend the XtextResourceSet, override getURIConverter() and adding my handler to the ExtensibleURIConverterImpl? This seams quite intrusive to me Confused
Re: Custom scheme for import URIs [message #640822 is a reply to message #640790] Tue, 23 November 2010 09:53 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 11/23/10 9:03 AM, schrieb Michael Zeising:
> Is there a simpler way of registering my URIHandler than to extend the
> XtextResourceSet, override getURIConverter() and adding my handler to
> the ExtensibleURIConverterImpl? This seams quite intrusive to me :?

Yes:

((ExtensibleURIConverterImpl)resourceSet.getURIConverter()). getContentHandlers().add(myhandler)

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Custom scheme for import URIs [message #640930 is a reply to message #640822] Tue, 23 November 2010 15:21 Go to previous messageGo to next message
Michael Zeising is currently offline Michael ZeisingFriend
Messages: 11
Registered: March 2010
Junior Member
Okay, but for this I need to hook into the ResourceSet creation, right?

As far as I can see, I may only register a custom IResourceSetProvider in the UI project. I've tried it and called
((ExtensibleURIConverterImpl) resourceSet.getURIConverter()).getURIHandlers().add(uriHandler)
in IResourceSetProvider#get - with no effect Sad

Apart from that I'm pretty sure that the non-UI project also needs to create ResourceSets and needs the URIHandler (in standalone mode, e. g.). So isn't there a central place where I can hook my URIHandler?

Thanks in advance!
Re: Custom scheme for import URIs [message #641002 is a reply to message #640930] Tue, 23 November 2010 19:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31961
Registered: July 2009
Senior Member
Note that casting to ExtensibleURIConverterImpl is unnecessary given
that getURIHandlers is a method on URIConverter.

Michael Zeising wrote:
> Okay, but for this I need to hook into the ResourceSet creation, right?
> As far as I can see, I may only register a custom IResourceSetProvider
> in the UI project. I've tried it and called
> ((ExtensibleURIConverterImpl)
> resourceSet.getURIConverter()).getURIHandlers().add(uriHandl er) in
> IResourceSetProvider#get - with no effect :(
> Apart from that I'm pretty sure that the non-UI project also needs to
> create ResourceSets and needs the URIHandler (in standalone mode, e.
> g.). So isn't there a central place where I can hook my URIHandler?
>
> Thanks in advance!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom scheme for import URIs [message #1836412 is a reply to message #640930] Sat, 02 January 2021 23:16 Go to previous message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 105
Registered: July 2009
Location: New York City, NY
Senior Member
It's doubtful that this is of any help to the original poster more than a decade later, but for anybody who might be struggling with the same problem (like myself), I'd like to add this little tidbit:

In my particular circumstances, just using
resourceSet.getURIConverter().getURIHandlers().add(uriHandler)

did also not have any effect, mainly because the new URIHandler will be added at the very end of the list, and the default list in URIHandler.DEFAULT_HANDLERS already contains a "catch all" handler:
  List<URIHandler> DEFAULT_HANDLERS = 
    Collections.unmodifiableList
      (Arrays.asList
         (new URIHandler [] 
          { 
            new PlatformResourceURIHandlerImpl(), 
            new FileURIHandlerImpl(), 
            new EFSURIHandlerImpl(), 
            new ArchiveURIHandlerImpl(), 
            new URIHandlerImpl()
          }));

The canHandle(...) method of that last new URIHandlerImpl() entry looks like this:
  public boolean canHandle(URI uri)
  {
    return true;
  }

so it will intercept all URI handling before any other handlers that come after it.
Therefore, the solution, in my case at least, was to add the new handler at the beginning of the list (or at least somewhere before that final "catch all" handler):
resourceSet.getURIConverter().getURIHandlers().add(0, uriHandler)


Previous Topic:Incremental updates on editor models
Next Topic:Nested project: Dsl files compiled twice
Goto Forum:
  


Current Time: Fri Jul 30 05:27:54 GMT 2021

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

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

Back to the top