Using Meta-code Generation to Realize Higher-order Model
Transformations
Thomas Buchmann and Felix Schw
¨
agerl
Chair of Applied Computer Science I, University of Bayreuth, Universitaetsstrasse 30, 95440 Bayreuth, Bayreuth, Germany
Keywords:
Model-driven Development, M2M Transformations, Model Transformations, Higher-order Transformations,
Software Product Lines.
Abstract:
Model-driven engineering is a wide-spread paradigm in modern software engineering. During the last couple
of years, many tools and languages have been developed, which are especially designed for model transfor-
mations a discipline which is needed in many model-driven engineering approaches. While most of the
existing model-to-model tools and languages are tailored towards batch transformations for specific model in-
stances, they lack support for generic transformation problems, where the metamodel is unknown beforehand.
In this paper we present a two-step meta-code generation approach that derives a metamodel-specific model-
to-model transformation from a model-to-text transformation. The approach has been successfully applied to
the problem of product derivation in model-driven software product lines.
1 INTRODUCTION
Model-driven engineering (MDE) is a wide-spread
paradigm in modern software engineering. It puts
strong emphasis on the development of higher-level
models rather than on source code. Many MDE dis-
ciplines are supported by model transformations. A
wide range of languages and tools have been devel-
oped (Czarnecki and Helsen, 2006), including e.g.
QVT (OMG, 2011) and ATL (Jouault et al., 2008) for
model-to-model transformations (M2M) or the MOF
model-to-text standard (OMG, 2008) for model-to-
text transformations (M2T). At present, the technol-
ogy for defining and executing unidirectional batch
transformations seems to be well-developed.
Usually the metamodels for which a model trans-
formation is written are known beforehand. As classi-
fied in (Mens and van Gorp, 2006), model transforma-
tions can be exogenous, i.e. source and target models
are instances of different metamodels, or endogenous,
i.e. both models conform to the same metamodel. The
terms in-place and out-place refer to transformations
which do or do not modify the source model.
While common approaches work fairly well for
fixed metamodels, they lack support for mechanisms
such as reflection, which could be used in cases where
only the meta-metamodel is known during develop-
ment time. Only recently, the concept of higher-order
transformations (HOT) has been introduced as a pos-
sible compensation for that lack: A HOT is a transfor-
mation that produces or modifies another executable
transformation. Unfortunately, there is no mature tool
support for higher-order transformations yet.
In this paper, we present a two-step meta-code
generation approach to compensate that lack. We use
an Acceleo
1
model-to-text transformation to generate
ATL
2
code for an endogenous out-place model trans-
formation at runtime. We apply our approach to a spe-
cific problem scenario the derivation of products
in model-driven software product lines. Nevertheless,
the approach can be transferred to many other com-
mon MDE problems.
2 PROBLEM DESCRIPTION
One area of our research is dedicated to model-
driven software product line engineering (SPLE).
SPLE (Clements and Northrop, 2001) addresses the
organized reuse of software artifacts. Feature models
(Kang et al., 1990) are used to capture the common-
alities and differences of members of a product line,
while feature configurations describe the characteris-
1
http://www.eclipse.org/acceleo; An implemen-
tation of the OMG standard model to text; (OMG, 2008)
2
http://www.eclipse.org/atl; A model-to-model
transformation language for EMF (Jouault et al., 2008)
536
Buchmann T. and Schwägerl F..
Using Meta-code Generation to Realize Higher-order Model Transformations.
DOI: 10.5220/0004522305360541
In Proceedings of the 8th International Joint Conference on Software Technologies (ICSOFT-PT-2013), pages 536-541
ISBN: 978-989-8565-68-6
Copyright
c
2013 SCITEPRESS (Science and Technology Publications, Lda.)
Feature Model
Multi-variant
Domain Model
Feature
Configuration
Configured Domain
Model
refers to
assigns
F2DMM
Mapping
Model
Mapping
conforms to
Selection
State
Object
Feature
refers to
refers to
derive
feature
expression
subset of
Domain Metamodel
0..*
0..*
0..*
1
instance of
instance of
Ecore
instance of
instance of
Figure 1: Conceptual overview on the FAMILE toolchain.
tics of a specific member thereof. Software product
line engineering is divided into two levels. (1) Do-
main engineering is used to analyze the domain and
capture the commonalities and variabilities in a fea-
ture model. Furthermore, the features are realized in a
corresponding implementation. In model-driven soft-
ware product lines, models represent the implementa-
tion at a higher level of abstraction. (2) Application
engineering deals with binding the variability defined
in the feature model and deriving concrete products.
In SPLE, basically two different approaches ex-
ist to realize variability in the corresponding feature
implementation: (1) In approaches based on positive
variability, product-specific artifacts are built around
a common core. During application engineering,
composition techniques are used to assemble the final
product using these artifacts. (2) In approaches based
on negative variability, a superimposition of all vari-
ants is created. The derivation of products is achieved
by removing all fragments of artifacts implementing
features which are not contained in the specific fea-
ture configuration for the desired product.
Several approaches exist to associate elements
of the feature model with artifacts part of the do-
main model; in previous publications (Buchmann and
Schw
¨
agerl, 2012) we presented FAMILE, an EMF-
based toolchain for model-driven software product
line development using negative variability. Figure 1
depicts the different models involved in FAMILE.
The left part shows the feature model and correspond-
ing configurations. The right part of the figure de-
picts the multi-variant domain model the superim-
position which contains the implementation of all
features described in the feature model. As stated
above, FAMILE uses negative variability, i.e. the do-
main model is the superimposition of all variants. The
central part of Figure 1 depicts the feature-to-domain
mapping model (F2DMM). It is used to map features
declared in the feature model to the corresponding im-
plementation fragments in the domain model. Fea-
ture expressions, which can be arbitrary logical com-
binations of features, are used for that purpose. For a
selected feature configuration, all feature expressions
assigned in the mapping model are evaluated to de-
termine the selection states of mappings. Selection
states are used to include or exclude corresponding
domain model elements in/from a configured domain
model.
Product derivation comprises the creation of a
configured domain model by filtering all domain
model elements which refer to feature expressions
evaluating to false w.r.t a given feature configuration.
It can be regarded as an endogenous out-place (Mens
and van Gorp, 2006) model-to-model transformation:
Source and target model are both instances of the
same meta-model, but the respective instances differ.
In our particular case, the target model is a subset of
the source model, which means that the problem can
be solved by a conditional copying transformation:
only elements mapped to positive selection states (i.e.
active, enforced or surrogated) are copied from the
source to the target model; details see (Buchmann and
Schw
¨
agerl, 2012).
The initial implementation of this transforma-
tion was realized by a hand-written model-to-
model transformation specified in Java. The
transformation redefined the EMF copy operation
(EcoreUtil.copy(EObject)) which uses the reflec-
tive EMF layer to instantiate the copied object from
the respective EClass of its original. Using this
mechanism, the concrete EFactory is called at run-
time to produce an instance of the desired class. Fur-
thermore, its structural features are traversed and also
copied if implied by their respective selection states.
As we encourage the use of model-driven tech-
niques in our research, we strived for a more declara-
UsingMeta-codeGenerationtoRealizeHigher-orderModelTransformations
537
Multi-variant
Domain Model
Configured
Domain Model
F2DMM
Domain Metamodel
instance of
M2T (Acceleo)
instance of
M2M
(ATL)
Feature
Configuration
1
2
conforms to
Figure 2: Transformation steps included in our product derivation process.
tive solution to solve this task. Using a M2M transfor-
mation language like ATL, copying an object of a spe-
cific class could be implemented by a simple transfor-
mation rule including a guard which ensures that the
rule is applied only if the associated mapping has a
positive selection state. The rule itself copies the val-
ues of all structural features. FAMILE and F2DMM
in particular allow the use of any Ecore-based domain
model, but ATL and other model-to-model transfor-
mation languages require the specification of concrete
metamodels. Consequently, this problem can only be
solved by means of a generic M2M transformation.
3 META-CODE GENERATION
If ATL provided native support for generic transfor-
mations, we could write down a single transforma-
tion rule to match all classes C from the domain meta-
model (cf. Listing 1). As stated in Section 2, deriv-
ing concrete products from the multi-variant domain
model can be regarded as a model transformation re-
alizing a conditional copy operation.
Listing 1: Fictional ATL rule augmented with generics and reflection.
1 rule <C ex t e n ds EO bject > Ob je c t 2O b j e ct {
2 fr o m
3 source : C ( so u r c e . i sI n c l ud e d () and
4 source . e C lass = C )
5 to
6 target : C (
7 fo r ( E St r uc t u ra l Fe a t ur e f e atur e :
8 C. e A l l S t r uc t ur a l F e a t u r e s ) {
9 feat u r e <- s o u rce . f e atur e
10 }
11 )
12 }
For our generic transformation rule above, we
augmented the ATL syntax with fictional constructs
based on Java generics and OCL queries for ac-
cessing the metamodel reflectively. The type pa-
rameter C attached to the Object2Object rule
is lower-bounded by the basic EMF Object type
EObject. The guard consists of a conjunction of
two queries: source.eClass = C ensures that no in-
stances of sub-classes of C are matched to the rule
and source.isIncluded() requires that an object’s
associated feature expression evaluates to a positive
selection state. Inside the rule body, the for loop
accesses the reflective EMF layer to iterate over the
structural features of the class bound to the type pa-
rameter at runtime. Please note that in general pur-
pose programming languages like Java or Ada, a
generic type is statically instantiated during compile
time. In our case, the type parameter has to be bound
dynamically depending on the type of the source ob-
ject. Unfortunately such mechanisms do neither exist
in ATL nor in other common M2M languages. In the
following we describe how we applied our two-step
meta-code generation approach (cf. Figure 2) to sim-
ulate such a generic behavior.
In the first step we execute an Acceleo model-to-
text transformation that takes as input the metamodel
of the multi-variant domain model. At runtime, it can
be retrieved from the current F2DMM instance, as
the mapping model stores a reference to the domain
model (cf. Figure 1). Using EMF’s reflective layer,
the meta-class for each EObject and thus the contain-
ing EPackage can be retrieved. Afterwards, the M2T
transformation is run on that EPackage. The template
shown in Figure 3 produces four kinds of ATL code
fragments:
The header (lines 7 to 11): The metamodel iden-
tifier and the namespace URI of the domain meta-
model as well as the module name are produced
by the transformation at runtime, while the cor-
responding information related to the F2DMM
metamodel is fixed.
OCL-helpers (lines 13 to 19). They are pro-
duced for every class contained in the respective
EPackage of the domain metamodel which repre-
sent a root in the inheritance hierarchy. The gener-
ated code is a number of isIncluded()-queries
containing OCL expressions that find the mapping
for an instance of the given class and check if its
ICSOFT2013-8thInternationalJointConferenceonSoftwareTechnologies
538
Figure 3: Cut-out of our M2T transformation which produces a metamodel-specific ATL file.
associated selection state implies its inclusion (ac-
tive, enforced or surrogated) in the configured do-
main model.
Conditional copy rules (lines 21 to 41): For each
concrete class from the input domain metamodel,
a copy transformation rule is produced which uses
the appropriate isIncluded()-query as a guard
and copies instances of that class. Similar to List-
ing 1, the produced rule body will copy the at-
tributes and references of the given object.
In order to avoid the creation of unnecessary
ATL code, we additionally perform a check if at
least one concrete instance of a meta-class is ac-
tually contained in the multi-variant domain model
(isContainedInModelInstance()). Only if this
query evaluates to true, a corresponding transforma-
tion rule is generated. This results in a more compact
and faster ATL transformation.
The output of the first (higher-order) transforma-
tion step is an ATL file that describes a (first-order)
transformation which has both the multi-variant do-
main model and the F2DMM mapping model as in-
put. This transformation produces the configured do-
main model, i.e. the subset of the multi-variant do-
main model which conforms to the selected feature
configuration.
As an example, a cut-out of the generated ATL
module file for the Eclipse UML2 metamodel is
shown in Listing 2. The ATL transformation uses in-
stances of the UML2 as well as the F2DMM meta-
model as input to create a filtered UML model as
output. The conditional copy behavior is realized
as follows: The rule Class2Class is used to create
new Classes in the configured domain model. The
guard source.isIncluded() next to the source pat-
tern makes use of the helper function defined above.
It is only produced for the UML!Element which is the
base class of all metaclasses in the UML package.
Please note that the derivation process is fully au-
tomated and both transformations described in this
section are performed “under the hood”: The user can
invoke the complete meta-code generation with a sin-
gle click. The framework then performs both trans-
formations in order to produce the configured domain
model. Optionally, the user can choose to serialize the
derived ATL transformation which can be reused for
different feature configurations.
UsingMeta-codeGenerationtoRealizeHigher-orderModelTransformations
539
Listing 2: Cut-out of the generated ATL file for the Eclipse UML2
metamodel.
1 m o dule uml2 u m l ;
2 c r eate OUT : UML fr om IN : UML , F2D : F2DMM ;
3
4 h e lper cont e x t UML ! E l e m e n t
5 def : is I nc l u d ed () : Bo o l e a n =
6 Se q u e n ce {# acti ve , # e n forced , # s urr o g a te d }
7 -> in c l u des ( F2DMM ! Ma p pi n g Mo d e l . al l I ns t a nce s
8 -> f i r s t () . g et O b je c t Ma p p i n g ( s e l f )
9 . s e le c t io n S ta t e );
10
11 r u l e C l a ss2 C l as s {
12 fr o m
13 source : UML ! C l a s s ( so u r c e . is In c l u ded ()
14 an d sour c e . oc lI s T y pe O f ( UML ! Clas s ) )
15 to
16 target : UML ! C l a s s (
17 e A n no t a ti o n s < - so u r c e . e An n o ta t i o ns
18 , ow n e d Co m m en t <- s o u rce . o wn e d Co m m e nt
19 , na m e <- so u r ce . name
20 // ...
21 )
22 }
4 RELATED WORK
As stated in Section 1, common model transformation
approaches lack support for higher-order tranforma-
tions. However, there are some experimental exten-
sions available for some of those tools. In this section
we briefly compare them to our approach.
EMF Henshin (Arendt et al., 2010) is a model
transformation tool which allows to specify both en-
dogenous or exogenous model transformations using
a graphical syntax. The tool is based upon the concept
of graph transformations. In (Biermann et al., 2010),
the authors present a solution for an Ecore2GenModel
transformation which also makes use of higher-order
transformations. However, there are significant differ-
ences to our approach. For example, both metamodels
(the Ecore metamodel and the Ecore generator meta-
model) are known when the higher-order transforma-
tion is specified. Furthermore, the higher-order trans-
formation specified in the approach of Biermann et al.
requires the modeler to precisely be familiar with the
abstract syntax of Henshin transformation rules be-
cause the abstract syntax is used to create new trans-
formation rules on the fly. Contrasingly, our approach
makes use of the concrete syntax of ATL.
The authors of (Tisi et al., 2010) present several
proposals to facilitate the definition of HOTs in ATL.
In a survey (Tisi et al., 2009) the authors detected
four usage classes of HOTs in real-world model trans-
formation scenarios. Like in the EMF Henshin ap-
proach, the authors use ATL to dynamically create
new ATL transformation rules which implement the
higher-order behavior. In contrast to our approach,
the abstract syntax of ATL has to be known by the
developer of the HOTs. Furthermore, the metamodel
has to be fixed at the time when the HOT is written.
In (Oldevik and Haugen, 2007) an approach is
presented that also uses HOTs in the field of soft-
ware product lines. It differs from our work pre-
sented in this paper in several ways: First of all, Olde-
vik and Haugen extend MOFScript, a M2T language,
with aspects tailored towards the generation of prod-
uct specific application code from a product line UML
model. We use model-to-text transformations to gen-
erate code for a specific model-to-model transforma-
tion. The variability that Oldevik and Haugen address
in their paper is restricted to variability in the imple-
mentation technique. E.g. they use different mecha-
nisms to implement UML associations in the result-
ing source code. Our approach provides much more
flexibility since we can deal with variability in the do-
main model. In our approach, the variability is bound
when meta-code generation is used to derive a con-
figured domain model (which is then used as a basis
for generating the application source code). Further-
more, our approach can handle any Ecore-based do-
main model and is not limited to UML only.
In (Botterweck et al., 2009), the authors describe
their approach on using HOTs as a variability mecha-
nism for embedded systems. Botterweck et al. also
use HOTs to derive products in a software prod-
uct line. In their approach, they used it on Mat-
lab/Simulink models. The main differences to our ap-
proach are the fact that they (ab)use the M2M trans-
formation tool in order to perform a M2T transfor-
mation. Their higher-order ATL transformation only
consists of queries, which produces one large output
string: the final ATL transformation. Furthermore,
they need a second ATL transformation for which the
helpers generated by the first one are manually over-
loaded. Contrastingly, our approach has a clear sepa-
ration of concerns, as we use a dedicated model-to-
text transformation tool, to generate our ATL rules
corresponding to the respective domain metamodels.
Our approach does not either require any manual
overloading of the generated rules or helpers. Further-
more, the approach of Botterweck et al. needs a post-
processing step after the transformation has been per-
formed, to remove dangling edges. This is not necces-
sary in our approach, since the validity of the config-
ured domain model is ensured by sophisticated mech-
anisms incorporated in our toolchain (Buchmann and
Schw
¨
agerl, 2012).
ICSOFT2013-8thInternationalJointConferenceonSoftwareTechnologies
540
5 CONCLUSION AND FUTURE
WORK
Higher-order transformations have just recently been
addressed in model-driven software development
(Tisi et al., 2010). As a consequence, there is no
sufficient tool support available at the moment. In
our paper, we presented a novel approach to bridge
this gap by a two-step meta-code generation approach
which enables the specification of a higher-order en-
dogenous model transformation that is independent
from the concrete metamodel. Only at runtime, ATL
code is generated for the specific metamodel using an
Acceleo template, and the resulting first-order ATL
transformation is then performed on corresponding
model instances.
We applied our approach to the problem of prod-
uct derivation in model-driven software product lines,
where we could successfully test its correctness by
comparing results to the existing, Java-based solution.
The meta-transformation code we had to write is sig-
nificantly more declarative. Furthermore, the Acceleo
template comprises 124 lines of code, which is about
a third of the original Java source code (370 lines).
For future work, we plan to transfer our approach
to another research project which is dedicated to
three-way merging of models (Westfechtel, 2012) and
has a problem definition similar to the one described
in this paper. The algorithm allows merging of arbi-
trary Ecore model instances. The main differences
are that first, the result is not only obtained by a
conditional copy of one, but three input models, and
second, filtering of artifacts is replaced by dedicated
merge rules.
ACKNOWLEDGEMENTS
The authors want to thank Bernhard Westfechtel for
his valuable comments on the draft of this paper.
REFERENCES
Arendt, T., Biermann, E., Jurack, S., Krause, C., and
Taentzer, G. (2010). Henshin: Advanced concepts
and tools for in-place emf model transformations. In
Proceedings of the 13th International Conference on
Model Driven Engineering Languages and Systems
(MoDELS 2010), LNCS 6394, pages 121–135, Oslo,
Norway.
Biermann, E., Ermel, C., and Jurack, S. (2010). Modeling
the ”Ecore to GenModel” transformation with EMF
Henshin. In Mazanek, S., Rensink, A., and Gorp,
P. V., editors, Proc. Transformation Tool Contest 2010
(TTC’10).
Botterweck, G., Polzer, A., and Kowalewski, S. (2009).
Using higher-order transformations to derive variabil-
ity mechanism for embedded systems. In Ghosh, S.,
editor, MoDELS Workshops, volume 6002 of Lecture
Notes in Computer Science, pages 68–82. Springer.
Buchmann, T. and Schw
¨
agerl, F. (2012). Ensuring well-
formedness of configured domain models in model-
driven product lines based on negative variability. In
Proceedings of the 4th International Workshop on
Feature-Oriented Software Development, FOSD ’12,
pages 37–44, New York, NY, USA. ACM.
Buchmann, T. and Schw
¨
agerl, F. (2012). FAMILE: tool
support for evolving model-driven product lines. In
St
¨
orrle, H., Botterweck, G., Bourdells, M., Kolovos,
D., Paige, R., Roubtsova, E., Rubin, J., and Tolvanen,
J.-P., editors, Joint Proceedings of co-located Events
at the 8th European Conference on Modelling Foun-
dations and Applications, CEUR WS, pages 59–62,
Building 321, DK-2800 Kongens Lyngby. Technical
University of Denmark (DTU).
Clements, P. and Northrop, L. (2001). Software Product
Lines: Practices and Patterns. Boston, MA.
Czarnecki, K. and Helsen, S. (2006). Feature-based sur-
vey of model transformation approaches. IBM Sys-
tems Journal, 45(3):621–645.
Jouault, F., Allilaire, F., B
´
ezivin, J., and Kurtev, I. (2008).
ATL: A model transformation tool. Science of Com-
puter Programming, 72:31–39. Special Issue on Ex-
perimental Software and Toolkits (EST).
Kang, K. C., Cohen, S. G., Hess, J. A., Novak, W. E.,
and Peterson, A. S. (1990). Feature-oriented do-
main analysis (FODA) feasibility study. Technical Re-
port CMU/SEI-90-TR-21, Carnegie-Mellon Univer-
sity, Software Engineering Institute.
Mens, T. and van Gorp, P. (2006). A taxonomy of model
transformation. Electr. Notes Theor. Comput. Sci.,
152:125–142.
Oldevik, J. and Haugen, Ø. (2007). Higher-order transfor-
mations for product lines. In SPLC, pages 243–254.
IEEE Computer Society.
OMG (2008). MOF Model to Text Transformation
Language, Version 1.0. OMG, Needham, MA,
formal/2008-01 edition.
OMG (2011). Meta Object Facility (MOF) 2.0
Query/View/Transformation, v1.1. Object Manage-
ment Group, Needham, MA, formal/2011-01-01 edi-
tion.
Tisi, M., Cabot, J., and Jouault, F. (2010). Improving
higher-order transformations support in ATL. In Tratt,
L. and Gogolla, M., editors, ICMT, volume 6142 of
Lecture Notes in Computer Science, pages 215–229.
Springer.
Tisi, M., Jouault, F., Fraternali, P., Ceri, S., and B
´
ezivin, J.
(2009). On the use of higher-order model transforma-
tions. In Paige, R. F., Hartman, A., and Rensink, A.,
editors, ECMDA-FA, volume 5562 of Lecture Notes in
Computer Science, pages 18–33. Springer.
Westfechtel, B. (2012). Merging of EMF models - formal
foundations. Software and Systems Modeling. Online
First.
UsingMeta-codeGenerationtoRealizeHigher-orderModelTransformations
541