Show in Frame No Frame
Up Previous Next Title Page Index Contents Search

Moving a property slot to a supertype

8.5.3 Refactoring metamodels with XML

Most refactoring operations on the metamodels can be carried out simply with the existing metamodeling tools. For instance, renaming a type in the Object Tool is sufficient, with no need to manually update other parts of the metamodel that use that type (generators excepted). There are however sometimes specific operations or mass refactorings that would be easier or indeed only possible with XML. These can be accomplished by exporting the metamodel to an MXT file, modifying the file, and re-importing it.

Moving a property slot to a supertype

In the metamodeling tools, deleting a property slot from a subtype and adding it a similar one to the supertype will result in a new property slot, losing any existing values of that property in instances of the subtype. That is no problem when building the metamodel initially (no valuable instances will exist yet), but in the less common case of a major metamodel refactoring with existing models, it is good to have a solution that preserves all values. With careful MXT use, we can push the existing slot up into the supertype and maintain existing property values.

Export the metamodel to an MXT file, and edit it to produce two new files:
*propertyRemovedFromSubtype.mxt, with the property slot cut from the subtype
*propertyAddedToSupertype.mxt, with the property slot pasted to the desired position in the supertype’s list of slots
The slot should include the <slot> tag and all its contents up to and including the closing of the slot tag. It is important that the internal slot id is the same as in the initial file. Normally the property type, typeName and local name should also be unchanged.

Logout and take a backup of your repository, as before any major operation.
1)Select no projects and Login
2)Switch to the Type Browser tab
3)Repository | Import, and select propertyRemovedFromSubtype.mxt
4)This will ask to open a project. Select the project that contains the metamodel, and hold Shift down as you press OK. If you are warned that types are also in another project, hold down Shift as you press OK. Keeping Shift held down avoids loading any models from those projects yet, protecting the existing instances from being updated and hence losing that property value.
5)Repository | Import, and select propertyAddedToSupertype.mxt

You can now look at the models back in the Graph Browser tab, opening and selecting projects as needed, and confirm that the property slot has maintained its values in existing instances of the subtype, and has new default values in instances of the supertype and its other possible subtypes. If all is well, you can commit.



Show in Frame No Frame
Up Previous Next Title Page Index Contents Search