Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] How to get the extension for an EObject/EClass
[EMF] How to get the extension for an EObject/EClass [message #1272585] Tue, 18 March 2014 09:00 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

I am extending the backend of NetXStudio to be able to deal
with a regular XML store. I need to auto-generate the URI's of the
resource files based on the EClass.

So a file URI is produces with "file://path/package_name.extension"


For the extension, I can retrieve the registered extension parts, and
get a map with this.

Registry instance = Resource.Factory.Registry.INSTANCE;

Map<String, Object> extensionToFactoryMap = instance
.getExtensionToFactoryMap();

But how do I know which EClass belongs to this EResourceFactory?
Is there a link between the EPackage of the EClass and the corresponding
EResourceFactory?

Thanks!

Christophe
Re: [EMF] How to get the extension for an EObject/EClass [message #1272698 is a reply to message #1272585] Tue, 18 March 2014 14:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christophe,

Comments below.

On 18/03/2014 2:00 AM, Christophe Bouhier wrote:
> Hi,
>
> I am extending the backend of NetXStudio to be able to deal
> with a regular XML store. I need to auto-generate the URI's of the
> resource files based on the EClass.
>
> So a file URI is produces with "file://path/package_name.extension"
>
>
> For the extension, I can retrieve the registered extension parts, and
> get a map with this.
>
> Registry instance = Resource.Factory.Registry.INSTANCE;
>
> Map<String, Object> extensionToFactoryMap = instance
> .getExtensionToFactoryMap();
>
> But how do I know which EClass belongs to this EResourceFactory?
No, there isn't really such a general mapping.
> Is there a link between the EPackage of the EClass and the
> corresponding EResourceFactory?
You could generally use "xmi" for any EObject. Even for something like
the Ecore model, tools would generally expect an EPackage to be at the
root of a *.ecore resource but anything else from an Ecore model would
be expected to be nested below an EPackage...

For a generated package, you could use
getEPackageNsURIToGenModelLocationMap to locate the GenModel containing
a GenPackage for the EPackage's nsURI, and from that you can look at
things like
org.eclipse.emf.codegen.ecore.genmodel.GenPackage.getFileExtensions()
and
org.eclipse.emf.codegen.ecore.genmodel.GenPackage.getContentTypeIdentifier().
>
> Thanks!
>
> Christophe


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] How to get the extension for an EObject/EClass [message #1272713 is a reply to message #1272698] Tue, 18 March 2014 15:12 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 18-03-14 15:31, Ed Merks wrote:
> Christophe,
>
> Comments below.
>
Thanks, it's harder than I expected...

> On 18/03/2014 2:00 AM, Christophe Bouhier wrote:
>> Hi,
>>
>> I am extending the backend of NetXStudio to be able to deal
>> with a regular XML store. I need to auto-generate the URI's of the
>> resource files based on the EClass.
>>
>> So a file URI is produces with "file://path/package_name.extension"
>>
>>
>> For the extension, I can retrieve the registered extension parts, and
>> get a map with this.
>>
>> Registry instance = Resource.Factory.Registry.INSTANCE;
>>
>> Map<String, Object> extensionToFactoryMap = instance
>> .getExtensionToFactoryMap();
>>
>> But how do I know which EClass belongs to this EResourceFactory?
> No, there isn't really such a general mapping.
>> Is there a link between the EPackage of the EClass and the
>> corresponding EResourceFactory?
> You could generally use "xmi" for any EObject. Even for something like
> the Ecore model, tools would generally expect an EPackage to be at the
> root of a *.ecore resource but anything else from an Ecore model would
> be expected to be nested below an EPackage...
>
> For a generated package, you could use
> getEPackageNsURIToGenModelLocationMap to locate the GenModel containing
> a GenPackage for the EPackage's nsURI, and from that you can look at
> things like
> org.eclipse.emf.codegen.ecore.genmodel.GenPackage.getFileExtensions()
> and
> org.eclipse.emf.codegen.ecore.genmodel.GenPackage.getContentTypeIdentifier().
>
>>
>> Thanks!
>>
>> Christophe
>
Previous Topic:Eclipse 4.3 Paste holding unwanted transitions
Next Topic:IObservableMap EMF implementation
Goto Forum:
  


Current Time: Fri Apr 19 22:03:16 GMT 2024

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

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

Back to the top