2022年1月31日月曜日

Cozy

Modegramming Styleブログではモデリングとプログラミングの一体化を指向したModegrammingというコンセプトを提唱しており、その実現のための技術体系としてSimpleModelingを整備しています。

プロダクト

ちょうど一年前の記事「SimpleModeling」では、このSimpleModelingの技術体系の構成要素である以下の4つのプロダクトの開発について説明しました。ちょうど一年前の記事「SimpleModeling」では、このSimpleModelingの技術体系の構成要素である以下の4つのプロダクトの開発について説明しました。

SmartDox
文書処理系
SimpleModeler
モデルコンパイラ
Kaleidox
アクション言語
Arcadia
Webフレームワーク

この中で、この一年は特にアクション言語であるKaleidoxの開発を進めてきました。

開発方法論

7月からオブジェクト指向開発方法論の講座を始めました。

UML(Unified Modeling Language)/UP(Unified Process)の基本を押さえつつ、オブジェクト指向開発方法論の現在地を整理する目的です。

その上で、最終的には上記のプロダクトを活用したモデル駆動開発と連携できればと考えています。

Cozy

Kaleidoxの開発も順調に進んできたので、Kaleidox, SmartDox, SimpleModeler, Arcadiaを統合した、モデル駆動開発のワークベンチとして新たなプロダクトCozyを立ち上げました。

モデルコンパイラにアクション言語、文書処理系、Webフレームワークを統合し連携することでより有効な活用を行うことができるでしょう。

状態機械図

Kaleidox, SmartDox, SimpleModeler, Arcadiaを統合することにより、KaleidoxからSimpleModelerのモデル生成機能などを直接使用できるようになりました。

今回はSimpleModelerの持つ状態機械図生成機能を使ってKaleidox上の状態機械モデルの状態機械図を生成してみます。

状態機械

まず「Kaleidox/状態機械:ヒストリー」で使用した状態機械の状態機械図を生成します。

以下のモデルでは状態機械purchaseを定義しています。

  1. * event  
  2. event=[{  
  3.     name="confirm"  
  4.   },{  
  5.     name="reject"  
  6.   },{  
  7.     name="delivered"  
  8.   },{  
  9.     name="cancel"  
  10.   },{  
  11.     name="suspend"  
  12.   },{  
  13.     name="resume"  
  14. }]  
  15. * statemachine  
  16. statemachine={  
  17.   name="purchase"  
  18.   state=[{  
  19.     name=INIT  
  20.     transition=[{  
  21.       to=running  
  22.     }]  
  23.   },{  
  24.     name=canceled  
  25.     transition=[{  
  26.       to=FINAL  
  27.     }]  
  28.   },{  
  29.     name=suspended  
  30.     transition=[{  
  31.       guard=resume  
  32.       to=HISTORY  
  33.     }]  
  34.   }]  
  35.   statemachine=[{  
  36.     name="running"  
  37.     state=[{  
  38.       name=applying  
  39.       transition=[{  
  40.         to=confirming  
  41.       }]  
  42.     },{  
  43.       name=confirming  
  44.       transition=[{  
  45.         guard=confirm  
  46.         to=confirmed  
  47.       },{  
  48.         guard=reject  
  49.         to=rejected  
  50.       }]  
  51.     },{  
  52.       name=confirmed  
  53.       transition=[{  
  54.         to=delivering  
  55.       }]  
  56.     },{  
  57.       name=rejected  
  58.       transition=[{  
  59.         to=FINAL  
  60.       }]  
  61.     },{  
  62.      name=delivering  
  63.       transition=[{  
  64.         guard=delivered  
  65.         to=delivered  
  66.       }]  
  67.     },{  
  68.       name=delivered  
  69.       transition=[{  
  70.         to=FINAL  
  71.       }]  
  72.     }]  
  73.     transition=[{  
  74.       guard=cancel  
  75.       to=canceled  
  76.     },{  
  77.       guard=suspend  
  78.       to=suspended  
  79.     }]  
  80.   }]  
  81. }  

statemachine-diagram関数で上記の状態機械purchaseから状態機械図を生成します。

  1. cozy> statemachine-diagram 'purchase  
  2. Image  

画像をviewコマンドで表示します。Kaleidox上で定義した状態機械の状態機械図として表示することができました。

  1. cozy> :view  

エンティティ

次は「Kaleidox状態機械/エンティティの状態遷移」で使用した状態機械を持つエンティティです。

エンティティsalesorderが状態機械statusを持っています。

  1. * event  
  2. event=[{  
  3.     name="confirm"  
  4.   },{  
  5.     name="reject"  
  6.   },{  
  7.     name="delivered"  
  8.   },{  
  9.     name="cancel"  
  10.   },{  
  11.     name="suspend"  
  12.   },{  
  13.     name="resume"  
  14. }]  
  15. * entity  
  16. ** salesorder  
  17. *** features  
  18. table=salesorder  
  19. *** attributes  
  20. | Name | Type  | Multiplicity |  
  21. |------+-------+--------------|  
  22. | id   | token |            1 |  
  23. | price| int   |            1 |  
  24. *** statemachines  
  25. **** status  
  26. state=[{  
  27.   name=INIT  
  28.   transition=[{  
  29.     to=running  
  30.   }]  
  31. },{  
  32.   name=canceled  
  33.   transition=[{  
  34.     to=FINAL  
  35.   }]  
  36. },{  
  37.   name=suspended  
  38.   transition=[{  
  39.     guard=resume  
  40.     to=HISTORY  
  41.   }]  
  42. }]  
  43. statemachine=[{  
  44.   name="running"  
  45.   state=[{  
  46.     name=applying  
  47.     transition=[{  
  48.       to=confirming  
  49.     }]  
  50.   },{  
  51.     name=confirming  
  52.     transition=[{  
  53.       guard=confirm  
  54.       to=confirmed  
  55.     },{  
  56.       guard=reject  
  57.       to=rejected  
  58.     }]  
  59.   },{  
  60.     name=confirmed  
  61.     transition=[{  
  62.       to=delivering  
  63.     }]  
  64.   },{  
  65.     name=rejected  
  66.     transition=[{  
  67.       to=FINAL  
  68.     }]  
  69.   },{  
  70.    name=delivering  
  71.     transition=[{  
  72.       guard=delivered  
  73.       to=delivered  
  74.     }]  
  75.   },{  
  76.     name=delivered  
  77.     transition=[{  
  78.       to=FINAL  
  79.     }]  
  80.   }]  
  81.   transition=[{  
  82.     guard=cancel  
  83.     to=canceled  
  84.   },{  
  85.     guard=suspend  
  86.     to=suspended  
  87.   }]  
  88. }]  

statemachine-diagram関数で上記のエンティティpurchaseが持っている状態機械statusの状態機械図を生成します。

  1. cozy> statemachine-diagram 'salesorder  
  2. Image  

画像をviewコマンドで表示します。こちらもKaleidox上で定義した状態機械の状態機械図として表示することができました。

状態機械モデルとしては前出のpurchaseと同じなので、同じ状態機械図になっています。

  1. cozy> :view  

まとめ

Kaleidoxの開発もいい感じに進み、Cozyの枠組みの中でSimpleModelerと連携して状態機械図を生成することができるようになりました。

今年はCozyの各種機能の連携を強化し、効果的なモデル駆動開発の環境づくりに取り組んでいきたいと思います。

諸元

Cozy
0.0.2