Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Custom persistence in EMF(Save ECore metamodels in a custom text file (non XML nor XMI format))
Custom persistence in EMF [message #492960] Thu, 22 October 2009 14:03 Go to next message
Emilio Salazar is currently offline Emilio SalazarFriend
Messages: 9
Registered: October 2009
Junior Member
Hello all,

I'm trying to implement a custom text format persistency for ECore in order to feed an external tool.

This tool will analyze the text file and, probably, change it. Finally, the text file will be reloaded as ECore model (with the applied changes).

The problem is that the text format is not XML nor XMI format, so default implementations provided by EMF are not useful in this case.

I've been playing with Resource, ResourceSet and Resource.Factory, EStore but I haven't been successful.

I would really apreciatte any guidance on the right strategy to use here. Should I specialize Resource, EStore, both, or none of them?.
Any suggestions?

Thanks in advance.
Re: Custom persistence in EMF [message #492971 is a reply to message #492960] Thu, 22 October 2009 14:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Emilio,

Mostly it's a matter of extending ResourceImpl and specializing the
doLoad and doSave methods. For example, BinaryResourceImpl does that to
serialize arbitrary instances in a very fast compact binary format.


Emilio Salazar wrote:
> Hello all,
>
> I'm trying to implement a custom text format persistency for ECore in
> order to feed an external tool.
> This tool will analyze the text file and, probably, change it.
> Finally, the text file will be reloaded as ECore model (with the
> applied changes).
>
> The problem is that the text format is not XML nor XMI format, so
> default implementations provided by EMF are not useful in this case.
>
> I've been playing with Resource, ResourceSet and Resource.Factory,
> EStore but I haven't been successful.
> I would really apreciatte any guidance on the right strategy to use
> here. Should I specialize Resource, EStore, both, or none of them?.
> Any suggestions?
>
> Thanks in advance.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom persistence in EMF [message #492978 is a reply to message #492971] Thu, 22 October 2009 14:56 Go to previous messageGo to next message
Emilio Salazar is currently offline Emilio SalazarFriend
Messages: 9
Registered: October 2009
Junior Member
Thanks Ed for your quick reply.

I was able to figure that out, but what I couldn't do to make EMF use my implementation instead of XMI's ResourceImpl (which is default one).

I belive it's a question of how to register my specialized resource. I've taken a look at my ecore's genmodel generated code, but I wasn't capable of finding the piece of code where the registration takes place (I guess there's a default registration taking place outside the generated code).

How should I make EMF use my implementation of "doSave()"?

Regards,
Emilio.
Re: Custom persistence in EMF [message #492990 is a reply to message #492960] Thu, 22 October 2009 15:29 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Hi Emilio,

You'll have to specialize ResourceImpl. In addition you need to create
your own Resource.Factory and register an instance of that with the
ResourceSet that your application uses.

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Emilio Salazar schrieb:
> Hello all,
>
> I'm trying to implement a custom text format persistency for ECore in
> order to feed an external tool.
> This tool will analyze the text file and, probably, change it.
> Finally, the text file will be reloaded as ECore model (with the
> applied changes).
>
> The problem is that the text format is not XML nor XMI format, so
> default implementations provided by EMF are not useful in this case.
>
> I've been playing with Resource, ResourceSet and Resource.Factory,
> EStore but I haven't been successful.
> I would really apreciatte any guidance on the right strategy to use
> here. Should I specialize Resource, EStore, both, or none of them?.
> Any suggestions?
>
> Thanks in advance.


Re: Custom persistence in EMF [message #492996 is a reply to message #492978] Thu, 22 October 2009 15:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Emilio,

You need to register a resource factory that creates your type of
resource. Look at the generated model for the Library schema tutorial
to see the LibraryResourceFactoryImpl and the registration for it in the
plugin.xml.


Emilio Salazar wrote:
> Thanks Ed for your quick reply.
>
> I was able to figure that out, but what I couldn't do to make EMF use
> my implementation instead of XMI's ResourceImpl (which is default one).
>
> I belive it's a question of how to register my specialized resource.
> I've taken a look at my ecore's genmodel generated code, but I wasn't
> capable of finding the piece of code where the registration takes
> place (I guess there's a default registration taking place outside the
> generated code).
>
> How should I make EMF use my implementation of "doSave()"?
>
> Regards,
> Emilio.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom persistence in EMF [message #493200 is a reply to message #492996] Fri, 23 October 2009 15:16 Go to previous message
Emilio Salazar is currently offline Emilio SalazarFriend
Messages: 9
Registered: October 2009
Junior Member
Thank you very much Ed and Eike,

I finally achieve my propouse. I had an error in the registration of my factory. The problem was that I registered my factory in a 'local' ResourceSet instance instead of in the Resource.Factory.Registry.INSTANCE.

At the end, the code look like this:

MyFactoryImpl myFactory = new MyFactoryImpl();

Resource.Factory.Registry.INSTANCE
.getExtensionToFactoryMap()
.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
myFactory);

instead of

MyFactoryImpl myFactory = new MyFactoryImpl();
ResourceSetImpl myResourceSet = new ResourceSetImpl();

myResourceSet
.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put( Resource.Factory.Registry.DEFAULT_EXTENSION,
myFactory);

I don't know if it's the most elegant way, but it works (planning to change DEFAULT_EXTENSION for my own extension in the future).
I'll check on plugin.xml to do the registration by extension point when I'm ready to export my plugin.


Regards,
Emilio
Previous Topic:How to control the line termintor used by XML resources?
Next Topic:xsi:type in EReference as Featurekind "element" wrong
Goto Forum:
  


Current Time: Fri Sep 20 10:43:34 GMT 2024

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

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

Back to the top