Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » URIConverter and href?
URIConverter and href? [message #430144] Tue, 12 May 2009 11:37 Go to next message
Ingrid is currently offline IngridFriend
Messages: 4
Registered: July 2009
Junior Member
Hi

I have a few questions regarding the URIConverter. I'm new to EMF so I
hope you can understand what I mean.

I have some XML/(XMI?) files containing a bunch of hrefs which demands the
referenced files to be located in the same directory. I want to be able to
translate the URIs in these hrefs into other URIs which the user has
mapped himself using a ProjectMapping model.

We want to let the user map some different types e.g:
config -> path to configurationfiles
test -> path to testfiles

I guess it could look something like this.
href="config:/configfile" -> href="file:/C:/configuration/configfile"
href="test:/testfile" -> href="file:/C:/Development/test/testfile"

Is this possible to do using the URIConverter? Can I map "config:/" to
"file:/C:/configuration/", or do I have to map
"platform:/resource/config/" to "file:/C:/configuration/"?

I tried to create a ResourceSet (for reading the mappings) and an
URIConverter like this when the user maps the data:
---
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMIResourceFactoryImpl());

// Register the package to ensure it is available during loading.
resourceSet.getPackageRegistry().put(ProjectMappingsPackage. eNS_URI,ProjectMappingsPackage.eINSTANCE);
uriConverter = new ExtensibleURIConverterImpl();
resourceSet.setURIConverter(uriConverter);
---
uri1 = URI.createURI("platform:/resource/" + mapping.getName() + "/");
uri2 = URI.createFileURI(mapping.getPath() + "/");
uriConverter.getURIMap().put(uri1, uri2);
URI testURI = URI.createURI("platform:/resource/config/configfile");
System.out.println("TestURI: " + testURI.toString());
System.out.println("Normalized URI: " + uriConverter.normalize(testURI));


When I test this with normalize in the code, it works. But how do I get
this to work for the XML-files? Can I get some kind of global ResourceSet
where I set the URIConverter so that the framework can find the mappings
when reading the XML-files?

The setting of the URIConverter on the ResourceSet above doesn't do it
anyway.

Thanks for any help.
/Ingrid Berggren
Re: URIConverter and href? [message #430155 is a reply to message #430144] Tue, 12 May 2009 14:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080008000504040903020303
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Ingrid,

Comments below.

Ingrid wrote:
> Hi
>
> I have a few questions regarding the URIConverter. I'm new to EMF so I
> hope you can understand what I mean.
>
> I have some XML/(XMI?) files containing a bunch of hrefs which demands
> the referenced files to be located in the same directory. I want to be
> able to translate the URIs in these hrefs into other URIs which the
> user has mapped himself using a ProjectMapping model.
Perhaps you'll want to look at this option too:

/**
* A {@link URIHandler} value that will be used to control how
URIs are {@link URI#resolve(URI) resolved} during load
* and {@link URI#deresolve(URI) deresolved} during save.
* @see URI
* @see URIHandler
* @see XMLHelper#resolve(URI, URI)
* @see XMLHelper#deresolve(URI)
* @see URIHandlerImpl
*/
String OPTION_URI_HANDLER = "URI_HANDLER";

>
> We want to let the user map some different types e.g:
> config -> path to configurationfiles
> test -> path to testfiles
>
> I guess it could look something like this.
> href="config:/configfile" -> href="file:/C:/configuration/configfile"
> href="test:/testfile" -> href="file:/C:/Development/test/testfile"
>
> Is this possible to do using the URIConverter? Can I map "config:/" to
> "file:/C:/configuration/", or do I have to map
> "platform:/resource/config/" to "file:/C:/configuration/"?
It looks like former should do the trick.
>
> I tried to create a ResourceSet (for reading the mappings) and an
> URIConverter like this when the user maps the data:
> ---
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,new
> XMIResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> resourceSet.getPackageRegistry().put(ProjectMappingsPackage. eNS_URI,ProjectMappingsPackage.eINSTANCE);
>
> uriConverter = new ExtensibleURIConverterImpl();
> resourceSet.setURIConverter(uriConverter);
The resource set already has a URI converter so this part is redundant.
> ---
> uri1 = URI.createURI("platform:/resource/" + mapping.getName() + "/");
> uri2 = URI.createFileURI(mapping.getPath() + "/");
> uriConverter.getURIMap().put(uri1, uri2);
> URI testURI = URI.createURI("platform:/resource/config/configfile");
> System.out.println("TestURI: " + testURI.toString());
> System.out.println("Normalized URI: " + uriConverter.normalize(testURI));
>
>
> When I test this with normalize in the code, it works. But how do I
> get this to work for the XML-files?
Keep in mind that relative URIs are resolved long before the URI
converter seems them. The option I pointed out above can be used to
control the resolution process during load as well as the deresolution
process during save.
> Can I get some kind of global ResourceSet where I set the URIConverter
> so that the framework can find the mappings when reading the XML-files?
Yes there is a global URI map. You should use the extension point to
populate that, not change it programmatically.
>
> The setting of the URIConverter on the ResourceSet above doesn't do it
> anyway.
Monitor closely what actual URIs are passed to the URI converter keeping
in mind my comment about the fact that relative URIs are resolved
syntactically during loading long before the URI converter is used to
map them.
>
> Thanks for any help.
> /Ingrid Berggren
>

--------------080008000504040903020303
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ingrid,<br>
<br>
Comments below.<br>
<br>
Ingrid wrote:
<blockquote
cite="mid:de32d70790dc156f32bf8b493dbb2eeb$1@www.eclipse.org"
type="cite">Hi
<br>
<br>
I have a few questions regarding the URIConverter. I'm new to EMF so I
hope you can understand what I mean.
<br>
<br>
I have some XML/(XMI?) files containing a bunch of hrefs which demands
the referenced files to be located in the same directory. I want to be
able to translate the URIs in these hrefs into other URIs which the
user has mapped himself using a ProjectMapping model.
<br>
</blockquote>
Perhaps you'll want to look at this option too:<small><br>
</small>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: URIConverter and href? [message #430210 is a reply to message #430155] Wed, 13 May 2009 13:24 Go to previous messageGo to next message
Ingrid is currently offline IngridFriend
Messages: 4
Registered: July 2009
Junior Member
Hi
Thanks for the information.

I checked out the global URIConverter and its extension points, and that
works. However, I need to do this programtatically since different users
have different mappings.

How do you mean that I could use this URIHandler? Should I create an
URIHandler of my own and implement a resolve method that checks if the uri
contains e.g. "config" or "test" and then adds the mapping?

Will this URIHandler be added to the URIConverter?
Maybe you can give me an example of how it is being used?

Thanks
/Ingrid
Re: URIConverter and href? [message #430212 is a reply to message #430210] Wed, 13 May 2009 13:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Ingrid,

Comments below.

Ingrid wrote:
> Hi
> Thanks for the information.
>
> I checked out the global URIConverter and its extension points, and
> that works. However, I need to do this programtatically since
> different users have different mappings.
Don't do it globally then. Different users will have different resource
sets do the registrations in that local resource set.
>
> How do you mean that I could use this URIHandler? Should I create an
> URIHandler of my own and implement a resolve method that checks if the
> uri contains e.g. "config" or "test" and then adds the mapping?
The URI handler load/save option is for doing the syntactic manipulation
for converting relative URIs to absolute URIs on load and for doing the
inverse on save. Use it only if the behavior you're getting by default
isn't what you want.
>
> Will this URIHandler be added to the URIConverter?
What I referred to was an option in XMLResource.
> Maybe you can give me an example of how it is being used?
EcoreResourceFactoryImpl uses that option. You won't need it if your
hrefs are already in a form that makes you happy.
>
> Thanks
> /Ingrid
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: URIConverter and href? [message #430313 is a reply to message #430212] Thu, 14 May 2009 13:33 Go to previous message
Ingrid is currently offline IngridFriend
Messages: 4
Registered: July 2009
Junior Member
Thanks for the help. I found the problem.
It turned out that I was usingh the wrong ResourceSet.

Regards
/Ingrid
Previous Topic:Best way to get root object of a model
Next Topic:Multiple annotations with same source/key with different values
Goto Forum:
  


Current Time: Fri Apr 26 12:50:57 GMT 2024

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

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

Back to the top