|
There's an interesting special case if you already have important models, and want to push a property up or down in the hierarchy. At some point in that move, you would either have the same property slot twice in the hierarchy (illegal), or not at all (in which case all instances will lose that property and its value). Here are the details, and how to succesfully carry out this refactoring - from the draft manual of the next version (but applicable to 5.1 and older versions too):
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.
- Select no projects and Login
- Switch to the Type Browser tab
- Repository | Import, and select
propertyRemovedFromSubtype.mxt
- 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.
- 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.
|