EMF校验框架

EMF提供了两类三种方式来校验EMF模型。

1> EMF ECore规则校验

2> Live校验

3> Batch校验

 

· EMF校验代码

这里用到的代码可以在EMF提供的例子中查看到。Example->EMF Validation Framework Plug-ins->General Validation Example)

 

· EMF ECore规则校验

    主要由org.eclipse.emf.ecore.util.EObjectValidator来完成,主要校验EFeature和EAttribute(EXTLibraryPackageImpl.initializePackageContents())

    或者,通过EOperation/EAnnotation添加操作来实现自定义[1]的校验。

 

    如果在Ecore中设置的属性,需要有特殊的考虑,可以通过实现自定义的EValidator来代替EMF默认的EObjectValidator。注册方式如下:

    // Register package validator
    EValidator.Registry.INSTANCE.put
      (theEcorePackage, 
       new EValidator.Descriptor()
       {
         public EValidator getEValidator()
         {
           return EcoreValidator.INSTANCE;
         }
       });

 

可以通过下面两种方式来注册:

1) 在初始化ModelPackage时实现: org.eclipse.emf.ecore.impl.EcorePackageImpl.init()

2) 通过StartUp扩展点来实现: org.eclipse.ui.startup [2]

 

· Batch模型校验 & Live实时校验 [3][4]

    主要是通过扩展点来注册,实现AbstractModelConstraint(#validate)校验类,并把该类添加到扩展点的constraint节点上:

 

需要注意的是,constraintProvider的package的Uri需要和模型中的package-uri对应。如图所示:

 

参考文章:

[1] 八进制-模型的验证 http://www.cnblogs.com/bjzhanghao/archive/2006/08/09/472607.html

官方EMF Validation Overview http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.emf.doc%2Freferences%2Foverview%2FEMF.Validation.html

[2] EMF Validation Adapter http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html

[3] 使用 EMF Validation 框架来验证 EMF 模型 http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-emfvldt/index.html

Validator Service http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html

[4] Live校验 http://cutesunshineriver.iteye.com/blog/1186298

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值