Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to retrieve a specific Resource.Factory from the registry?
How to retrieve a specific Resource.Factory from the registry? [message #521745] Thu, 18 March 2010 16:13 Go to next message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
Hi all,

I have registered my own Resource.Factory for a specific file extension.
I sometimes need to save/load the resource using a stream. I'm currently
doing this:

// Creates a new resource.
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource= resourceSet.createResource(URI.createURI(".aar"));
InputStream stream= ...
resource.load(stream, null);

This works but I was wondering if there was a better solution for
URI.createURI(".aar")? What's the recommended way to retrieve a specific
Resource.Factory from the registry in the case an "explicit" stream is
passed to Resource#save or Resource#load?

Thank you.

Cyril Jaquier
Re: How to retrieve a specific Resource.Factory from the registry? [message #521758 is a reply to message #521745] Thu, 18 March 2010 16:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Cyril,

You could use Resource.Factory.Registry.INSTANCE.createResource, but
you'll still need a URI. The created resource won't be in any resource set.


Cyril Jaquier wrote:
> Hi all,
>
> I have registered my own Resource.Factory for a specific file
> extension. I sometimes need to save/load the resource using a stream.
> I'm currently doing this:
>
> // Creates a new resource.
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource= resourceSet.createResource(URI.createURI(".aar"));
> InputStream stream= ...
> resource.load(stream, null);
>
> This works but I was wondering if there was a better solution for
> URI.createURI(".aar")? What's the recommended way to retrieve a
> specific Resource.Factory from the registry in the case an "explicit"
> stream is passed to Resource#save or Resource#load?
>
> Thank you.
>
> Cyril Jaquier


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to retrieve a specific Resource.Factory from the registry? [message #521787 is a reply to message #521758] Thu, 18 March 2010 12:58 Go to previous messageGo to next message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
Hi Ed,

Thank you for the answer. Comments below.

> You could use Resource.Factory.Registry.INSTANCE.createResource, but
> you'll still need a URI. The created resource won't be in any resource
> set.
>

Yes but is URI.createURI(".bla") where ".bla" is a dummy "file" the
correct way to get the appropriate resource?

In other words, how would you use URI to create a resource that will be
loaded and saved using Resource#load(stream, options) resp.
Resource#save(stream, options)?

Thank you.
Cyril
Re: How to retrieve a specific Resource.Factory from the registry? [message #521790 is a reply to message #521787] Thu, 18 March 2010 18:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Cyril,

Given the factory will be determined based on the file extension of the
URI, you'll definitely need to use a URI with the desired file
extension. It's certainly possible to paw through the extension map
part of the registry, but you might end up pulling out a descriptor for
the factory rather than the actual and then you'll need to put in more
effort to resolve it. So specifying a URI that's as close to a
meaningful location as possible is always a good idea. I suppose the
stream you're loading doesn't contain references to other resources, or
at least not relative references, because if it did, the URI of the
resource into which it's loaded is important for turning the relative
references into the correct absolute references.


Cyril Jaquier wrote:
> Hi Ed,
>
> Thank you for the answer. Comments below.
>
>> You could use Resource.Factory.Registry.INSTANCE.createResource, but
>> you'll still need a URI. The created resource won't be in any
>> resource set.
>>
>
> Yes but is URI.createURI(".bla") where ".bla" is a dummy "file" the
> correct way to get the appropriate resource?
>
> In other words, how would you use URI to create a resource that will
> be loaded and saved using Resource#load(stream, options) resp.
> Resource#save(stream, options)?
>
> Thank you.
> Cyril


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] How to resolve 'adjusted' table and column names
Next Topic:xyzPackageImpl.init() race condition
Goto Forum:
  


Current Time: Thu Apr 18 03:47:24 GMT 2024

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

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

Back to the top