모델에서 모델로 맵핑 변환을 실행하면 임시 메모리 내 모델이 생성됩니다. 이 모델의 컨텐츠가 파일 시스템에 있는 기존 대상 모델의 컨텐츠와 다른 경우 해당 모델은 변환 사후 처리 중에 병합됩니다. 모델에서 모델로 변환 프레임워크에 제공되는 변환 규칙인 기본 병합 프로시저에서는 기존 대상 모델을 메모리에 로드하고 구조적 병합 기능을 사용하여 해당 모델을 생성된 메모리 내 모델과 결합합니다. 구조적 병합의 결과 발생하는 모델은 기존 대상 모델을 대체합니다.
모델에는 다른 모델의 오브젝트에 대한 참조가 포함되어 있을 수 있습니다. 예를 들어, UML 모델에는 UML 프로파일에 정의된 스테레오타입에 대한 참조가 포함되어 있거나 UML 라이브러리에 정의된 기본 유형에 대한 참조가 포함되어 있을 수 있습니다. 구조적 병합에서는 이러한 상호 모델 참조에서는 동일한 오브젝트의 동일한 메모리 내 인스턴스를 참조하는 경우에만 해당 오브젝를 참조한다는 것을 발견합니다.
예를 들어, 기본값이라는 UML 프로파일에 정의된 «Perspective» 스테레오타입이 생성된 메모리 내 모델의 패키지 ExamplePackage와 기존 대상 모델의 동일한 패키지에도 적용된다고 가정하십시오. 기존 대상 모델이 구조적 병합을 위해 메모리에 로드되면 «Perspective» 스테레오타입에 대한 참조가 해석됩니다. 구조적 병합에서는 생성된 메모리 내 모델이 참조하는 메모리에 있는 스테레오타입 오브젝트의 정확하게 동일한 인스턴스를 식별하지 않는 경우 ExamplePackage 패키지의 두 버전 모두에 동일한 스테레오타입이 적용되었음을 발견할 수 없습니다. 기본적으로 구조적 병합은 병합되는 모델에 의해 로드되고 참조되는 동일한 모델(예: 이 예제의 UML 기본값 프로파일)의 중복 인스턴스를 발견하는 경우 중지됩니다.
모델의 중복 메모리 내 인스턴스를 예방하려면 메모리 내 모델이 포함된 자원 세트에 각 모델의 인스턴스가 하나만 포함되어 있는지 확인하십시오.
이러한 규칙은 com.ibm.xtools.transform.authoring 패키지에 있습니다. 이러한 규칙에 대한 자세한 정보는 Rational Transformation Authoring 개발자 안내서 API 참조서를 참조하십시오. 이 샘플의 변환에서는 이러한 규칙을 둘 다 사용합니다. 생성된 변환 소스 코드를 탐색하여 사용자 정의할 수 있는 변환 소스 코드의 섹션에서 이들 규칙의 인스턴스화를 확인하십시오.
다음 코드 단편에는 규칙 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();
}};
}