Situation
I have an Eclipse RCP application that manages application projects within an EMF model.
These projects are saved by serializing them to the XMI format. Such files can then be loaded back into the model. I use the standard EMF tools (such as Resource) for this.
Due to model refactoring, the following has changed:
- Old model
- EClass
MyClass
with an attributeName
(with capital letter). - XMI:
<MyClass Name="My Class Name 1" ... />
- EClass
vs.
- New model
- EClass
MyClass
inherits fromMyBaseClass
, with attributename
(without capital letter). - EClass
MyClass
no longer hasName
attribute, since EMF does not allow both. This makes sense as it would collide on e.g. the getter methodgetName()
.
- EClass
Problem
How can I load an old XMI project file into my new model?
Up until this problem I was able to either:
- avoid modifying the model
- grow the model to contain both the old and new structures and perform modification after loading the project file: moving information from old to new types, updating references,....
In this case, however, I cannot load the XMI file in the first place: the model misses attribute name
on one hand and does not recognize (and thus ignores) attribute Name
on the other.
Question
What is the correct place to implement this backwards compatibility support?
I assume I should work on the deserialization process or the XML mapping.
Constraints for the solution are:
- New projects (containing
<MyClass name="..." ... />
) must be loaded correctly as well. - Saving (i.e. serializing) a project model should always happen in the new format!