Model Transformations for DSL Processing Stefan Kapferer January 7, - - PowerPoint PPT Presentation

model transformations for dsl processing
SMART_READER_LITE
LIVE PREVIEW

Model Transformations for DSL Processing Stefan Kapferer January 7, - - PowerPoint PPT Presentation

Model Transformations for DSL Processing Stefan Kapferer January 7, 2019 University of Applied Sciences of Eastern Switzerland (HSR FHO) Table of contents 1. Introduction 2. Example & Live Demo 3. Model Transformations with Henshin 4.


slide-1
SLIDE 1

Model Transformations for DSL Processing

Stefan Kapferer January 7, 2019

University of Applied Sciences of Eastern Switzerland (HSR FHO)

slide-2
SLIDE 2

Table of contents

  • 1. Introduction
  • 2. Example & Live Demo
  • 3. Model Transformations with Henshin
  • 4. Algebraic Graph Transformation
  • 5. Summary & Conclusions

1

slide-3
SLIDE 3

Introduction

slide-4
SLIDE 4

Models are everywhere

Models are used in all disciplines and phases of the software development lifecycle. MD* approaches:

  • Model-driven Development (MDD)
  • Model-driven Engineering (MDE)
  • Model-driven Architecture (MDA) [6]
  • Model-driven Security (MDS) [4]
  • and so on ...

2

slide-5
SLIDE 5

Models in SE disciplines

Software Engineering Discipline Examples of Models Business Modeling & Re- quirements Engineering Domain Models, Use Case Models, Business Process Models Analysis & Design Domain Models, Architecture View Models, DDD Context Maps, System Sequence Diagrams, State Machine Diagrams, Activity Diagrams Implementation Class, Object, Data Models Testing Performance Simulation Model, Test Case Specification Model Operations & Mainte- nance Deployment Models, Maintenance Models

3

slide-6
SLIDE 6

Model Transformation

Models need to be transformed into other models:

  • Different representations for different audiences
  • Change level of abstraction
  • Refinement of domain model towards fully-fledged class diagram
  • Keep level of abstraction but change language
  • Refactorings
  • Code migration into other language

4

slide-7
SLIDE 7

Model Transformation Taxonomy [5]

Different types of model transformations:

  • Endogenous vs. Exogenous
  • Endogenous: Source and target model are represented by the

same language

  • Exogenous: Transformation between models in different

languages/representations

  • In-place vs. Out-place
  • Concerns endogenous transformations only. Exogenous

transformations are always out-place.

  • In-place: Transformation within the same meta-model
  • Out-place: Source meta-model differs from output meta-model
  • Horizontal vs. Vertical
  • Horizontal: Source and target model are on same level of

abstraction

  • Vertical: Transformation changes the level of abstraction

5

slide-8
SLIDE 8

Example & Live Demo

slide-9
SLIDE 9

ContextMapper DSL [2]

A Domain-specific Language for Context Mapping & Service Decomposition1

  • Modeling Domain-driven Design (DDD) Context Maps
  • Goal: Apply model transformations to realize architectural

refactorings [8] towards service decomposition

  • Split bounded contexts

DSL Processing via Model Transformation:

  • DSL Text

parsing

− − − − → Abstract Syntax Tree (AST) − → Model

  • Model

transformation

− − − − − − − − → Model

  • Model −

→ Abstract Syntax Tree (AST)

unparsing

− − − − − − → DSL Text

1https://contextmapper.github.io/

6

slide-10
SLIDE 10

ContextMapper DSL Example Context Map

Example Context Map:

1

/* The DDD Cargo sample application modeled in CML. */

2

ContextMap {

3

contains CargoBookingContext

4

contains VoyagePlanningContext

5

contains LocationContext

6 7

/* 'Shared-Kernel' between CargoBooking and VoyagePlanning. */

8

CargoBookingContext <-> VoyagePlanningContext : Shared-Kernel

9 10

/* CargoBooking and VoyagePlanning use Location OHS */

11

CargoBookingContext -> LocationContext : Upstream-Downstream {

12

upstream implements OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE

13

}

14

VoyagePlanningContext -> LocationContext : Upstream-Downstream {

15

upstream implements OPEN_HOST_SERVICE, PUBLISHED_LANGUAGE

16

}

17

} 7

slide-11
SLIDE 11

ContextMapper DSL Example: Input

DSL snippet modeling a bounded context:

1

/* Example Bounded Context in CML */

2

BoundedContext CustomerManagement {

3

Aggregate Customers {

4

Entity Customer {

5

String firstName

6

String familyName

7

Account customerBankAccount

8

}

9

Entity Account {

10

String iban

11

String bankName

12

}

13

}

14

Aggregate CustomerSelfService {

15

Entity Account {

16

String username

17

String password

18

Customer owner

19

}

20

}

21

} 8

slide-12
SLIDE 12

Live Demo: «Split Bounded Context by Duplicate Entity Name»

8

slide-13
SLIDE 13

ContextMapper DSL Example: Output

1

/* Example Bounded Context in CML */

2

BoundedContext CustomerManagement {

3

Aggregate Customers {

4

Entity Customer{

5

String firstName

6

String familyName

7

Account customerBankAccount

8

}

9

Entity Account {

10

String iban

11

String bankName

12

}

13

}

14

}

15

BoundedContext SplitBoundedContext {

16

Aggregate CustomerSelfService {

17

Entity Account {

18

String username

19

String password

20

Customer owner

21

}

22

}

23

} 9

slide-14
SLIDE 14

Model Transformations with Henshin

slide-15
SLIDE 15

Henshin Transformation Tool

Henshin [1] is an EMF [7] based transformation tool.

  • Henshin means transformation in Japanese
  • Supports in-place model transformations
  • Endogenous & Exogenous
  • Horizontal & Vertical
  • Based on Algebraic Graph Transformation [3]

10

slide-16
SLIDE 16

The Henshin Transformation Meta-Model2

2Copied from

https://wiki.eclipse.org/Henshin/Transformation_Meta-Model

11

slide-17
SLIDE 17

Example Transformation Model

Transformation model for example seen in the live demo:

  • LHS graph: «preserve» + «delete»
  • RHS graph: «preserve» + «create»

12

slide-18
SLIDE 18

Algebraic Graph Transformation

slide-19
SLIDE 19

From String Grammars ...

The classical string grammar you know: DecimalNumeral −> 0 | NonZeroDigit D i g i t s D i g i t s −> ε | D i g i t | D i g i t s D i g i t D i g i t −> 0 | NonZeroDigit NonZeroDigit −> 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

  • Example: DecimalNumeral grammar of the Java Language

Specification in Backus-Naur Form (BNF).

  • String grammar consists of a set of production rules.

13

slide-20
SLIDE 20

... to Graph Grammars

Similar principle with graphs:

  • Left-hand side (LHS) of the rule has to be matched in graph on

which the rule is applied to.

  • Right-hand side (RHS) describes the changes which will be

applied Example: Banking scenario «create new account for a customer».

14

slide-21
SLIDE 21

Typed Graphs

A simple graph is not sufficient.

  • Vertices and edges have to be typed.
  • Implicitly suggested in this example:

Lets make this concept explicit ...

15

slide-22
SLIDE 22

Typed Graph Fundamentals

A typed graph is based on the concept of a graph morphism: A graph G(V, E, s, t) consists of a set V of vertices, a set E of edges, source and target functions s, t : E → V. A type graph is a graph TG = (VTG, ETG, sTG, tTG). A graph morphism is an application f : G1 → G2, f = (fV, fE) of a graph G1 to another graph G2 which consists of two functions fV : V1 → V2 and fE : E1 → E2.

16

slide-23
SLIDE 23

Typed Graph

A typed graph GT = (G, ftype) over a type graph TG is a graph G and a graph morphism ftype : G → TG.

17

slide-24
SLIDE 24

Graph Productions

Graph rewriting rules, such as shown below, are also called graph productions: A graph production p = (LHS

l

← − K

r

− → RHS) consists of (typed) graphs LHS, K and RHS, and injective (typed) graph morphisms l and r. K is called the gluing graph and is derived by the mapping between the LHS and the RHS graph.

18

slide-25
SLIDE 25

Pushout

The so-called pushout is an operator transforming a graph G into another graph G′ given a production p. This is the key concept for applying transformations according to the algebraic graph transformation concept: A pushout PO over two graph morphisms f : G1 → G2 and g : G1 → G3 is defined by a pushout graph G4 and morphisms f′ : G3 → G4 and g′ : G2 → G4 with f′ ◦ g = g′ ◦ f.

19

slide-26
SLIDE 26

Pushout Example

The pushout concept applied to our banking example:

20

slide-27
SLIDE 27

Single Pushout Summarized

The Single Pushout (SPO) method applied to a graph G can be summarized as follows:

  • 1. Find a match of LHS in G, or formally, find a morphism

m : LHS → G.

  • 2. Deleting the sub-graph m(LHS) − m(LHS ∩ RHS) from G, which

trivially removes all elements from the graph that are within the LHS graph but not in the intersection graph of the LHS and RHS graph and thus are meant to be deleted by the rewriting rule.

  • 3. Adding the sub-graph m(RHS) − m(LHS ∩ RHS) to G to get the

result G′. This step adds all elements which are part of the RHS graph but not part of the intersection of the LHS and RHS graph and thus are meant to be created in G′ by the rewriting rule.

21

slide-28
SLIDE 28

Graph Grammar Definition

From graph productions to graph transformation systems and finally, graph grammars: A direct (typed) graph transformation G

p,m

= = ⇒ G′ is given by POs, a production p and match m : LHS → G. A (typed) graph transformation G0

= ⇒ Gn is a sequence G0 ⇒ G1 ... ⇒ Gn of direct (typed) graph transformations. A (typed) graph transformation system GTS = (TG, P) consists of a type graph TG and a set of (typed) graph productions P. A (typed) graph grammar GG = (GTS, S) consists of a graph transformation system GTS and a (typed) start graph S.

22

slide-29
SLIDE 29

Why do we need these formalisms?

The presented algebraic graph transformation approach behind Henshin allows formal reasoning about a transformation system:

  • Reasoning about applicability
  • Analyze if productions are parallel independent
  • Important for performance if you have huge transformation

systems

  • Find so-called critical pairs
  • Pairs of direct transformations which are parallel dependent

23

slide-30
SLIDE 30

Summary & Conclusions

slide-31
SLIDE 31

Seminar Question #1: Model Transformation vs. Program Transformation

  • Other software engineering disciplines
  • Business Modeling, Analysis & Design vs. Implementation
  • Other level of abstraction
  • Model Transformations
  • model-to-model
  • model-to-code
  • code-to-model
  • Program Transformations
  • code-to-code

Note: Refactoring (code-to-code) can be implemented as model transformation too.

24

slide-32
SLIDE 32

Seminar Question #2: Henshin Maturity & Differences to other Tools

  • Henshin Conclusion:
  • + Expressive transformation specification
  • + Mature transformation engine
  • + Solid foundations
  • - Improvable Tooling
  • Main differences to other transformation approaches:
  • Not only theoretic research project
  • Good compromise between scientific foundations & feasible tool

implementation

  • Declarative transformation specification
  • Other tools often use imperative approaches

25

slide-33
SLIDE 33

Seminar Question #3: Model Transformation for DSL Processing

  • DSL as a customized model representation
  • DSL text can be transformed into other model representations
  • Example:
  • DSL to EMF model («Parsing»)
  • EMF model to DSL («Unparsing»)
  • DSL processing approach:
  • DSL Text

parsing

− − − − → Abstract Syntax Tree (AST) − → Model

  • Model

transformation

− − − − − − − − → Model

  • Model −

→ Abstract Syntax Tree (AST)

unparsing

− − − − − → DSL Text

26

slide-34
SLIDE 34

Questions?

26

slide-35
SLIDE 35

Discussion

26

slide-36
SLIDE 36

References i

  • T. Arendt, E. Biermann, S. Jurack, C. Krause, and G. Taentzer.

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: Part I, MODELS’10, pages 121–135, Berlin, Heidelberg, 2010. Springer-Verlag. ContextMapper DSL. A Domain-specific Language for Context Mapping & Service Decomposition. https://contextmapper.github.io/.

[Online; Accessed: 2018-12-09].

slide-37
SLIDE 37

References ii

  • H. Ehrig, K. Ehrig, U. Prange, and G. Taentzer.

Fundamentals of Algebraic Graph Transformation. Monographs in Theoretical Computer Science. An EATCS Series. Springer, 2006.

  • T. Lodderstedt, D. Basin, and J. Doser.

Secureuml: A uml-based modeling language for model-driven security. In J.-M. Jézéquel, H. Hussmann, and S. Cook, editors, UML 2002 — The Unified Modeling Language, pages 426–441, Berlin, Heidelberg, 2002. Springer Berlin Heidelberg.

  • T. Mens and P. Van Gorp.

A taxonomy of model transformation.

  • Electron. Notes Theor. Comput. Sci., 152:125–142, Mar. 2006.
slide-38
SLIDE 38

References iii

  • R. Soley et al.

Model driven architecture. OMG white paper, 308(308):5, 2000.

  • D. Steinberg, F. Budinsky, E. Merks, and M. Paternostro.

EMF: Eclipse Modeling Framework. Eclipse Series. Pearson Education, 2008.

  • O. Zimmermann.

Architectural refactoring for the cloud: a decision-centric view

  • n cloud migration.

Computing, 99(2):129–145, 2017.