34
1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo) Shinji Sano, Yusaku Maeno, Satoshi Murakami (Kyushu Institute of Technology) 29 September 2005 GPCE 2005 Generative Programming and Component Engineer

1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

Embed Size (px)

Citation preview

Page 1: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

1

Model Compiler Construction Based on Aspect-oriented Mechanisms

Naoyasu Ubayashi (Kyushu Institute of Technology)Tetsuo Tamai (University of Tokyo)Shinji Sano, Yusaku Maeno, Satoshi Murakami (Kyushu Institute of Technology)

29 September 2005

GPCE 2005Generative Programming and Component Engineering

Page 2: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

2

Overview

1. Motivation2. AspectM 3. Model compiler construction using

AspectM4. Discussion5. Related work6. Conclusion

Page 3: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

3

1. Motivation

Page 4: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

4

Issues to be tackled Model-based development is a software

development method in which models are created before source code is written.

Although the method is effective, we have to modify models when we face evolution such as change of platforms.

These modifications crosscut over many places in the models, and tend to cause unexpected errors.

New platformsNew requirements

Optimization

Multiple concerns!

Page 5: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

5

How does MDA deal with this problem ?

Analysis

Design

Coding

CIM

PIM

PSM

Source code

MDA: Model-Driven Architecture PIM: Platform Independent ModelCIM: Computation Independent Model PSM: Platform Specific Model

OOSD MDA

model compilerWe can regard PIMs as new kinds of reusable software components because they can be reused even if a platform is changed.

Page 6: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

6

But, …

Although MDA is effective for software development, it mainly focuses on platform-specific concerns.

We have to modify models when we face evolution related to other kinds of concerns including application-specific optimization, security policies, and deployment.

It is necessary to allow a modeler to customize transformation rules because model modifications for dealing with these concerns may be specific to an application.

Multiple concernsMultiple concerns

ExtensibilityExtensibility

Page 7: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

7

Motivating example -- A simple bulletin board system

Page 8: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

8

ExampleOriginal Platform

ConcernOptimization

Concern

make a product that is executable on the Struts platform

optimize memory usage

logging

add a logging function for debugging

logging

modifications crosscut over many places

LoggingConcern

delete

application-specific

Page 9: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

9

Our Approach We propose a method for constructing an extensible

model compiler based on aspect-orientation. Aspect-orientation is useful for platform descriptions

because they crosscut over many model elements. A modeler can extend model transformation rules by

defining new aspects in the process of modeling.

AspectAspect

UML modelUML model weaveweave

Extensible model compilerExtensible model compiler

UML modelUML model

AspectAspect

UML modelUML model

UML modelUML model

PIM PSM

AspectM

Page 10: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

10

2. AspectM

Page 11: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

11

Aspect orientation

AOP is based on the JPM (Join Point Model).

Join pointJoin point

PointcutPointcut

AdviceAdvice

program execution points including method invocations and field access points

a means of extracting a set of join points related to a specific crosscutting concern from all join points

a means of raising effects at the join points

Page 12: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

12

Aspect orientationat the modeling-level (example)

classA

attributes

operationsclassB

attributes

operationsclassC

attributes

operations

join point

(class) classA || classB(extract join point whose name is classA or classB)

pointcut classA

attributesnew attributes

operationsnew

operations

adviceadd new attributesadd new operations

Extension of JPMs (Join Point Models) in AOP

classB

attributesnew attributes

operationsnew

operations

join point

(class) join point

(class)

Page 13: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

13

JPMs for model transformationsJPM Join point Pointcut Advice

PA operation

Example 1) setX || setY 2) set* 3) classA ||

classB   4) class*

before,after,around

CM class merge-by-name

NE class-diagram add-classdelete-class

OC class add-operation,delete-operation,add-attribute,delete-attribute

RN class, operation, attribute

rename

RL class add-inheritance,delete-inheritance,add-aggregation,delete-

aggregation,add-relationship,delete-relationship

PA ( pointcut & advice ), CM ( composition ), NE ( new element ), OC ( open class ), RN ( rename ),RL ( relation )

Page 14: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

14

AspectM

AspectM is an aspect-oriented modeling language that supports six kinds of JPMs.

In AspectM, an aspect can be described in either a diagram or an XML format.

AspectM provides the two kinds of aspects: ordinary aspect and component aspect. A component aspect is a special aspect for composing aspects.

An aspect can have parameters for supporting generic facilities. By filling parameters, an aspect for a specific purpose is generated.

Page 15: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

15

Example of AspectM descriptions

<< OC >>addAttributeX

classeAandB : class { pointcut-body=“cname(classA) || cname(classB)” }

merge [classAandB] : add-attribute { advice-body=“attributeX” }

aspect

<aspect name=“addAttributeX” type=“ordinary” jpm=“OC" > <pointcut name=“classeAandB” type=“class”> <pointcut-body> cname(classA) || cname(classB) </pointcut-body> </pointcut> <advice name=“add-attributeX” type=“add-attribute” ref-

pointcut=“classAandB”> <advice-body> attributeX </advice-body> </advice></aspect>

classA

classB

classC

classA

newattributes

advice

add newattributes

pointcutclassA || classB

classB

newattributes

Page 16: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

16

AspectM Tools

UML diagrams

Aspect diagrams

Model Editor (Eclipse UML)

AspectMmetamodel

(EMF)

XMI (PIM)

XMIXSLT style sheet

XMI (PSM)

XSLT style sheet

Java code

Model Compiler

Page 17: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

17

AspectM metamodel

Page 18: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

18

Implementation of model compilerAspect diagram

(XML)

XSLT processorXSLT style sheet

forconverting aspect (XML)

to XSLT style sheetXSLT style sheet

forconverting UML (XML) to UML (XML)

UML diagram (XML)

XSLT processor(Weaver)

UML diagram (XML)

The firsttransformation phase

The secondtransformation phase

Model Compiler

Page 19: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

19

3. Model compiler construction using AspectM

Page 20: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

20

Application-specific model compiler

UML modelUML model

Weaver(XSLT processor)

Weaver(XSLT processor)

UML modelUML model

UML modelUML model

UML modelUML model

AspectAspect

Aspect Aspect

Aspect

Aspect

Extended application-specificmodel compiler

Page 21: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

21

ExampleOriginal Platform

ConcernOptimization

Concern

make a product that is executable on the Struts platform

optimize memory usage

logging

add a logging function for debugging

logging

LoggingConcern

delete

application-specific

Page 22: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

22

Aspect for platform concern

<< CM >>MergeClasses

inputClasses : class { pointcut-body=“cname(Message) || cname(MessageProfile)” }

merge [inputClasses] : merge-by-name { advice-body=“PostMessage” }

aspectStep1: merge PIMsStep1: merge PIMs

Step 2: transform the merged classto an action form bean class

Step 2: transform the merged classto an action form bean class

1) merge PIM classes

2) change the name of merged class3) inherit ActionForm4) add setter/getter

Platform: Struts

Page 23: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

23

Component, Generics<aspect name="Generic-Classes2ActionFormBean" type="component">

<params> <param> @input-classes@ </param> <param> @merged-class@ </param> </params>

<aspect name="MergeClasses" template="Generic-MergeClasses"> <set-param name="@input-classes@"> @input-classes@ </set-param> <set-param name="@merged-class@"> @merged-class@ </set-param> </aspect>

<aspect name="SetActionFormBeanName" template="Generic-SetActionFormBeanName"> <set-param name="@class@"> @merged-class@ </set-param> </aspect>

<aspect name="InheritActionForm" template="Generic-InheritActionForm"> <set-param name="@sub-class@">concat( @merged-class@ ,"Form")</set-param> </aspect>

<aspect name="AddAccessors" template="Generic-AddAccessors"> <set-param name="@class@">concat( @merged-class@ ,"Form")</set-param> </aspect>

</aspect>

Step1

Step2

component

generics

Page 24: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

24

Aspect for optimization concern

<aspect name="DeleteAttribute" type="ordinary" jpm="OC"> <pointcut name="postMessageClass" type="class"> <pointcut-body> cname(PostMessage) </pointcut-body> </pointcut> <advice name="deleteDate" adviceType="delete-attribute" ref-pointcut="postMessageClass"> <advice-body> date </advice-body> </advice></aspect>

<< OC >>DeleteAttribute

postMessageClasse : class { pointcut-body=“cname(PostMessage)” }

merge [postMessageClasse] :delete-attribute { advice-body=“date” }

aspect

Page 25: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

25

Aspect for logging concern

<aspect name="LoggingSetter" type="ordinary" jpm="PA"> <pointcut name="allSetter" type="method"> <pointcut-body> oname(set*)</pointcut-body> </pointcut> <advice name="logSetter" adviceType="before" ref-pointcut="allSetter"> <advice-body> Log.write() </advice-body> </advice></aspect>

<< PA >>LoggingSetter

allSetter : method { pointcut-body=“oname(set*)” }

merge [allSetter] : before { advice-body=“Log.write()” }

aspect

Page 26: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

26

Towards product-line engineering

Aspects are useful for product-line engineering in which avariety of PSMs are generated from a single set of PIMs.

Aspect library

for .NETAspect libraryfor J2EE

Aspect libraryfor other platforms

:

Aspect libraryfor product-

line BAspect libraryfor product-

line A

Aspect libraryfor other product-lines

:

Application-specificaspects

UML diagrams

defined by modelers

Application-specificaspects

UML diagrams

Product X

Product Y

weave

weave

Page 27: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

27

4. Discussion

Page 28: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

28

Scalability ?

Aspect libraries that support de facto standard platforms such as J2EE and .NET.

Aspect libraries that support platform-independent model transformations commonly applied to many applications.

It is not realistic for a modeler to define all of the aspects needed to construct a model compiler from scratch.

① fusion of classes having certain kinds of patterns

② generation of setter/getter methods③ change of naming conventions

Page 29: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

29

Are six JPMs enough ?

It is still not clear whether all kinds of model transformations can be described by the six JPMs.

We think that there are situations for which new kinds of JPMs must be introduced.

It would be better if a modeler can modify the AspectM metamodel using the model editor.

This function can be considered as a modeling-level reflection, a kind of compile-time reflection.

Page 30: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

30

Is AspectM really AOP language ?

AspectM can describe not only model transformation concerns but also ordinary crosscutting concerns such as logging.

AspectM unifies (lightweight) meta-programming with ordinary aspect-orientation by extending the idea of JPMs.

aspect-orientation

lightweightmeta-programming

JPMs

Someone might claim that AspectM is not an aspect-oriented language but a meta language for model transformations.

Page 31: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

31

5. Related work

Page 32: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

32

Related workAspect-oriented domain modeling (AODM) [J. Gray et. al. 2003]

AODM introduced a language called ECL that provides facilities for adding model elements such as attributes and relations.

In Draco, software development processes were considered as a series of transformations.

Draco [J. Neighbors 1984]

Persistence as an Aspect [A.Rashid and R.Chitchyan 2003]Aspect-oriented mechanisms (+ reflection) for describing database concerns are proposed.

QVT [OMG]QVT (Queries, Views, and Transformations) is a model transformation language.

Page 33: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

33

6. Conclusion

Page 34: 1 Model Compiler Construction Based on Aspect-oriented Mechanisms Naoyasu Ubayashi (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo)

34

Conclusion

We proposed a method for constructing an extensible model compiler that can deal with application-specific model transformations.

A modeler can extend model transformation rules by defining new aspects in the process of modeling.