Dealing with model structure changes [message #1778535] |
Fri, 15 December 2017 18:25  |
Eclipse User |
|
|
|
I have an EMF model that I have saved using the built-in XMI serialization. I need to change the name of an attribute in my model. Understandably, when I try to load saved models that were saved in v.1, that old field is dumped. What is the best practice for dealing with model changes so I can grab that old named field and put it in the newly named attribute?
Thanks!
|
|
|
Re: Dealing with model structure changes [message #1778536 is a reply to message #1778535] |
Sat, 16 December 2017 01:01  |
Eclipse User |
|
|
|
Perhaps better would have been if you made the old attribute transient volatile and derived and implemented the getter and setter to delegate to the new getter and setter, perhaps suppressing the getter and setter from the public interface (using an annotation as created by org.eclipse.emf.ecore.util.EcoreUtil.setSuppressedVisibility(EStructuralFeature, int, boolean)). You could use the org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA option in your resource factory implementing a derived subclass of org.eclipse.emf.ecore.util.BasicExtendedMetaData.BasicExtendedMetaData(Registry) that specializes org.eclipse.emf.ecore.util.BasicExtendedMetaData.getLocalAttribute(EClass, String, String) so that for the old attribute name it returns the new EAttribute that replaces it. Note also that the option org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE is generally useful for supporting both forward and backward compatibility. It would allow an older runtime to read a newer serialization, ignoring but recording things that are recognized, and writing them back out again on serialization. Post processing that information, perhaps with a org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RESOURCE_HANDLER, would also allow you to transfer the value of the old recorded attribute's value to the new attribute, and removing it from the recorded information so it's not serialized.
|
|
|
Powered by
FUDForum. Page generated in 0.04204 seconds