This restricted form of rule structure enables the simplification, analysis and modularisation of transformation definitions, and the potential partitioning of large input models into separate parts relevant to each sub-transformation.
These are possible signs of a lack of a coherent processing strategy within the transformation, and of excessively complex rules which can hinder comprehension, verification and reuse.
Problems (i), (ii) and (iii) are inter-related: if a rule is attempting to construct target elements at more than one hierarchical level, corresponding to more than one level in the source language, then it will (for example) be navigating from a higher to a lower level and referring to the features of lower-level objects, a double navigation. Alternation of quantifiers arise because such rules express ``For all s : Si, create a t : Tj, and for all s' contained in s create a t' contained in t".
The figure shows a case of the pattern where a transformation relates part of a source language metamodel (on the LHS) to part of a target language metamodel (on the RHS). Source entity type Si is considered higher in the source composition hierarchy structure than SSub, and likewise Tj in the target language is considered higher than TSub. A rule (rule2) at the Si level maps an Si instance satisfying SCond to a Tj instance satisfying TCond, and the rule also navigates down one level to lookup TSub elements previously mapped (by rule1) from SSub elements in order to set the tr feature of the Tj instances.
There are two basic variations on this pattern: (i) Bottom-up Phased Construction builds a target model starting from entities at the base of the composition hierarchy of the target language, then successively builds composite elements using their part elements; (ii) Top-down Phased Construction instead starts from the entities at the top of the target language hierarchy and builds downwards.
The choice of one or other variation depends on the structure of the target model. It is generally desirable to maintain the validity of the target model during the transformation (e.g., to simplify verification and composition of the transformation). This means that where there are mandatory associations T1 *---1 T2 in the target model, construction of T2 instances should precede construction of T1 instances. For T1 *---* T2 associations either order of construction can be chosen, whilst in the case of T1 1..*---* T2 associations, T1 instances should be created before T2 instances.
Phased Construction potentially enables large input models to be split into two or more smaller models, on the basis of the entity type hierarchy of the source language, and for these models to be separately processed, thus reducing memory requirements. This leads to the Phased Model Construction architectural pattern.
A large transformation using the bottom-up version of the Phased Construction pattern is the migration transformation case solution of TTC 2010 in UML-RSDS. The UML to relational mapping is also specified using the top-down version of this pattern in the Viatra manual, using explicit tracing to look up transformed model elements.
The UML to relational database example in QVT-R can be expressed using this pattern by using QVT-R top relations instead of invoked relations (relations which are only executed when invoked from the where clause of another relation):
top relation Package2Schema
{ checkonly domain uml p: Package { name = pn }
enforce domain rdbms s: Schema { name = pn }
}
top relation Class2Table
{ checkonly domain uml c : Class
{ package = p : Package {}, name = cn }
enforce domain rdbms t : Table
{ schema = s : Schema {}, name = cn }
when
{ Package2Schema(p,s); }
// p already mapped to s
}
top relation Attribute2Column
{ checkonly domain uml a : Attribute
{ owner = c : Class {}, name = an }
enforce domain rdbms cl : Column
{ table = t : Table {}, name = an }
when
{ Class2Table(c,t); }
// c already mapped to t
}
Reverse rules for an inverse transformation t~ can be deduced from transformations t in phased construction form.
One motivation for applying the Phased Construction pattern is that it provides improved modularity compared to versions of a transformation without the pattern. In particular, many transformation languages such as QVT-R, ATL and ETL adopt a `recursive descent' style of specification, in which top-level rules apply to the entities at the top of a composition hierarchy in a source language metamodel (such as Packages in the UML to relational database transformation) and these then invoke subordinate rules at successively lower levels of the source language composition hierarchy.
Analysis of the semantics of QVT-R transformations has shown that these typically follow the recursive descent specification style, with top relations invoking non-top relations. Each such invocation may introduce a further implicit alternation of quantifiers. Our observation is that a Phased Construction approach would be a preferable alternative in many cases.