モデルからモデルへのマッピング変換を実行すると、一時的なメモリー内モデルが生成されます。 このモデルのコンテンツが、ファイル・システム内の既存のターゲット・モデルのコンテンツと異なる場合 、モデルは変換の後処理中にマージされます。モデルからモデルへの変換フレームワークで提供される変換規則 である、デフォルトのマージ手順は、既存のターゲット・モデルをメモリーにロードし、構成マージ機能を使用して、 この既存のターゲット・モデルと生成されたメモリー内モデルとを組み合わせます。構成マージによって マージされたモデルは、既存のターゲット・モデルに置き換わります。
モデルには、多くの場合、他のモデル内のオブジェクトへの参照が含まれています。例えば、 UML モデルには、UML プロファイル内に定義されているステレオタイプへの参照や、 UML ライブラリーに定義されている基本タイプへの参照が含まれている場合があります。構成マージでは、 これらのモデル間参照が、オブジェクトの同じメモリー内インスタンスを参照する場合にのみ、 同じオブジェクトを参照しているとみなします。
例えば、Default という UML プロファイルに定義されている «Perspective» ステレオタイプが、生成 されたメモリー内モデルの ExamplePackage というパッケージおよび既存のターゲット・モデル内の同じパッケ ージに適用されるとします。既存のターゲット・モデルが構成マージのためにメモリーにロードされると、« Perspective» ステレオタイプへの参照が解決されます。構成マージは、メモリー内で、 生成されたメモリー内モデルが参照するステレオタイプ・オブジェクトのまったく同じインスタンスが識別されない 場合には、両方のバージョンの ExamplePackage パッケージに同じステレオタイプが適用されているとみなすことが できません。デフォルトでは、構成マージは、ロードされ、マージ中のモデルに参照される、 同じモデルの重複するインスタンス (この例の UML Default プロファイルなど) を検出した場合、停止します。
モデルのメモリー内インスタンスの重複を回避するには、メモリー内モデルを含むリソース・セットに、各モデ ルのインスタンスが 1 つのみ存在するようにしてください。
これらの規則は、com.ibm.xtools.transform.authoring というパッケージにあります。 これらの規則について詳しくは、 「Rational Transformation Authoring Developer Guide API Reference」を参照してください。このサンプルの変 換では、これらの両方の規則を使用します。生成された変換ソース・コードを検討し、変換ソース・コードのカスタマイズ可能なセクションで、これらの規則のインスタンス化を確認してください。
以下のコード・フラグメントは、 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();
}};
}