GReTL: an extensible, operational, graph-based transformation language

  • Published on

  • View

  • Download


  • Softw Syst Model (2014) 13:301321DOI 10.1007/s10270-012-0250-3


    GReTL: an extensible, operational, graph-based transformationlanguage

    Jrgen Ebert Tassilo Horn

    Received: 4 April 2011 / Revised: 6 March 2012 / Accepted: 13 April 2012 / Published online: 8 May 2012 Springer-Verlag 2012

    Abstract This article introduces the graph-based transfor-mation language GReTL. GReTL is operational, and trans-formations are either specified in plain Java using the GReTLAPI or in a simple domain-specific language. GReTL followsthe conception of incrementally constructing the target meta-model together with the target graph. When creating a newmetamodel element, a set-based semantic expression is spec-ified that describes the set of instances that have to be createdin the target graph. This expression is defined as a query onthe source graph. GReTL is a kernel language consisting of aminimal set of operations, but it is designed for being extensi-ble. Custom higher-level operations can be built on top of thekernel operations easily. After a description of the founda-tions of GReTL, its most important elements are introducedalong with a transformation example in the field of metamod-el integration. Insights into the design of the GReTL API aregiven, and a convenience copy operation is implemented todemonstrate GReTLs extensibility.

    Keywords Model transformation Graph transformation Metamodel merging

    1 Introduction

    With the advent of model-driven development (MDD[13]), models and modeling languages have gained

    Communicated by Dr. Andy Schrr and Arend Rensink.

    J. Ebert T. Horn (B)Institute for Software Technology, University Koblenz-Landau,Koblenz, Germanye-mail:

    J. Eberte-mail:

    considerable attention. Models are viewed as the key soft-ware development artifacts which are created, analyzed,refactored, versioned, and maintained like code, the latterbeing just viewed as yet another model.

    Models are written in modeling languages which aredefined by metamodels. They are instances of these meta-models in the sense that models of a given modeling lan-guage have to conform to the languages metamodel in theirabstract syntax.

    Modeling languages are being developed and adapted tooptimally fit to given domains, which lead to lots of domain-specific languages (DSLs [4]), each of which is defined by itsown metamodel, concrete syntax, and semantics. With thisnew trend, the area of metamodel engineering has emerged,which treats metamodels as first class entities and deals withtheir design, refactoring, versioning, and maintenance.

    Several graph and model transformation languages pro-vide a well-established means for transforming models andare widely used for automating transformation chains in thecourse of MDD. Consequently, metamodel engineering gen-erates the need for metamodel transformation languages,which support the transformation of metamodels includingthe migration of their instance models.

    In this paper, we introduce the Graph Repository Transfor-mation Language (GReTL) [5], an operational graph-basedtransformation language that allows the transformation ofa source metamodel to a target metamodel by a sequenceof create-operations, thereby also migrating existing sourceinstances into corresponding target instances. In this respect,GReTL combines metamodeling with model transformation.If the target metamodel already exists, GReTL can also beused to transform only the instances.

    In essence, GReTL is a kernel language defined by a JavaAPI that provides a minimal set of elementary transforma-tion operations for constructing metamodels and conforming


  • 302 J. Ebert, T. Horn

    models in parallel. These API operations are used as transfor-mation objects referencing the relevant context information.Since the corresponding transformation classes follow thecommand pattern [6], they can be manipulated and combinedto higher-level transformations easily. Thus, it is possible andeven encouraged to develop packages of suitable transforma-tions for given (domain-specific) languages by extending andcombining the set of transformation operations provided bythe API. An example of such an extended transformationoperation is illustrated in Sect. 4.3.

    The usage of GReTL as a Java API enables exploita-tion of all Java facilities for the definition and structur-ing of complicated transformation tasks. Thus, Java canbe used to perform extensive intermediate computations toderive powerful comprehensive transformations for largertasks. For simpler cases, also a concrete DSL for notat-ing GReTL transformations is provided, where transforma-tions are composed as sequences of single transformationoperations.

    GReTL was developed for the TGraph technologicalspace [7,8], where typed, attributed, and ordered directedgraphs are used to represent models. In TGraphs, edges arefirst class elements. They are typed and attributed and canbe traversed in both directions. Moreover, there is an orderbetween all vertices and edges in a TGraph, and for each ver-tex, there is a local order between all incident edges. This factentails useful properties of TGraphs and makes them ame-nable for describing global interrelationships between modelelements.

    GReTL is by no means a rule-based graph transformationlanguage with matchreplace semantics. GReTL transforma-tions are usually performed out-place, they are guaranteed toterminate, and running a transformation twice on the samesource model produces identical target models.

    GReTLs conception is to construct a new target metamod-el and thereby specify the target graph in terms of extensions(i.e., instance sets) of the new target metamodels constit-uents. Since GReTL builds on the formally defined graphquery language GReQL [9] for defining these extensions, itis mathematically well founded.

    The usage of GReTL as a transformation language andits capabilities are explained along a typical task from meta-model engineering, namely metamodel merging. Given twodifferent but related domain-specific languages from the tele-communication domain, we show how their metamodels maybe merged into one using GReTL operations, thereby alsofusing corresponding pairs of instances of both languages.Applications like this occur when models developed con-currently by different partners in different DSLs have to bemerged to enable further cooperative work.

    Although GReTL is still under development, the kernelof the language described in this paper can be assumed tobe stable. First experiences with GReTL in a architecture

    migration project1 have shown that the approach is applica-ble in practice for transforming graphs consisting of severalmillions of elements. Furthermore, the live contests of theTransformation Tool Contest (TTC) 20102 and 20113 couldbe won. In 2011, the GReTL solution for the TTC reengi-neering case [10,11] submitted by the second author has won,and GReTL also scored as the second-best solution after thereference solution for the TTC compiler optimization case[12,13]. The solutions can be reproduced online using theexcellent SHARE research cloud [14,15].

    The remainder of this article is organized as follows:Sect. 2 describes the TGraph technical space with its com-positional semantics and gives a first sketch of the con-ception behind GReTL. In Sect. 3, the use of the GReTLDSL is explained along a non-trivial example of mergingtwo domain-specific modeling languages. Section 4 intro-duces the GReTL Java framework and its use, describes theexecution semantics of GReTL, and exemplifies its extensi-bility by defining a custom higher-level transformation oper-ation. Section 5 compares GReTL to other transformationlanguages and Sect. 6 concludes the article.

    2 Foundations

    GReTL is the transformation language of the TGraph techno-logical space [8], where models are represented using a verygeneral and expressive kind of graphs. This section intro-duces the concept of TGraphs, their schemas, and the relationbetween schemas and their corresponding graphs.

    2.1 Overview

    GReTL is defined on typed, attributed, and ordered directedgraphs (TGraphs). In this article, the ordering is ignored.

    A TGraph metamodel (grUML schema) specifies sets ofconforming TGraphs (a graph class) by defining the abstractsyntax of graph instances. grUML (graph UML) is a largesubset of UML class diagrams4 comprising only elementsthat can be given a graph semantics [16].

    Figure 1 depicts a TGraph that conforms to the grUMLschema in Fig. 2. This graph is used as one of the sourcegraphs for the example transformation discussed in Sect. 3.It is the abstract syntax graph of a model written in BEDSL(Fig. 4 on page 307), a domain-specific modeling languagewhich will be explained in more detail, later.

    1 The readers are expected to have basic knowledge about UML classdiagrams.


  • GReTL: extensible, operational, graph-based transformations 303

    Fig. 1 A TGraph conforming to the schema in Fig. 2

    Fig. 2 A schema (source schema) conforming to the metaschema inFig. 3

    In Fig. 1, the TGraph properties (except ordering) areclearly visible. All elements have a type, the edges aredirected, and the vertices are attributed. For example, ver-tex v1 has the type Entity, and its name attribute is setto the string Cisco. It is connected to vertex v5 of typeReferenceAttribute via the edge e3 of type HasAttribute.The name attribute of v5 is set to HasConfig. In this exam-ple, there are no attributes on the edges.

    Figure 2 shows the schema defining the graph classBedslGraph. The vertex types (VertexClasses) are modeledas UML classes, and edge types (EdgeClasses) are mod-eled as associations. The incidences between associationsand classes prescribe the relation between the edge typesand the types of their start and end vertices for instancegraphs. An additional UML class with a stereotype specifies the type of the graph, BedslGraph. Clas-ses and associations may contain attributes specified in theusual UML style, e.g., by using association classes for attrib-uted associations. They prescribe the attribute names andthe value domains for instance elements. Supported attributetypes (Domains) include all common basic types (booleans,

    numbers, strings, etc.), enumerations and records (also spec-ified in the schema), and homogenous collections of arbitraryother domains (lists, sets, maps). Both vertex and edge clas-ses may specialize other vertex or edge classes, respectively.

    2.2 Definitions

    Unordered TGraphs consist of five components: (i) a non-empty finite set V of vertices, (ii) a finite set E of edges,(iii) an incidence function assigning a start and an end ver-tex to each edge, (iv) a type function t ype assigning a typeto each vertex and edge, and (v) an attribute function valueassigning to each vertex and edge a set of attribute-valuepairs (i.e., a finite partial function from attribute identifiersto values), according to the following definition:

    Definition 2.1 (Unordered TGraph) Let

    V ertex be a universe of vertices, Edge be a universe of edges, T ypeI d be a universe of type identifiers, Attr I d be a universe of attribute identifiers, and V alue be a universe of attribute values.

    Then, G =(V, E, , t ype, value) is an unordered TGraph,iff

    (i) V V ertex is a non-empty finite vertex set,(ii) E Edge is a finite edge set,

    (iii) : E V V is an incidence function assigninga start and target vertex to each edge,

    (iv) t ype : V E T ypeI d is a type function, and(v) value : V E (Attr I d V alue) is an attribute

    function, where x, y V E :t ype(x) = t ype(y) dom (value(x)) = dom(value(y)).


  • 304 J. Ebert, T. Horn

    Fig. 3 grUML metaschema, describing all schemas such as in Fig. 2

    2.3 Schemas and their constituents

    The structure of grUML schemas is defined by thegrUML metaschema (Fig. 3), which contains four important,non-abstract constituents5 that define a schema S:(1) VertexClasses, (2) EdgeClasses, (3) Attributes,and (4) specialization hierarchies. Since an EdgeClassuniquely determines two IncidenceClasses and anAttribute uniquely determines a Domain, the latter are sub-sumed as parts of the former. All other elements of the meta-schema are not essential for conforming schemas.

    These four constituents have the following properties:1. A VertexClass has a qualified name and may be

    abstract. With reference to Fig. 2, Entity is a non-abstractVertexClass where the qualifiedName is set to Entity,and Attribute is an abstract VertexClass withqualifiedName Attribute.

    2. An EdgeClass also has a qualified name and may beabstract. It owns exactly two IncidenceClasses holdingthe association end properties (multiplicities, role name,aggregation kind) with respect to the VertexClass it endsat. The aggregation kind may be NONE, SHARED, orCOMPOSITE. In Fig. 2, References is an EdgeClassbetween the vertex classes ReferenceAttribute andEntity where the endpoints are IncidenceClass objectswhose min and max multiplicity and roleName attributesare set accordingly.

    5 Some metaschema elements, e.g., GraphClass, Schema, andPackage, are used for structuring grUML diagrams and are not dis-cussed further in this paper.

    3. An Attribute has a name, an optional default value, andexactly one associated Domain, and it belongs to exactlyone vertex or edge class. In Fig. 2, value is an Attribute ofthe VertexClass with the qualifiedName SimpleAttrib-ute and with name set to value and no defaultValue.

    4. There are two separate (acyclic) specializationhierarchies defined by SpecializesVertexClass andSpecializesEdgeClass. In Fig. 2, the specializationsfrom Attribute to SimpleAttribute and Reference-Attribute are both of type SpecializesVertexClass, andthere are no specializations among edge classes.

    With these constituents, a schema describes the avail-able vertex types (as VertexClasses) and edge types (asEdgeClasses), and for each edge type, the valid start andend vertex types including their association end propertiesare defined. Furthermore, the schema specifies the attributesof all element classes, i.e., vertex or edge classes. The special-ization hierarchies imply (transitive) inheritance of attributesand allowed incidences from superclasses to subclasses.

    The implementation of the TGraph approach (JGraLab)guarantees the conformance of a graph to its schema. Like-wise, the implementation guarantees the conformance of aschema to the grUML metaschema.

    2.4 Defining a graph

    There may be an infinite number of instance graphs con-forming to a given grUML schema S. But, assuming S isthe target schema of a model transformation, one specific


  • GReTL: extensible, operational, graph-based transformations 305

    instance graph has to be created as target graph for a givensource graph.

    To describe such a specific TGraph G conforming to S,all five components (i)(v) of G (according to Def. 2.1) haveto be defined. We do this in a compositional way by definingthe extensions (instance sets) of the four respective schemaconstituents (1)(3) of S respecting (4).

    Let V ertexClass and EdgeClass be the sets of vertexand edge classes defined by a schema S, let subtypes be areflexive function that returns all subclasses for a given class,and let G be any graph conforming to S.

    Then, the extensions in G of the constituents of S are sim-ple mathematical objects, namely sets and functions:

    1. There is a set Vc V for every vertex class c V ertexClass.

    2. There is a set Er E for every edge class r EdgeClass.Assuming that r connects a vertex class c to a ver-tex class c, there is a function r : Er V V ,which assigns a tuple (u, w) to every e Er witht ype(u) subtypes(c) and a t ype(w) subtypes(c).

    3. There is a function valA : csubtypes(c)Vc V aluefor every A Attribute of c V ertexClass EdgeClass.If the attribute A has the domain D and assuming thatD denotes a set TD V alue, valA assigns only valuesfrom TD .

    For example, the extension of the vertex class Reference-Attribute in the graph in Fig. 1 is VRef erenceAttribute ={v5, v7, v12}, the extension of the edge class HasSupertypeis EHasSupertype = {e1, e7, e8, e9, e10}, and the extensionof the value attribute of the SimpleAttribute vertex class isvalSimpleAttribute.value = {v3 1299 EUR}.

    Given these sets and functions, the corresponding TGraphis uniquely determined by G = (V, E, , t ype, value) with

    (i) V =

    cV ertexClass Vc, (i i) E =

    rEdgeClass Er ,

    (i i i) =

    rEdgeClass r , (iv) t ype : V E T ypeI dwith v V : t ype(v) = c v Vce E : t ype(e) = r e Er

    (v) value : V E (Attr I d V alue)with x V E : value(x)(A) = t valA(x) = t

    These definitions are compatible with the model-theoreticsemantics of grUML, since the set of all TGraphs conformingto a schema S equals the set of TGraphs composable fromextensions of the schema constituents [16].

    2.5 Specifying extensions

    Archetypes and images In GReTL, the extensions of vertexclasses, edge classes, and attributes are specified by so-calledsemantic expressions which are assigned to the create-opera-tions of the respective metamodel constituents as parameters,e.g., a vertex class with three vertices may be described bythe expression {1, 2, 3}.

    The semantic expressions define archetype sets for vertexand edge classes. For every member of such a set (an arche-type), a new element is created in the target graph. Thus,every newly created vertex or edge is an image of exactlyone archetype. It has to be stressed that there is no restrictionon what may be chosen as archetype. Although mostly sourcegraph elements are used, archetypes may as well be primi-tive values (numbers, strings) or composite values thereof(tuples, sets, lists). This also enables the use of GReTL tobuild new graphs without any source graph at all.

    More precisely, the semantic expressions define

    1. for each set Vc a set of vertex archetypes v,2. for each set Er a set of triples (e, u, w) denoting an edge

    archetype e together with two vertex archetypes u and wof its start and end vertex,

    3. for each attribute function valA a function assigning avalue t to an archetype x , with the constraints that t has toconform the domain (attribute type) of A, and the imageof x is a target graph element whose type defines orinherits the attribute A.

    Thus, any target graph element is the image of exactly onearchetype.

    Maps During the creation of the images for a target schemaelement class X , two fine-grained functions (img_X fromarchetypes to images and its inverse function arch_X fromimages to archetypes) are constructed implicitly. The func-tions for the element class X also include the mappings ofall functions corresponding to an element class Y , iff Y is aspecialization of X . Therefore, we can also say that an arche-type is an arbitrary object that unambiguously identifies sometarget graph element within its type hierarchy.

    These functions are implemented according to thejava.util.Map interface. These maps may be accessedby other transformation operations in their semantic expres-sions. They may also be persisted to keep the information fortraceability purposes.

    Because the functions img_X and arch_X are viewed asmaps, they are accessed using methods compatible with theMap interface, i.e., containsKey returns true, iff the mapcontains an entry for the specified key, and keySet returns aset view of the keys contained in the map.


  • 306 J. Ebert, T. Horn

    GReQL In GReTL operations, the semantic expressionsare described using the Graph Repository Query LanguageGReQL [9]. GReQL is a sophisticated, dynamically typedgraph query language based on set theory and predicate log-ics, giving access to all TGraph properties and to the schemainformation.

    An important kind of composite expressions in GReQLare from-with-report comprehensions as used in the follow-ing example query:

    1 from e: V{ Entity } , a: V{ Attribute }2 with = "Cisco7603"3 and e >{HasSupertype} >{HasAttribute} a4 reportSet a, end

    This query delivers a set of tuples, where the first compo-nent is an Attribute vertex and the second component is thevalue of that Attributes name. The reported attributes arerestricted to those contained by an Entity named Cisco7603and all its supertypes, i.e., those attributes which are reach-able by traversing a path consisting of an arbitrary numberof HasSupertype edges in forward direction followed byexactly one HasAttribute edge. When run on the sourcegraph of Fig. 1, the query returns the tuples (v3, price),(v5, HasConfig), (v7, HasConfig), and (v12, DoesNot-WorkWith).

    This query also highlights one of GReQLs most power-ful features, namely regular path expressions [9] which allowfor describing complex correlations between vertices usingregular operators (sequences, options, alternatives, and iter-ations). In the example query, the denotes the transitiveclosure with respect to edges of type HasSupertype in theoutgoing direction with respect to the Entity vertex boundto e.

    2.6 Creating the target graph

    The conception of GReTL is to create the new target schemaoperationally, thereby specifying the extensions of eachschema element in order to define the target graph. Forthat purpose, GReTL supplies a set of elementary create-operations, one for each kind of constituent of a grUMLschema:

    (1) CreateVertexClass, (2) CreateEdgeClass, and(3) CreateAttribute.

    These operations create the constituents of the targetschema and their extensions, the latter being given as a set- orfunction-valued GReQL semantic expression, respectively.Besides that, the hierarchy information has to be given byadditional operations:

    (4) AddSuperClass or AddSubClass.For example, to create a new vertex class Property in

    the target schema, with one Property vertex per Attribute

    vertex computed above, one could write the following state-ment using the GReTL DSL:

    1 CreateVertexClass Property2 {HasSupertype} >{HasAttribute} a5 reportSet a end;

    Here, line 1 describes the necessary syntactic parame-ters (the name Property) to create a vertex class accord-ing to Fig. 3, and lines 25 contain the semantic GReQLexpression which has to be evaluated on the graph withalias bedsl.

    Using the Java API, the same effect would be achievedby the creation and execution of a CreateVertexClassobject:1 VertexClass property =2 new CreateVertexClass(context , "Property " ,3 "#bedsl# "4 + "from e: V{ Entity } , a: V{ Attribute } "5 + "with = Cisco7603 "6 + " and e >{HasSupertype} >{HasAttribute} a "7 + "reportSet a end " ) . execute ( ) ;

    Here, the (single) syntactic parameter follows the contextparameter in line 2, and the semantic expression is givenas string as the last parameter in lines 37. Both forms ofoperations, including their parameters and conventions, areintroduced in more detail in the following sections.

    3 GReTL for schema merges

    As stated in Sect. 1, the usage of models in software develop-ment can be considered a standard. During the developmentof a system, a multitude of models are created on differ-ent layers of abstraction and focusing on different aspects.Today, domain-specific modeling languages are widely usedfor code generation purposes and to restrict the available con-cepts to those that are supported by a domain.

    In this section, the elementary GReTL transformationoperations are introduced in the context of a schema merg-ing scenario. Two graphs conforming to two different DSLs(defined by their schemas) are given, and the transforma-tion creates an integrated schema and merges the elementsof these source graphs into one target graph.

    3.1 A schema merge use case

    Comarch6 is a Polish IT company that is specialized in inno-vative solutions for the telecommunication industries anduses different domain-specific modeling languages during



  • GReTL: extensible, operational, graph-based transformations 307

    Fig. 4 The source BEDSL model of Fig. 1 in concrete syntax

    their development process. Two of them will be consideredin a simplified form in this section [17].

    BEDSL The Business Entities Domain-Specific Language(BEDSL) is a platform-independent modeling language,abstracting from any specific technology and focusing onrepresenting business objects, like entities their attributes andrelationships, in a generic manner.

    The description is done on the instance level, but the enti-ties are only placeholders of objects in the context of productmanagement and decision support. A simple BEDSL modelin a concrete syntax is shown in Fig. 4.

    The BEDSL schema describing the abstract syntax hasalready been depicted in Fig. 2 on page 303: An Entity has aname and may have an arbitrary number of Attributes. EachAttribute has a name, and it may either be a SimpleAttributecarrying a value or a ReferenceAttribute referencinganother Entity. At last, an Entity may be specialized, butonly single inheritance is supported. Figure 1 on page 303shows the abstract syntax graph corresponding to the modelof Fig. 4. It is one of the two source graphs used by theexample integration transformation in the following.

    Figure 4 models an Entity Cisco with one subtypeCisco7603. The Cisco entity has a ReferenceAttributeHasConfig. It specifies, that a Cisco entity has a CiscoCon-figuration. Likewise, the entity Cisco7603 has a CiscoCon-figuration7603, which is a subtype of CiscoConfiguration.For the Cisco subtype Cisco7603, its price of 1299 EURis given by the SimpleAttribute price, and an additionalReferenceAttribute states that this entity does not work withHotSwappable CiscoCards. The Entity CiscoCard has threesubtypes: HotSwappable, SPAInterface, and Supervisor.

    PDDSL The other domain-specific language used is thePhysical Device Domain-Specific Language (PDDSL). Itis used to describe possible connections between physicaldevice elements for a concrete customer in the context of con-crete planning of network infrastructures. Here, the descrip-tion is also on the instance level, but concrete sellable devicesare addressed. An example model in a tree-like representa-tion is depicted in Fig. 5.

    The PDDSL schema is shown in Fig. 6.

    Fig. 5 A sample PDDSL model presented as tree

    Fig. 6 The PDDSL schema

    Fig. 7 The PDDSL source graph

    Each PDDSL Element has a name. A Chassis has aConfiguration, which may have one or many Slots. EachSlot contains exactly one Card.

    Figure 7 shows the abstract syntax graph correspondingto the PDDSL model of Fig. 5. In this graph, the ChassisCisco has a Configuration CiscoConfiguration, which hastwo Slots, CiscoSlot and CiscoSlot2. The former has oneCard CiscoCard, and the latter has another card CiscoCard2.

    The two modeling languages describe different aspects ofthe same things on different levels of abstraction. While theBEDSL model describes relationships between business enti-ties in terms of arbitrary reference attributes and allows forarbitrary simple attributes, the PDDSL model specifies howconcrete elements may be plugged together to gain a work-ing configuration. In general, different people with different


  • 308 J. Ebert, T. Horn

    Fig. 8 The target schema the transformation should construct

    technical backgrounds and different viewpoints are respon-sible for creating the models.

    3.1.1 Merging BEDSL and PDDSL

    In the following, we derive a GReTL integration transfor-mation that merges the two schemas and graphs to gather acomplete view on all relevant artifacts of the domain with-out duplicating or losing information. The intention behindthis merging is to achieve an amalgamation of both views,the product management view and the installation planningview.

    A target schema which fulfills this intention is visualizedin Fig. 8. The transformation exemplified in this section willconstruct this target schema on its own. The grUML diagramgiven here for explanation purposes was generated from thetarget schema constructed by the transformation, and not theother way round.

    In the target schema, the PDDSL schema (printed withgray background color) is integrated unchanged, except forleaving out the name attribute of Element which is inher-ited from Entity here. The rationale for this decision is thatPDDSL is the more specific schema, i.e., the different kindsof network devices and their relationships should preferablybe modeled with PDDSL instead of the more lax BEDSL.This also adds the requirement that the transformation shouldidentify entities in the BEDSL graph that actually model net-work devices and represent them using one of the PDDSLtypes in the target graph. In this example, we assume thatentities whose name equals some PDDSL element actuallyrepresent the same thing, but in general, this identificationmay be much more sophisticated.

    The BEDSL models may also contain entities that areunrelated to network devices and cannot be representedappropriately as an instance of Elements subclasses; thus,the Entity vertex class is also present in the target schema.Because entities that the transformation identified as anetwork device, and thus are represented using a sub-class of Element in the target graph, might have taken

    part in HasSupertype relationships or were connected toAttributes, Element must be a specialization of Entity inorder not to lose this information. One could argue that theabstract vertex class Element is not needed and Chassis,Configuration, Slot, and Card should specialize Entitydirectly. This is a justified claim, but by keeping Elementone can distinguish network devices from other entities sim-ply by testing if it is an Element instance.

    3.2 The schema merge transformation

    As described in Sect. 2, the conception of GReTL is to spec-ify the transformations target schema in conjunction withthe extensions of the individual schema element instanceswhich have to be created in the target graph. This meansthat GReTL combines modeling with transformation. Thegeneral guidance to define GReTL transformations is tothink about metamodeling the target domain in terms of aclass diagram. Before an association (i.e., an edge class)can be defined using CreateEdgeClass, its connecting ver-tex classes have to be created using CreateVertexClass.Before adding attributes to the classes and associations usingCreateAttribute, it makes sense to define the type hierar-chies using AddSubClass, because specialized classes andassociations inherit their parents attributes.

    All elementary transformation operations in the schemamerge transformation example are expressed in GReTLssimple DSL. The use of the Java API in order to extend thelanguage with a higher level operation will be discussed inSect. 4.

    Defining the transformation Any transformation starts bydeclaring its name.

    1 transformation BedslPddslMerge;

    Declaring the source graphs The two source graphs areloaded from files, and to each of them a unique alias is


  • GReTL: extensible, operational, graph-based transformations 309

    assigned that can be used throughout the transformation torefer to it.

    2 AddSourceGraph #pddsl# "pddslgraph. tg " ;3 AddSourceGraph #bedsl# "bedslgraph. tg " ;

    Usually, the setting of source graphs is done externally by aGReTLRunner class that provides a convenient commandline interface and allows for batch processing transforma-tions.

    Creating a vertex class and vertices The first class createdis the abstract vertex class Element.

    4 CreateAbstractVertexClass Element;

    Since abstract classes do not have instances, theCreateAbstractVertexClass operation does not have asemantic expression.

    The next operation creates the vertex class Chassis orig-inating from the PDDSL schema.

    5 CreateVertexClass Chassis6

  • 310 J. Ebert, T. Horn

    13 CreateEdgeClass HasConfig14 from Chassis (1 ,1) to Configuration (1 ,1) role config aggregation shared15

  • GReTL: extensible, operational, graph-based transformations 311

    The SimpleAttributes are copied from the BEDSL sourcegraph by creating a target graph SimpleAttribute for anysimple attribute in the source graph and setting the valueattribute according to the archetype values.

    The ReferenceAttribute vertex class including its corre-sponding edge classes are the last parts missing in the mergedschema.

    43 CreateVertexClass ReferenceAttribute44

  • 312 J. Ebert, T. Horn

    Fig. 9 The final target graph

    Fig. 10 Transformations as objects

    we simulated the key concept known from QVT Relations[18] without the need of a new language construct.

    4 GReTL as an extensible language

    As mentioned in the introduction and in Sect. 2.6, GReTL isimplemented as a Java API, which can easily be extended.This section introduces the overall design of the GReTLtransformation framework, describes the runtime executionof GReTL transformations, and presents an example ofGReTLs extensibility.

    4.1 GReTL core design

    The structure of the GReTL transformation framework isdepicted in Fig. 10.

    Transformation is the top-level class of this frameworkproviding a very slim public interface consisting only of themethod execute() for executing a transformation. Addition-ally, it declares an abstract, protected transform() method.This method has to be overridden by concrete subclasseswhere the transformations behavior is to be implemented.The Transformation class is defined with a type parame-ter T, which specifies the return type of its transform() andexecute() methods.


  • GReTL: extensible, operational, graph-based transformations 313

    The elementary transformation operations CreateVertex-Class, CreateEdgeClass, CreateAttribute, and AddSub-Class used in the GReTL DSL example transformationin Sect. 3 are such concrete Transformation subclasses.The operations CreateAbstractVertexClass and AddSub-Classes are not shown here, because they are onlyconvenience operations built on top of CreateVertexClassand AddSubClass, respectively. Furthermore, even Create-VertexClass and CreateEdgeClass are in fact composites:they perform the target schema element constructionthemselves, but create and invoke CreateVertices andCreateEdges transformation objects for the instantiationof vertices and edges in the target graph.

    Every transformation is executed in some Context. Thecontext is an object that keeps track of the transformationsstate, holds the source graphs, and manages the creation ofthe target schema and the target graph. Since all state infor-mation is managed by the transformations Context, a trans-formation itself is stateless.

    To invoke such a transformation, a transformation objectis instantiated and executed using the execute() method. Theconstructor gets as its first parameter the context object, fol-lowed by the schema-relevant (syntactical) parameters andthe instance-relevant semantic expression. As an example,the following statement depicts the creation of the Chassisvertex class and its extension and is completely equivalent tothe lines 5 and 6 of the example transformation in Sect. 3.2.:

    1 VertexClass chassis = new CreateVertexClass(context , "Chassis" ,2 "#pddsl# from c: V{Chassis} reportSet end" ) . execute ( ) ;

    Besides the elementary transformations, also larger com-posite transformations may be implemented directly in Javacode. As an example, the whole transformation describedin Sect. 3 could been implemented by a class extendingTransformation.

    1 public class BedslPddslMerge extends Transformation {2 public BedslPddslMerge(Context c) { super(c ) ; }34 @Override protected Graph transform () {5 VertexClass element = new CreateAbstractVertexClass(context ,6 "Element" ) . execute ( ) ;7 VertexClass chassis = new CreateVertexClass(context , "Chassis" ,8 "#pddsl# from c: V{Chassis} reportSet end" ) . execute ( ) ;9 / / . . .

    10 / / . . . other operation calls follow here . . .11 / / . . .12 return context .getTargetGraph ( ) ;13 }1415 public static void main( String . . . a) {16 Context c = new Context("bedsl_pddsl .MergedSchema" , "MergedGraph" ) ;17 c.addSourceGraph("bedsl " , BedslSchema. instance ( ) . loadGraph(a[0 ] ) ) ;18 c.addSourceGraph("pddsl " , PddslSchema. instance ( ) . loadGraph(a[1 ] ) ) ;19 GraphIO.saveGraphToFile(a[2] , new BedslPddslMerge(c ) .execute ( ) ) ;20 }21 }

    Here, the sequence of operations is specified in thetransform() method (lines 413). The type parameter of the

    Transformation class is set to Graph, and the transform()method returns the target graph.

    For convenience, also a main() method (lines 1520) isshown, which gets the source BEDSL and PDDSL graphfiles as its first and second parameter and the file name forthe target graph as its third parameter. It creates a contextobject, which receives the qualified name of the schema tobe created and that schemas graph class name. Then, the twosource graphs are assigned to the context with their aliases.Finally, an instance of the BedslPddslMerge transforma-tion is created and executed, and the resulting target graph issaved to a file.

    Compared to the GReTL DSL, there are only a fewdifferences:

    1. All transformations are instantiated using the new key-word.

    2. The context is passed explicitly as a parameter.3. The names of the new schema elements and the semantic

    expressions are provided as Java strings.4. The transformations are executed explicitly.

    Note that the composite BedslPddslMerge transforma-tion is technically not different from the elementary trans-formations like CreateVertexClass, because they share thesame interface inherited from Transformation. The differ-ence is only conceptual: BedslPddslMerge performs a com-plete transformation use case with a fixed number of sourcegraphs conforming to fixed schemas and producing a targetgraph conforming to a complete target schema it creates onits own. In contrast, CreateVertexClass performs only onesingle step in such a use case and is completely generic.

    Executing GReTL transformations The GReTL user shouldbe able to specify a transformation in the DSL, Java, or evena mix of both. Therefore, the DSL interpreter can be invokedfrom within a transformation.

    This interpreter for the GReTL DSL (class Execute-Transformation) simply parses the file, instantiates trans-formation objects using reflection, and executes them. Theinterpreter is a transformation itself, which makes it possi-ble to execute transformations from within other transforma-tions, passing the context of the calling transformation to thecalled transformation.

    1 new ExecuteTransformation(context ,2 new File ( "~/My Transforms/Example. gret l " ) ) . execute ( ) ;

    Since all transformation classes of the API are also avail-able in the DSL, the possibility of calling DSL transforma-tions from within other DSL transformation is given as well.

    1 ExecuteTransformation "~/My Transforms/Example. gret l " ;


  • 314 J. Ebert, T. Horn

    For executing a transformation written in the GReTL DSLfrom the command line, a GReTLRunner class exists whichrequires all context information (source graphs, name oftarget schema/graph class) by command line options. Thisallows for executing complex chains of transformations interms of batch processing.

    4.2 Execution semantics

    As already discussed in Sect. 2.6, GReTLs conception is tocreate the target schema incrementally, while specifying theextensions of the new schema elements in order to define thetarget graph. Thus, the execution of GReTL transformationsdistinguishes two phases:

    The first phase (Schema phase) creates the target schemaconstituents.

    The second phase (Graph phase) creates the extensionsof the target schema constituents in the target graph.

    The current phase is encoded in the transformations Contextobject. The transform() method is called twice, once for theSchema phase and the other for the Graph phase. The ele-mentary transformation operations transform() methods actdifferently depending on the current phase.

    In the Schema phase, the elementary transformationscreate the target schema constituents according to the(syntactical) schema information given as their firstparameters. The semantic expressions are not evaluated.After this phase, the target schema is fully defined. Allvertex and edge classes exist, all attributes are assigned totheir classes, and the specialization relationships betweenvertex and edge classes are established.

    The Graph phase starts with generating Java code for thetarget schema created in the previous phase. This gener-ation is initiated by the switch between the phases. Thegenerated code is compiled in memory, and the targetgraph is instantiated as an instance of the graph classspecified by the schema.Then, the elementary transformation operations retrievethe schema element they have created in the Schema phaseby the qualified name provided to all operations as param-eter. The other parameters specifying schema propertiesare ignored. The semantic expressions are evaluated onthe respective source graph, and the creation of verticesand edges and the assignment of attribute values are per-formed.

    This two-phase execution is fully transparent to users ifthe transform() method only contains invocations of elemen-tary transformation operations. If the transform() method ofa composite transformation should also contain other code

    besides pure transformation invocations, it should be con-sidered that the method will be run twice, e.g., expensivecalculations should run only in the phase where the resultof the calculations are needed by checking the value ofcontext.getPhase().

    It should be noted that the Schema phase is skipped if thetarget schema already exists. For example, when transform-ing a set of graphs in a sequence, then only the first executioncreates the target schema and all following executions simplyreuse it.

    4.3 Extension operation: copying vertex classes

    The encapsulation of transformations in transformation clas-ses allows defining composite transformations which deliverhigher level transformation services.

    As an example, imagine a CopyVertexClass operation,which can be used to copy a source schema vertex classinto the target schema, where all attributes defined for thesource vertex class shall be copied as well. At the instancelevel, this operation should create one target graph vertexfor every source graph vertex, using the source vertices asarchetypes.

    This operation allows for replacing one CreateVertex-Class operation call followed by arbitrary manyCreateAttributes operation calls with one single instruction.For example, the sequence of operation calls

    1 CreateVertexClass SimpleAttribute2

  • GReTL: extensible, operational, graph-based transformations 315

    The constructor requires the mandatory context object, thesource vertex class to be copied, and the alias of the sourcegraph which contains the vertex instances to be copied.

    The behavior of the new operation is specified in itstransform() method. The important point here is that weimplement it by composing already existing elementary oper-ations.

    6 @Override protected VertexClass transform () {7 String qname = sourceVC.getQualifiedName ( ) ;8 VertexClass targetVC = new CreateVertexClass(context , qname,9 "#" + alias + "# V{ " + qname + " ! } " ) . execute ( ) ;

    10 for ( Attribute sourceAttr : sourceVC. getOwnAttributeList ( ) ) {11 Domain d = new CopyDomain(context , sourceAttr .getDomain( ) ) . execute ( ) ;12 new CreateAttribute (context ,13 new AttributeSpec(targetVC, sourceAttr .getName() , d) ,14 "from v: keySet(img_" + qname + ") "15 + "reportMap v > v. " + sourceAttr .getName() + " end" ) . execute ( ) ;16 }17 return targetVC;18 }

    First, CreateVertexClass creates a vertex class with thesame qualified name in the target schema. The semanticexpression expands into V{QName!} where QName is thequalified name of the source vertex class. This expressionevaluates to the set of vertices which are direct instances(note the exclamation mark) of the vertex class QName.

    Thereafter, one CreateAttribute operation is executed foreach attribute defined for the copied vertex class. The seman-tic expression evaluates to a function that assign to everyarchetype vertex v its attribute value in the source graph.Thus, the attributes are simply copied over, and the sameapplies to the attribute values on the instance level.

    Note that the implementation of transformations as Javaclasses allows to use the full power of Java to compute anyrelevant information. Every elementary transformation oper-ation has a constructor that receives a semantic expressionas GReQL string, which is evaluated by the transforma-tion object when it is executed. Additionally, all GReTLoperations have another constructor that directly receivesan already calculated result. Thus, instead of using GReQLto specify the vertex archetypes and the value assignmentfunction for attributes, it is possible to compute those algo-rithmically in Java and pass the calculated results to the trans-formation constructor.

    Making the operation callable from the GReTL DSL Untilnow, the implementation of CopyVertexClass is completewith respect to the Java API. To make it also usable inthe GReTL DSL, the operation has to provide an addi-tional parseAndCreate() factory method that parses theoperation arguments and returns a transformation instance.The method receives the current GReTL interpreter of typeExecuteTransformation as a parameter which provides aset of matching methods.

    19 public static CopyVertexClass parseAndCreate(ExecuteTransformation et ) {20 String alias = Context .DEFAULT_SOURCE_GRAPH_ALIAS;21 i f ( et . tryMatchGraphAlias ( ) )22 alias = et .matchGraphAlias ( ) ;23 String qname = et .matchQualifiedName( ) ;24 VertexClass sourceVC = et . context .getSourceGraph( alias ) .getSchema()25 .getGraphClass ( ) . getVertexClass(qname) ;26 return new CopyVertexClass( et . context , sourceVC, alias ) ;27 }

    Because the CopyVertexClass operation is generallyuseful, the source graph alias is made optional here, so thatit can be omitted if there is only one source graph. In thatcase, the default alias is used. The vertex class to be cop-ied is retrieved from the source graphs schema, and finallya new CopyVertexClass instance is instantiated with theinterpreters context and returned.

    In only 27 lines of code, we have added a completelynew transformation operation to the GReTL framework bycomposing it using the elementary operations CreateVertex-Class and CreateAttributes. The new CopyVertexClassoperation is convenient, whenever a transformation scenariorequires the unmodified transfer of several vertex classesfrom source schemas into the target schema including themigration on the instance level.

    Except that a custom transformation has to extend theTransformation class and override its abstract transform()method, GReTL does not place any restrictions on its behav-ior. For most cases, it suffices to compose the elementaryoperations in some way, but it may also introduce completelynew semantics and even a new syntax for its arguments.

    Although not the topic of this article, it should be men-tioned that the GReQL query language is also extensible. Toadd a new function to GReQL, one has to extend an abstractFunction class and implement an evaluate() method witharbitrary arguments, returning an arbitrary object as a result.So if some information needed in the semantic expressionsgiven to the GReTL operations can better be calculated algo-rithmically or even requires communication with auxiliaryservices, there is nothing hindering users from doing so.

    The complete power of Java with its huge ecosystem andthousands of libraries can always be exploited in both GReQLqueries and GReTL transformations.

    5 Related work

    In this section, GReTL is compared to todays most relevantand widely used transformation languages. A coarse-graineddistinction can be made between whether a transformationlanguage is especially targeted to a certain use case (special-purpose) or whether it is general enough to preform arbitrarytransformations (general-purpose).

    First, we give a brief overview of the field of coupled evo-lution which is related to GReTLs idea of transformations


  • 316 J. Ebert, T. Horn

    on both metamodels and models. We then outline the gen-eral concepts of graph rewriting systems pointing out themajor differences compared to GReTL, and finally we com-pare GReTL to the most prominent model transformationlanguages.

    Because GReTL is unidirectional and operational, weomit a discussion on logic-based transformation languageslike QVT Relations [18]. Since triple graph grammarapproaches like the TGG Interpreter [19] or MOFLON [20]are very similar to graph rewriting systems when applied asforward transformations, we only discuss them briefly at theend of the graph rewriting paragraph.

    5.1 Comparison with coupled evolution approaches

    Two special-purpose approaches tailored to coupled evolu-tion of metamodels and models are Epsilon Flock [21] andCOPE [22]. Their intent is to ease the creation of transforma-tions that migrate models conforming to a metamodel versiona to models conforming to a (usually newer) metamodelversion b. Usually, the differences between successive meta-model versions are relatively small compared to the com-monalities. With Epsilon Flock and COPE, transformationdevelopers have to specify the transformation only for theelements whose metamodel type has been changed betweenversions. Thus, the size of the transformations scales withthe amount of differences between the metamodel versionsinstead of the size of the metamodels.

    Epsilon Flock implements a model migration approachnamed conservative copy. With that approach, all elementsthat conform to both the source and the target metamodel areimplicitly copied to the target model. Rules need to be spec-ified only for elements directly affected by the metamodelchanges.

    COPE is not a separate transformation language, but acomplete modeling workbench integrated into the EclipseEcore editor. It provides a set of about 60 so-called reus-able coupled operations that are used to evolve a givenmetamodel interactively. Examples for such operations arerenaming a class or extracting an abstract superclass. Thesequence of operations applied to the Ecore metamodel inthe editor is recorded in a history from which model updatetransformations can be generated. Thus, when metamodel-ing using the COPE workbench, the update transformationsfrom any metamodel version a to a later version b emerge as aby-product of modeling.

    GReTL is not especially targeted at coupled evolution ofmetamodels and models, but its emphasis lies on the incre-mental and parallel construction of target schema and graphwhich can be seen as a generalization of coupled evolution.In Sect. 4.3, a generic copy operation for a vertex class andits instances has been implemented to demonstrate how toextend the language. Likewise, a similar operation could be

    implemented that copies an edge class into the target schemaand its instances into the target graph. If we wanted to evolvea schema, we could use GReTL to do so. First, we apply thegeneric copy operations to the schema elements that shouldstay as is, and thereafter we can specify the changed partsof the schema using the elementary operations introducedin Sect. 2.6 and exemplified in Sect. 3.2. This is similarto the COPE approach in that the evolution is specified interms of operations applied to the source metamodel version.Of course, such a GReTL transformation would be specificto exactly one source schema version and generate exactlyone target schema version with a conforming graph, whereasCOPE is capable of generating update transformations fromany metamodel version to any later version.

    A coupled evolution approach more similar to EpsilonFlock could be developed by integrating a schema compar-ison approach into a new GReTL operation. This operationwould receive a schema of a base version, a graph conformingto this base version, and a schema of another version. It wouldcalculate the schema elements that did not change betweenthe versions and copy the given source graph instances intothe target graph conforming to the other schema version.Again, only operations for elements whose type has beenmodified in the schema evolution would need to be speci-fied.

    5.2 Comparison with graph rewriting systems

    Today, graph transformation languages in the sense of graphrewriting systems are widely applied in the fields of modeltransformation [23,24] as well as simulation and verification[2527], and program optimization [28,29].

    The basic building blocks of graph transformations arerules consisting of a left-hand side and a right-hand side.The left-hand side is a graph pattern, and the right-hand sideis a replacement graph. Both sides consist of symbols fornodes and edges connecting those nodes. When a rule isapplied, one arbitrary occurrence of a subgraph matchingthe graph pattern is searched in the host graph and replacedby an instance of the replacement graph. The symbols occur-ring both in the graph pattern and in the replacement graphdenote nodes and edges that are preserved by a rule appli-cation. Symbols occurring only in the graph pattern denotenodes and edges that are deleted, and symbols occurring onlyin the replacement graph denote nodes and edges that are cre-ated by a rule application. Most languages support negativeapplication conditions (NAC) in the left-hand side, which for-bid the rules application if they can be matched in the hostgraph.

    For specifying the control flow of a transformation, manygraph rewriting systems provide separate rule applicationlanguages. For example, PROGRES [30] specifies the order


  • GReTL: extensible, operational, graph-based transformations 317

    of rule applications using so-called transactions, which arein essence transformation procedures triggering rule appli-cations or other transactions, by using control structures likeconditional application, nondeterministic choice, and iter-ated application. Fujaba7 and MDELab8 use story diagrams[31], which is a visual language similar to UML activity dia-grams. VIATRA2 [32] uses abstract state machines [33], andGrGen.NET [34] provides a custom graph rewrite sequencelanguage based on logical and regular expressions. Henshin[35,36], the successor of the Tiger EMF Transformation Pro-ject [37], provides a visual rule application control languagesimilar to graph rewrite sequences, where different controlunits can be nested inside each other. There are units forsequential application, application in arbitrary order, iteratedapplication, conditional application, priority-based applica-tion, and so called amalgamation units providing a foralloperator. AGG [38] supports priority-based layering of ruleapplication, where all rules of the layer with highest priorityare applied as long as possible, then all rules of the followinglayer, etc. The transformation terminates either when no ruleof the lowest layer can be applied anymore, or optionally ifno rule of no layer can be applied. Furthermore, users caninteractively select a rule to be applied in a debugger-likestepwise execution mode.

    Graph transformation languages focusing on enumeratingall possible graphs that can be generated from a given startgraph by applying a set of rules usually execute all applica-ble rules in parallel. These languages are used for verifica-tion purposes, i.e., the system is modeled as a graph, and thedynamic semantics of a system is modeled in terms of rulesthat transition the system from one state into another. If tworule application sequences result in isomorphic graphs, theytransit to the same state. For each state, invariants may bechecked, or properties like confluence can be proven. Lan-guages used for such purposes, although not limited to thisscenario, are for example GROOVE [39], AGG, and Hen-shin.

    The kind of graphs used by the individual graph transfor-mation tools varies from simple directed graphs with nodesand edges over labeled graphs, graphs with attributed nodesand/or edges to typed and attributed graphs with inheritancebetween node types [40]. The types available in a graph aredefined by a type graph or schema. Often, visual metamod-eling approaches similar to UML class diagrams are used todefine schemas. In the TGraph technological space on whichGReTL is based, graphs are ordered in addition to being typedand attributed. Furthermore, inheritance is not restricted tonode types, but possible also for edge types.

    One major difference between graph rewriting systemsand GReTL is that the former always work in-place, i.e.,


    they modify their source graph directly, and source and tar-get graphs are the same. This also means that there cannot bemany input graphs to a transformation, as it was the scenarioin the example of Sect. 3. Of course, it is possible to copy theelements of many graphs into one, but then the identities ofthe individual graphs are lost, so that additional constructsare needed to restrict pattern matching to a subgraph that hasbeen a single input graph before. VIATRA2 has a specialkeyword below, which can be used to restrict an element tobe contained directly or indirectly in some other element forpurposes like that.

    GReTL transformations usually work out-place. Theyconstruct a completely new target graph (including a newtarget schema) out of arbitrary many source graphs, wherearbitrary many also includes zero. GReTL transformationsmay also use the given source graph as target graph, but thenthey are restricted to the instance level, i.e., they cannot mod-ify the schema.

    The in-place nature of graph rewriting systems has theconsequence that they are, in principle, restricted to endoge-nous transformations, i.e., transformations whose source andtarget graphs conform to the same schema. However, in prac-tice this restriction is circumvented by the use of a combinedschema encompassing at least source and target schema plusoptionally node and edge types used only during the execu-tion of a transformation. This makes graph rewriting systemsalso applicable for typical model transformation tasks, wherethe schemas of source and target model differ.

    Graph rewriting systems use pattern matching to locateone single occurrence of a rules left-hand side in the hostgraph which is then replaced by the right-hand side. Instead ofpattern matching, GReTL uses graph querying on the sourcegraphs to compute sets of arbitrary archetypes, and for eacharchetype a new target graph element is created. For many usecases, this novel concept enabled us to define very conciseand elegant transformations like in [11], but it is not suitedout-of-the-box for most typical graph rewriting domains likeoptimization and verification. However, because GReTL isextensible, it can be adapted to such domains as well. Forsolving the TTC 2011 compiler optimization case [12], somecustom in-place operations were developed to make GReTLfit this purpose [13].

    It should be noted that although we do not compareGReTL with TGGs in detail here, most differences betweenGReTL and graph rewriting systems apply in a similarvein for TGGs. A TGG forward (i.e., uni-directional) trans-formation is similar to a graph rewriting transformation,except that it does not work in-place. However, the men-tioned main differences apply: TGGs use pattern matching,whereas GReTL is based on querying, and GReTL is ableto construct a new metamodel and instantiate a conform-ing graph, whereas TGGs assume a fixed, pre-existing targetmetamodel.


  • 318 J. Ebert, T. Horn

    5.3 Detailed comparison with model transformationlanguages

    There are only a few widely used general-purpose transfor-mation languages, the most well known being ATL [41], theEpsilon Transformation Language (ETL, [42,43]), and theQVT languages Operational Mappings (QVTo) and Rela-tions [18].

    GReTL claims to be competitive to ATL, ETL, and QVTo.Therefore, we compare GReTL to these languages in moredetail along the main language properties.

    GReTL is meant to be a graph-based transformation lan-guage. It shares with the competitors the property that trans-formations are usually executed out-place, i.e., a new targetmodel is created from a given input model. The propertyof transformations also constructing the target metamodel isa novel concept of GReTL. All other model transformationlanguages require a pre-existing target metamodel.

    ATL, ETL, and QVTo as well as GReTL support trans-formations using more than one input model simultaneously.Because of its flexible archetype concept which only requiresthat the semantic expressions given to the GReTL operationsevaluate to sets of arbitrary objects, GReTL also allows thecreation of a new target graph with no source graph at all.ATL, ETL, and QVTo allow for transformations that createmore than one target model, too, whereas GReTL transfor-mations are restricted to one single output graph at the currentpoint in time.

    While all cited transformation languages are rule-basedwith several differences in rule application semantics, e.g.,imperative (QVTo, ATL called rules) versus declarative (rela-tions, ATL matched rules, ETL rules), the concept of spec-ifying the target graph of a transformation by defining theextensions of the target schema constituents is a novel prop-erty of GReTL.

    ATL and ETL rules have a source pattern declaring iden-tifiers with source metamodel types and a target pattern thatspecifies elements to be created. In the case of ETL, rulescan only declare one input element in their source patterns.The source pattern may also contain constraints, and for allmatches of the source pattern in the source model and ful-filling the constraints, the elements in the target pattern arecreated in the target model.

    In contrast, QVTo and GReTL are based on querying.QVTo uses the Object Constraint Language (OCL, [44])whereas GReTL uses the GReQL language. We believe thatGReQL provides more expressive constructs than most otherquerying languages and comparable components of othertransformation languages. Especially when very complex,non-local connections of elements with arbitrary distance interms of edges in between have to be described, and GReQLsregular path expressions provide a powerful means.

    When not considering the optional creation of the targetschema, GReTLs operational execution semantics are quitesimilar to those of QVTo. For the latter, starting with a top-level mapping operation, sets of source model elements areselected using OCL, and for each of them another mappingis applied, creating a new target model element and possi-bly applying further mapping operations. Usually, this callhierarchy of mapping operations is aligned to the contain-ment hierarchy of the source model. With GReTL, there isno hierarchy of operation calls. The semantic expressionsdefine the archetype sets for each operation invocation, andsimilar to QVTo, for any member in these sets, a new targetgraph element is created.

    The strict separation of concerns in GReTLs concept ofcompositional semantics with respect to the constituents ofa schema results in a very slim set of only four transfor-mation operations which suffice to perform arbitrary trans-formations. These operations have a very simple and clearsemantics, and can easily be combined to more expressiveand convenient operations, as the example in Sect. 4.3 dem-onstrates. In contrast, all cited languages mix several con-cerns. Rules create output elements for some input elementsand additionally set the new elements attribute values andassign references or create edges between elements. This maylead to duplicate code in rules creating instances of subclass-es of some common superclass. Therefore, ATL, ETL, andQVTo provide advanced concepts like rule inheritance thatallow for aligning a transformation towards the type hierar-chy of the target metamodel. This way, inherited attributesand references are set by some parent rule, and specializedrules only have to deal with the direct properties of theiroutput elements. However, the implementation of rule inher-itance differs across languages [45]. For example, while ETLsupports multiple inheritance between rules, ATL and QVTosupport only single inheritance.

    The usual extension and reuse mechanism supported bymost transformation languages are libraries, which consistof helper functions and sometimes even rules. These helpers(and rules) can then be used in transformations. Beyond thatis the black-box implementation concept defined by the QVTstandard. It allows for implementing a QVTo mapping oper-ation with an arbitrary MOF operation [46] with the samesignature and semantics. However, GReTL allows for evenmore extensibility, because an extension operation developeris mostly free both in the choice of the syntax in the GReTLDSL and the semantics of the new operation. We acknowl-edge that there are scenarios, where the conceptual purity ofGReTLs elementary transformation operations is less con-venient. But GReTL was designed with extensibility in mind.An extended convenience operation like CopyVertexClassdiscussed in Sect. 4.3 is usually implemented in only a fewlines of Java code.


  • GReTL: extensible, operational, graph-based transformations 319

    With respect to traceability, the image and archetype func-tions that are created automatically during the execution of aGReTL transformation form a very fine-grained traceabilitymodel. They provide the possibility for navigating from anytarget graph element (image) to its archetype, and vice versa.These functions can be persisted as an XML file after thetransformation has succeeded and loaded back later in orderto navigate between target and source graphs. ATL, ETL,and the implementations of the QVT languages have similartraceability concepts, in that for each rule the mappings frominput to output elements are retained and can also be per-sisted. The main difference is that in GReTL, the archetypescan be chosen freely and are not restricted to source graphelements.

    6 Conclusion and future work

    This article introduced the graph-based GReTL transfor-mation language with a focus on its concrete syntax.A non-trivial example (merging the metamodels of twodomain-specific languages including the migration of theirinstances graphs) was explained in detail to demonstrate thepower of the approach. (A simpler introductory example isdiscussed in [5]).

    Also, a brief insight into its design as a Java API was given,and, using that, an extended copy operation was exemplarilyimplemented to show GReTLs extensibility.

    Based of the concept of compositional semantics ofTGraph schemas, GReTL introduces a novel concept tomodel transformations. GReTL transformations follow theconception of constructing the target schema, while simulta-neously creating the target graph as an extension.

    GReTLs API supplies a basis for the definition ofexpressive transformations that support frequently occur-ring transformation tasks appropriately. The encapsulationof transformations in plain Java transformation objects sup-ports this goal, facilitating reuse and composition in terms ofinheritance and nesting.

    We see several advantages for using the GReTL transfor-mation language:

    GReTL is operational. Thus, it can be included in arbi-trary (Java) application code.

    GReTL is formal, since it is built on TGraphs, grUML,and GReQL, which are formally defined.

    GReTL builds on the powerful GReQL querying lan-guage. Thus, GReTL transformations can use arbitraryinformation extracted from the source graph. BecauseGReQL has proven to be highly efficient for complexquerying of large graphs, the same can be said for GReTLfor the transformation of large graphs.

    GReTL builds on a powerful conception. Since grUMLhas compositional semantics, the full power expectedfrom a transformation language is granted by a kernelof four elementary operations.

    GReTL DSL has an easy syntax. Thus, a quick notationof simply structured transformations is possible.

    GReTL is embedded in Java. Thus, arbitrary computa-tions can be executed to steer the transformation opera-tions.

    GReTL transformations can be executed from the com-mand line using a convenient interface which enablesbatch processing of transformations.

    GReTL is extensible. Higher-level operations that pro-vide more expressiveness or are especially suited for aparticular domain can be built on top of the provided ele-mentary operations.

    GReTL supports full traceability, since the img/arch-maps are available and can be persisted. Thus, traceabilityinformation can be used inside the transformation codeand later on.

    First promising experiences with GReTL have beenachieved when using it in a reengineering project, where Javasoftware was parsed into TGraphs representing the abstractsyntax of the source code. Here, GReTL transformationshave been used for the extraction of state machines that hadbeen implemented in plain Java using a set of conventions.The input graph to this transformation had about 2.5 millionvertices and edges and it could still be executed on a usuallaptop in a few seconds.

    Furthermore, the Transformation Tool Contests 2010 and2011 were won using GReTL and other TGraph technologieslike GReQL.

    In future work, further issues have to be tackled, e.g., betterapplicability for endogenous in-place transformations, andthe inclusion of ordering information. Also, instead of hav-ing transformations that construct new schemas includingconforming graphs, the concepts should be extended to sup-port modification of existing schemas including the parallelmigration of existing graphs.

    Although GReTLs concepts were derived from the for-mal definition of TGraphs and are aligned to the constituentsthat make up a grUML schema (vertex classes, edge clas-ses, and attributes), it seems feasible to apply them on othertechnological spaces like EMF [47] as well. A grUML ver-tex class is equivalent to Ecores EClass, and grUML attri-butes correspond to Ecore EAttributes. The main differenceis that EMF does not consider edges as first class objects,but relations between elements are expressed as (pairs of)EReferences instead. However, it is still possible to imag-ine an operation that creates a reference (and an oppositereference) in an Ecore metamodel, and assigns that refer-ence for elements in an instance model with a provided set


  • 320 J. Ebert, T. Horn

    of tuples specifying the archetypes of the elements that haveto be connected. Using EMF technology, the Object Con-straint Language [44] or EMF Model Query [48,49] couldbe used for specifying semantic expressions.

    Because the GReTL archetype concept decouples theretrieval of source model information from the creation oftarget model elements, it seems feasible to allow for trans-formations crossing the borders of technological spaces, e.g.,archetypes calculated on a source TGraph using GReQLcould be passed to transformation operations creating ele-ments in an EMF model and vice versa.


    1. Bzivin, J.: Model driven engineering: an emerging technicalspace. In: Lmmel, R., Saraiva, J.A., Visser, J. (eds.) Generativeand Transformational Techniques in Software Engineering. Lec-ture Notes in Computer Science, chap. 2., vol. 4143, pp. 3664.Springer, Berlin (2006)

    2. Object Management Group: MDA Guide Version 1.0.1. (2003)3. Kleppe, A.G., Warmer, J., Bast, W.: MDA Explained: The

    Model Driven Architecture: Practice and Promise. Addison-Wes-ley/Longman, Boston (2003)

    4. van Deursen, A., Klint, P., Visser, J.: Domain-specific languages:an annotated bibliography. SIGPLAN Not. 35, 2636 (2000)

    5. Horn, T., Ebert, J.: The GReTL transformation language. In: Cabotand Visser [50], pp. 183197

    6. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Pat-terns. Addison-Wesley, Boston (1995)

    7. Ebert, J., Riediger, V., Winter, A.: Graph technology in reverseengineering. The TGraph approach. In: 10th Workshop SoftwareReengineering (WSR 2008). GI Lecture Notes in Informatics, vol.126. GI (2008)

    8. Kurtev, I., Bzivin, J., Aksit, M.: Technological spaces: an initialappraisal. In: CoopIS, DOA2002 Federated Conferences, Indus-trial track (2002)

    9. Ebert, J., Bildhauer, D.: Reverse engineering using graph queries.In: Graph Transformations and Model Driven Engineering. LNCS,vol. 5765, Springer, Berlin (2010)

    10. Horn, T.: Program understanding: a reengineering case for thetransformation tool contest. In: Van Gorp et al. [51]

    11. Horn, T.: Solving the TTC 2011 reengineering case with GReTL.In: Van Gorp et al. [51]

    12. Buchwald, S., Jakumeit, E.: Compiler optimization: a case for thetransformation tool contest. In: Van Gorp et al. [51]

    13. Horn, T.: Solving the TTC 2011 compiler optimization case withGReTL. In: Van Gorp et al. [51]

    14. Horn, T.: SHARE demo related to the paper Solving the TTC2011 Reengineering Case with GReTL.

    15. Horn, T.: SHARE demo related to the paper Solving theTTC 2011 Compiler Optimization Case with GReTL.

    16. Walter, T., Ebert, J.: Foundations of Graph-Based ModelingLanguages. Tech. Rep., University of Koblenz-Landau, Institutefor Software Technology (in press).

    17. Miksa, K., Kasztelnik, M., Sabine, P.: Case study design. ProjectDeliverable ICT216691/CMR/WP5-D2/D/RE/b1, MOST Project(2009)

    18. Object Management Group: Meta Object Facility (MOF) 2.0:Query/View/Transformation Specification v1.0. (2008)

    19. Greenyer, J., Kindler, E.: Comparing relational model transforma-tion technologies: implementing Query/View/Transformation withTriple Graph Grammars. Softw. Syst. Model. 9, 2146 (2010).doi:10.1007/s10270-009-0121-8

    20. Amelunxen, C., Knigs, A., Rtschke, T., Schrr, A.: MOFLON:a standard-compliant metamodeling framework with graph trans-formations. In: Rensink, A., Warmer, J. (eds.) Model DrivenArchitectureFoundations and Applications: Second EuropeanConference. Lecture Notes in Computer Science (LNCS), vol.4066, pp. 361375. Springer, Heidelberg (2006)

    21. Rose, L.M., Kolovos, D.S., Paige, R.F., Polack, F.A.C.: ModelMigration with Epsilon Flock. In: ICMT. Lecture Notes in Com-puter Science, vol. 6142, pp. 184198. Springer, Berlin (2010)

    22. Herrmannsdoerfer, M.: COPEa workbench for the coupled evo-lution of metamodels and models. In: Malloy, B.A., Staab, S., vanden Brand, M. (eds.) SLE. Lecture Notes in Computer Science,vol. 6563, pp. 286295. Springer, Berlin (2010)

    23. Taentzer, G., Ehrig, K., Guerra, E., de Lara, J., Lengyel, L.,Levendovszky, T., Prange, U., Varr, D., Varr-Gyapay, S.: Modeltransformation by graph transformation: a comparative study. In:ACM/IEEE 8th International Conference on Model Driven Engi-neering Languages and Systems. Montego Bay, Jamaica (2005)

    24. Ehrig, H., Ehrig, K.: Overview of formal concepts for model trans-formations based on typed attributed graph transformation. Elec-tron. Notes Theor. Comput. Sci. 152, 322 (2006)

    25. Aksit, M., Rensink, A., Staijen, T.: A graph-transformation-basedsimulation approach for analysing aspect interference on sharedjoin points. In: Proceedings of the 8th ACM International Con-ference on Aspect-Oriented Software Development, AOSD 09,pp. 3950, ACM, New York (2009)

    26. Gnczy, L., Kovcs, M., Varr, D.: Modeling and verificationof reliable messaging by graph transformation systems. Electron.Notes Theor. Comput. Sci. 175, 3750 (2007)

    27. Rth, I., Vago, D., Varr, D.: Design-time simulation of domain-specific models by incremental pattern matching. In: VL/HCC,pp. 219222. IEEE (2008)

    28. Assmann, U.: Graph rewrite systems for program optimiza-tion. ACM Trans. Program. Lang. Syst. 22, 583637 (2000)

    29. Schsser, A., Gei, R.: Graph rewriting for hardware dependentprogram optimizations. In: Schrr, A., Nagl, M., Zndorf,A. (eds.) Applications of Graph Transformations with IndustrialRelevance, pp. 233248. Springer, Berlin (2008)

    30. Schrr, A., Winter, A., Zndorf, A.: The PROGRES approach: lan-guage and environment. In: Ehrig, H., Engels, G., Kreowski, H.-J.,Rozenberg, G. (eds.) Handbook of Graph Grammars and Comput-ing by Graph Transformation: Applications, Languages, and Tools,vol. 3, pp. 487550. World Scientific, Singapore (1999)

    31. Fischer, T., Niere, J., Torunski, L., Zndorf, A.: Story Diagrams:a new graph rewrite language based on the unified modelinglanguage and Java. In: Ehrig, H., Engels, G., Kreowski, H.-J.,Rozenberg, G. (eds.) TAGT. Lecture Notes in Computer Science,vol. 1764, pp. 296309. Springer, Berlin (1998)

    32. Varr, D., Balogh, A.: The model transformation language of theVIATRA2 framework. Sci. Comput. Program. 68(3), 214234(2007, special issue on Model Transformation)

    33. Brger, E., Strk, R.F.: Abstract State Machines. A Method forHigh-Level System Design and Analysis. Springer, Berlin (2003)

    34. Jakumeit, E., Buchwald, S., Kroll, M.: GrGen. NET. Int. J. Softw.Tools Technol. Transf. (STTT) 12, 263271 (2010)

    35. Ermel, C., Biermann, E., Schmidt, J., Warning, A.: Visual mod-eling of controlled EMF model transformation using HENSHIN.ECEASST, 32 (2010)

    36. Arendt, T., Biermann, E., Jurack, S., Krause, C., Taentzer, G.:Henshin: advanced concepts and tools for in-place EMF


  • GReTL: extensible, operational, graph-based transformations 321

    model transformations. In: Petriu, D.C., Rouquette, N., Haugen,. (eds.) MoDELS (1). Lecture Notes in Computer Science, vol.6394, pp. 121135. Springer, UK (2010)

    37. Biermann, E., Ehrig, K., Ermel, C., Khler, C., Taentzer, G.: TheEMF model transformation framework. In: Schrr, A., Nagl, M.,Zndorf, A. (eds.) AGTIVE. Lecture Notes in Computer Science,vol. 5088, pp. 566567. Springer, Berlin (2007)

    38. Taentzer, G.: AGG: a graph transformation environment for mod-eling and validation of software. In: Kanade, T., Kittler, J.,Kleinberg, J.M., Mattern, F., Mitchell, J.C., Naor, M.,Nierstrasz, O., Pandu Rangan, C., Steffen, B. (eds.) Applications ofGraph Transformations with Industrial Relevance. Lecture Notesin Computer Science, chap. 35, vol. 3062, pp. 446453. Springer,Berlin (2004)

    39. Kastenberg, H., Rensink, A.: Model checking dynamic states inGROOVE. In: Valmari, A. (ed.) SPIN. Lecture Notes in ComputerScience, vol. 3925, pp. 299305. Springer, Berlin (2006)

    40. de Lara, J., Bardohl, R., Ehrig, H., Ehrig, K., Prange, U., Taent-zer, G.: Attributed graph transformation with node type inheri-tance. Theor. Comput. Sci. 376, 139163 (2007)

    41. ATLAS Group: ATL: User Guide. (2011)

    42. Kolovos, D., Rose, L., Paige, R.: The Epsilon Book. Accessed June2011

    43. Kolovos, D.S., Paige, R.F., Polack, F.A.: The epsilon transforma-tion language. In: Proceedings of the 1st International Conferenceon Theory and Practice of Model Transformations, ICMT 08,pp. 4660. Springer, Berlin (2008)

    44. Object Management Group: Object Constraint Language, Version2.2. (2010)

    45. Wimmer, M., Kappel, G., Kusel, A., Retschitzegger, W., Schn-bck, J., Schwinger, W., Kolovos, D.S., Paige, R.F., Lauder, M.,Schrr, A., Wagelaar, D.: A comparison of rule inheritance inmodel-to-model transformation languages. In: Cabot and Visser[50], pp. 3146

    46. Object Management Group: Meta Object Facility (MOF) CoreSpecification, Version 2.4.1. (2011)

    47. Steinberg, D., Budinsky, F., Paternostro, M., Merks, E.: EMF:Eclipse Modeling Framework, 2nd edn. Addison-Wesley/Long-man, Amsterdam (2009)

    48. The Eclipse Project: EMF Model Query.

    49. The Eclipse Project: EMF Model Query2.

    50. Cabot, J., Visser, E. (eds): Proceedings of the 4th International Con-ference on Theory and Practice of Model Transformations, ICMT2011, Zurich, Switzerland, June 2728, 2011. Lecture Notes inComputer Science, vol. 6707. Springer, Berlin (2011)

    51. Van Gorp, P., Mazanek, S., Rose, L. (eds): Post-Proceedings of theTTC 2011: Fifth Transformation Tool Contest, Zrich, Switzer-land, June 2930 2011. EPTCS (2011)

    Author Biographies

    Jrgen Ebert holds the Chairof Software Engineering at theUniversity of Koblenz-Landausince 1982. His research areasinclude software engineering,focusing on modeling, softwarearchitecture, and construction ofgeneric tools, especially usinggraph-based methods. In the lastdecade, he published primarilyin the area of graph technology,metamodeling, metaCASE, andsoftware reengineering. He wasan organizer or program commit-tee chair for several workshops

    and conferences in the area of software engineering environments andreengineering.

    Tassilo Horn is a researcherat the Institute for SoftwareTechnology at the Universityof Koblenz-Landau. He is cur-rently working on his Ph.D. inwhich he explores the usage ofthe functional programming par-adigm for model querying andtransformation. His further inter-ests include graph technology ingeneral, software reengineering,metamodeling, relational pro-gramming, metaprogramming,API design, and free software,where he is a contributor to a

    diversity of projects.


    GReTL: an extensible, operational, graph-based transformation languageAbstract1 Introduction2 Foundations2.1 Overview2.2 Definitions2.3 Schemas and their constituents2.4 Defining a graph2.5 Specifying extensions2.6 Creating the target graph

    3 GReTL for schema merges3.1 A schema merge use case3.1.1 Merging BEDSL and PDDSL

    3.2 The schema merge transformation

    4 GReTL as an extensible language4.1 GReTL core design4.2 Execution semantics4.3 Extension operation: copying vertex classes

    5 Related work5.1 Comparison with coupled evolution approaches5.2 Comparison with graph rewriting systems5.3 Detailed comparison with model transformation languages

    6 Conclusion and future workReferences


View more >