Running a model-to-model mapping transformation generates a temporary in-memory model. If the contents of this model are different from the contents of an existing target model in the file system, the models are merged during transformation post-processing. The default merge procedure, which is a transformation rule that is provided in the model-to-model transformation framework, loads the existing target model into memory and uses the structural merging functionality to combine it with the generated in-memory model. The model that results from the structural merge replaces the existing target model.
Models often contain references to objects in other models. For example, a UML model might contain references to stereotypes that are defined in UML profiles or it might contain references to primitive types that are defined in UML libraries. Structural merging detects that these cross-model references reference the same object only if they reference the same in-memory instance of that object.
For example, assume that the «Perspective» stereotype, which is defined in the UML profile named Default, is applied to the package named ExamplePackage in a generated in-memory model, and also to the same package in the existing target model. When the existing target model is loaded into memory for structural merging, the reference to the «Perspective» stereotype is resolved. If the structural merge does not identify the exact same instance of the stereotype object in memory that the generated in-memory model references, the structural merge cannot detect that both versions of the ExamplePackage package have the same stereotype applied to them. By default, the structural merge stops when it detects duplicate instances of the same model, such as the UML Default profile in this example, that are loaded and referenced by the models that are merging.
To avoid duplicate in-memory instances of a model, ensure that the resource set that contains the in-memory models has only one instance of each model.
These rules are located in the package named com.ibm.xtools.transform.authoring. For more information about these rules, see the Rational Transformation Authoring Developer Guide API Reference. The transformation in this sample uses both of these rules. Explore the generated transformation source code to see their instantiation in the sections of the transformation source code that you can customize.
The following code fragments show how to use the rule named UMLDefaultLibrariesAddRule.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private void addTransformElements(Registry registry) {
// You may add more transform element before the generated ones here
// Remember to remove the @generated tag or add NOT to it
addGeneratedTransformElements(registry);
// You may add more transform element after the generated ones here
// Remember to remove the @generated tag or add NOT to it
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
private void addTransformElements(Registry registry) {
add(new UMLDefaultLibrariesAddRule());
// You may add more transform element before the generated ones here
// Remember to remove the @generated tag or add NOT to it
addGeneratedTransformElements(registry);
// You may add more transform element after the generated ones here
// Remember to remove the @generated tag or add NOT to it
}
/**
* Creates a root transformation. You may add more rules to the transformation here
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param transform The root transformation
* @generated
*/
protected RootTransformation createRootTransformation(ITransformationDescriptor descriptor) {
// Create and return an instance of a class that extends RootTransformation
// and handles source objects of type = (resource) and target objects of type = (resource)
// and remove the @generated tag. The default implementation provided here is
// for source and target objects of type = (resource).
return new RootTransformation(descriptor, new MainTransform()){
protected void addPostProcessingRules() {
add(new UMLProfilesConsistencyCheckRule());
super.addPostProcessingRules();
}};
}
/**
* Creates a root transformation. You may add more rules to the transformation here
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param transform The root transformation
* @generated NOT
*/
protected RootTransformation createRootTransformation(ITransformationDescriptor descriptor) {
// Create and return an instance of a class that extends RootTransformation
// and handles source objects of type = (resource) and target objects of type = (resource)
// and remove the @generated tag. The default implementation provided here is
// for source and target objects of type = (resource).
return new RootTransformation(descriptor, new MainTransform()){
protected void addPostProcessingRules() {
add(new CrossModelReferenceCheckRule());
add(new UMLProfilesConsistencyCheckRule());
super.addPostProcessingRules();
}};
}