n n MIC ModelIntegrated Computing AOP AspectOriented Programming

  • Slides: 57
Download presentation

解決方法 n n MIC (Model-Integrated Computing) AOP (Aspect-Oriented Programming) IP (Itentional Programming) Gen. Voca

解決方法 n n MIC (Model-Integrated Computing) AOP (Aspect-Oriented Programming) IP (Itentional Programming) Gen. Voca 今日はアスペクト指向について紹介 アスペクト指向と絡めて、MDA、MICについて紹介 13

アスペクト指向を実現する 言語処理系、システム n n n n Aspect. J (Gregor Kiczales, et al. ) Hyper/J,

アスペクト指向を実現する 言語処理系、システム n n n n Aspect. J (Gregor Kiczales, et al. ) Hyper/J, CME (Harold Ossher, et al. ) Demeter. J (Karl J. Lieberherr, et al. ) Composition filters (Mehmet Aksit, et al. ) Caesar (Mira Mezini, et al. ) JBoss-AOP Aspect. Werkz J2EE環境への適用が増えている! POJO(Plain Old Java Object) 今日はAspectJベースで紹介 15

AOPのメカニズム JPM(Join Point Model) aspect Public. Error. Logging { static Log log = new

AOPのメカニズム JPM(Join Point Model) aspect Public. Error. Logging { static Log log = new Log(); pointcut public. Interface (): target (mypackage. . *) && call (public * *(. . )); after() returning (Object o): public. Interface() { System. out. println(this. Join. Point); } after() throwing (Error e): public. Interface() { log. write(e); } メソッド呼び出し、 変数参照/更新など の実行点を捕まえる weaving } ログ処理コードの 埋め込み (advice) プログラム上の 様々な実行点 (join point) 実行点の取り出し (pointcut) 実行点の中から ログ処理に関わ る部分を抽出 17

簡単なAspectJプログラム アスペクト Hello. World. java public class Hello. World { public static void main

簡単なAspectJプログラム アスペクト Hello. World. java public class Hello. World { public static void main ( String [], args) { Hello. World app = new Hello. World (); app. hello(); } Trace. java インタータイプ 定義 public aspect Trace { private String Hello. World. mes = “トレース”; ポイントカット public pointcut at. Hello() : call (void Hello. World. hello()); void hello() { System. out. println(“こんにちは!”); } before(Hello. World h) : at. Hello() && target(h) { System. out. println(h. mes + “呼び出し前”); } } after(Hello. World h) : at. Hello() && target(h) { System. out. println(h. mes + “呼び出し後”); } } アドバイス 「Aspect. Jによるアスペクト指向プログラミング入門」 長瀬、天野、鷲崎、立堀(著) より 19

例題: 簡易図形エディタ Display * Figure. Element Figure make. Point(. . ) make. Line(. .

例題: 簡易図形エディタ Display * Figure. Element Figure make. Point(. . ) make. Line(. . ) Point get. X() get. Y() set. X(int) set. Y(int) move. By(int, int) 2 Line get. P 1() get. P 2() set. P 1(Point) set. P 2(Point) move. By(int, int) operations that move elements Aspect. J. http: //eclipse. org/aspectj/より抜粋 20

通常の保守、改良 class Line { private Point p 1, p 2; Point get. P 1()

通常の保守、改良 class Line { private Point p 1, p 2; Point get. P 1() { return p 1; } Point get. P 2() { return p 2; } void set. P 1(Point p 1) { this. p 1 = p 1; Display. update(this); } void set. P 2(Point p 2) { this. p 2 = p 2; Display. update(this); } } void set. P 2(Point p 2) { this. p 2 = p 2; } } } class Point { class Point private int x = 0, y = 0; int get. X() { return x; } int get. Y() { return y; } void set. X(int x) { this. x = x; Display. update(this); } void set. Y(int y) { this. y = y; Display. update(this); } } void set. Y(int y) { this. y = y; } } { 変更が複数の クラスに散らば ってしまう! } Aspect. J. http: //eclipse. org/aspectj/より抜粋 21

Aspect. Jによる保守、改良 class Line { aspect Display. Updating { private Point p 1, p

Aspect. Jによる保守、改良 class Line { aspect Display. Updating { private Point p 1, p 2; pointcut move(Figure. Element fig. Elt): target(fig. Elt) && (call(void Figure. Element. move. By(int, int) || call(void Line. set. P 1(Point)) || call(void Line. set. P 2(Point)) || call(void Point. set. X(int)) || call(void Point. set. Y(int))); Point get. P 1() { return p 1; } Point get. P 2() { return p 2; } void set. P 1(Point p 1) { this. p 1 = p 1; } void set. P 2(Point p 2) { this. p 2 = p 2; } after(Figure. Element fe) returning: move(fe) { Display. update(fe); } } class Point { } private int x = 0, y = 0; int get. X() { return x; } int get. Y() { return y; } void set. X(int x) { this. x = x; } void set. Y(int y) { this. y = y; } 変更が1つのアスペクトに局所化される! } Aspect. J. http: //eclipse. org/aspectj/より抜粋 22

クラスを横断するアスペクト Display * Figure. Element Figure make. Point(. . ) make. Line(. . )

クラスを横断するアスペクト Display * Figure. Element Figure make. Point(. . ) make. Line(. . ) Point get. X() get. Y() set. X(int) set. Y(int) move. By(int, int) 2 Line get. P 1() get. P 2() set. P 1(Point) set. P 2(Point) move. By(int, int) Display. Updating Aspect. J. http: //eclipse. org/aspectj/より抜粋 23

MDA実現のための鍵 n n 厳密なモデル表記 (MOF、OCL) 厳密なモデル変換定義 (QVT) QVTの例 mapping Simple_Class_To_Java_Class refine Simple_Class_And_Java_Class { domain

MDA実現のための鍵 n n 厳密なモデル表記 (MOF、OCL) 厳密なモデル変換定義 (QVT) QVTの例 mapping Simple_Class_To_Java_Class refine Simple_Class_And_Java_Class { domain {(SM. Class)[name = n, attributes = A] } body { (JM. Class)[ name = n, attributes = A->iterate(a as ={} | as + Simple_Attribute_To_Java_Attribute(a)) ] } } MOF: Meta Object Facility OCL: Object Constraint Language QVT: Queries, Views, and Transformations 31

我々の研究室での研究事例 アスペクト指向に基づく拡張可能なモデルコンパイラ Naoyasu Ubayashi, Tetsuo Tamai, Shinji Sano, Yusaku Maeno, Satoshi Murakami: Model Compiler

我々の研究室での研究事例 アスペクト指向に基づく拡張可能なモデルコンパイラ Naoyasu Ubayashi, Tetsuo Tamai, Shinji Sano, Yusaku Maeno, Satoshi Murakami: Model Compiler Construction Based on Aspect-Oriented Mechanisms, 4 th ACM SIGPLAN International Conference on Generative Programming and Component Engineering (GPCE 2005), to appear 35

モデルレベルのアスペクト指向 join point (class) class. A pointcut class. A || class. B) advice add

モデルレベルのアスペクト指向 join point (class) class. A pointcut class. A || class. B) advice add new attributes add new operations attributes class. A attributes new attributes operations new operations class. B join point (class) class. C attributes class. B attributes operations join point (class) 横断的関心事(プラット フォームなど)をモデル に挿入 new attributes operations new operations JPMの概念を拡張(通常のAspectJにおけるJPMとは異なる) 37

モデル変換のためのJPM(つづき) JPM Join point Pointcut PA operation before, after, around CM class merge-by-name NE

モデル変換のためのJPM(つづき) JPM Join point Pointcut PA operation before, after, around CM class merge-by-name NE class-diagram OC class RN class, operation, attribute rename RL class add-inheritance, delete-inheritance, add-aggregation, delete-aggregation, add-relationship, delete-relationship 39 記述例 ① set. X || set. Y ② set* ③ class. A || class. B ④ class* Advice add-class delete-class add-operation, delete-operation, add-attribute, delete-attribute

AspectMによるモデル記述 l6つのJPMをサポート(新たなJPMを追加可能) l3種類のアスペクトをサポート(通常アスペクト、コンポーネント アスペクト、テンプレートアスペクト) lUMLを対象としたXMLベースのAOP言語 ダイアグラム表記 aspect << jpm-type >> aspect-name pointcut-name : joinpoint-type

AspectMによるモデル記述 l6つのJPMをサポート(新たなJPMを追加可能) l3種類のアスペクトをサポート(通常アスペクト、コンポーネント アスペクト、テンプレートアスペクト) lUMLを対象としたXMLベースのAOP言語 ダイアグラム表記 aspect << jpm-type >> aspect-name pointcut-name : joinpoint-type { pointcut-body } : : advice-name [pointcut-name]: advice-type { advice-body } : : ダイアグラム保存形式(XMLベース) <aspect name=aspect-name type=jpm-type > { <pointcut name=pointcut-name type=joinpoint-type> pointcut-body </pointcut> } + { <advice name=advice-name type=advice-type ref-pointcut=pointcut-name </advice> <advice-body>advice-body </advice-body> </advice> } + </aspect> 40

Aspect. M 支援ツール Model Editor (Eclipse UML) Model Compiler UML diagrams XMI (PIM) Aspect

Aspect. M 支援ツール Model Editor (Eclipse UML) Model Compiler UML diagrams XMI (PIM) Aspect diagrams XMI XSLT style sheet Aspect. M metamodel (EMF) XMI (PSM) XSLT style sheet Java code 41

Model-Integrating Computing (MIC) n n n Vanderbilt Univ. のISIS(Institute for Software Integrated Systems)で研究開発。 ドメイン専用モデリング環境を提供。

Model-Integrating Computing (MIC) n n n Vanderbilt Univ. のISIS(Institute for Software Integrated Systems)で研究開発。 ドメイン専用モデリング環境を提供。 アスペクト指向への応用は、J. Gray (現在、Univ. of Alabama )が研究。AODM(Aspect-Oriented Domain Modeling)を提案。 45

Model-integrated approach to software composition [出典] Janos Sztipanovits and Gabor Karsai: Generative Programming for

Model-integrated approach to software composition [出典] Janos Sztipanovits and Gabor Karsai: Generative Programming for Embedded Systems, GPCE 2002, LNCS 2487, pp. 32 --49, 2002 46

Meta-modeling language architecture 適用例 [出典] Janos Sztipanovits and Gabor Karsai: Generative Programming for Embedded

Meta-modeling language architecture 適用例 [出典] Janos Sztipanovits and Gabor Karsai: Generative Programming for Embedded Systems, GPCE 2002, LNCS 2487, pp. 32 --49, 2002 47

AOSD ソフト開発 程全体への波及 AOP(Aspect-Oriented Programming) から AOSD(Aspect-Oriented Software Development) へ AO: Aspect-Oriented 要求分析 Early

AOSD ソフト開発 程全体への波及 AOP(Aspect-Oriented Programming) から AOSD(Aspect-Oriented Software Development) へ AO: Aspect-Oriented 要求分析 Early Aspect 設計 AO Design Pattern AO Modeling Aspect Mining AO Framework 実装 AO Language AO Component AO Database 50

アスペクト指向に関する情報源 ポータルサイト http: //aosd. net 国際会議 Aspect-Oriented Software Development (AOSD) OOPSLA, ECOOP, GPCE, ICSE,

アスペクト指向に関する情報源 ポータルサイト http: //aosd. net 国際会議 Aspect-Oriented Software Development (AOSD) OOPSLA, ECOOP, GPCE, ICSE, FSE, ICFP など 53

最近の主な研究 Naoyasu Ubayashi and Tetsuo Tamai: Aspect-Oriented Programming with Model Checking, 1 st International

最近の主な研究 Naoyasu Ubayashi and Tetsuo Tamai: Aspect-Oriented Programming with Model Checking, 1 st International Conference on Aspect-Oriented Software Development (AOSD 2002) Kouhei Sakurai, Hidehiko Masuhara, Naoyasu Ubayashi, Saeko Matsuura, and Seiichi Komiya: Association aspects, 3 rd International Conference on Aspect-Oriented Software Development (AOSD 2004) Tetsuo Tamai, Naoyasu Ubayashi, and Ryoichi Ichiyama: An Adaptive Object Model with Dynamic Role Binding, 27 th IEEE/ACM International Conference on Software Engineering (ICSE 2005) Naoyasu Ubayashi, Tetsuo Tamai, Shinji Sano, Yusaku Maeno, Satoshi Murakami: Model Compiler Construction Based on Aspect-Oriented Mechanisms, 4 th ACM SIGPLAN International Conference on Generative Programming and Component Engineering (GPCE 2005), to appear Naoyasu Ubayashi, Genki Moriyama, Hidehiko Masuhara, and Tetsuo Tamai: A Parameterized Interpreter for Modeling Different AOP Mechanisms, 20 th IEEE/ACM International Conference on Automated Software Engineering (ASE 2005), to appear 55

現在進行形の研究 n n Weaving by Contract Generator for AO Refactorings Class-based AOP Language Reflective

現在進行形の研究 n n Weaving by Contract Generator for AO Refactorings Class-based AOP Language Reflective AOP Language 56