2013年3月1日金曜日

ecoreのオペレーションの実装について

EMFでecoreにeOperationを定義する際に、ソースコード生成を行うと、以下のように
UnsupportedOperationException()を返してしまう。

  1. /** 
  2.  * <!-- begin-user-doc --> 
  3.  * <!-- end-user-doc --> 
  4.  * @generated 
  5.  */  
  6. public void sample() {  
  7.  // TODO: implement this method  
  8.  // Ensure that you remove @generated or mark it @generated NOT  
  9.  throw new UnsupportedOperationException();  
  10. }  
これのデフォルト実装を行うためにはeOperationに対してeannotationを設定する必要がある。

  1. <eannotations source="http://www.eclipse.org/emf/2002/GenModel">  
  2.   <details key="body" value="return (rentBookRefered == null ) ? true : false;">  
  3. </details></eannotations>  

対応方法は

  • eannotation
    • 属性名:source
      • 値http://www.eclipse.org/emf/2002/GenModel
  • detailタグ
    • 属性名:key
      • 値:body
    • 属性名:value
      • operationの実装


これでデフォルトの実装が出力される。
これにより、モデルですべて実装まで定義できるようになります。