While my first post about EMF really should be about how to use it, I believe that any developer should be able to follow the tutorials provided on the Eclipse EMF site quite easily.
So, I've been using EMF for a while, and I had a problem with how the data was peristed using the default XMIResourceFactoryImpl. It's good, it works on saving and on loading, but I needed to pass the XML to another device.
The default implemtentation stores each object as an XML element, but each attribute for the object is an XML attribute.
I can't really disagree with that way of doing things, but it didn't suit my needs.
I found this tutorial ( Persisting EMF Models with WTP ) that describes in detail what I needed to do, but I'd like to break it down into a few points in this post here (more for my own records than anything!).
The tutorial tells you which plugins are required - if it's missing any post a comment to this post and I'll list the plugins I had to use.
- Normally when saving, you use
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); - This default XMLResourceFactoryImpl should get replaced with your own ResourceFactory extending TranslatorResourceFactory
Resource.Factory.Registry.DEFAULT_EXTENSION, new MyResourceFactoryImpl());
The getDoctype method in MyResourceImpl should refer to a root element definition.
Most importantly, you'll need to create a translator that is returned in the getRootTranslator method. This is covered more in the next step.
The example in the tutorial above describes this quite well.
That should cover all you need to know. The Eclipse tutorial linked above really does provide everything you need, this post just condenses it into a few points.
No comments:
Post a Comment