通过ECore创建EMF模型
来源:互联网 发布:小班美工材料投放图片 编辑:程序博客网 时间:2024/06/03 06:47
EMF作为Eclipse中的模型驱动架构(MDA)的框架,提供了非常强大的功能。
而EMF的开发又可以分为两部分,即模型创建与模型使用。本篇文章主要讲解如何创建模型。
假设我们模型如下:
转换到EMF中,他们的关系如下:
我们使用Ecore API来实现这个UML模型。
EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;EClass purchaseOrderClass = ecoreFactory.createEClass();purchaseOrderClass.setName("PurchaseOrder");EAttribute shipTo = ecoreFactory.createEAttribute();shipTo.setName("shipTo");shipTo.setType(ECorePackage.Literals.ESTRING);//使用ECore封装好的类型ESTRINGpurchaseOrderClass.getEStructuralFeatures().add(shipTo);EAttribute billTo = ecoreFactory.createEAttribute();billTo.setName("billTo");billTo.setType(ECorePackage.Literals.ESTRING);purchaseOrderClass.getEStructuralFeatures().add(billTo);EClass itemClass = ecoreFactory.createEClass();itemClass.setName("Item");EAttribute productName = ecoreFactory.createEAttribute();productName.setName("productName");productName.setType(ECorePackage.Literals.ESTRING);itemClass.getEStructuralFeatures().add(productName);EAttribute quantity = ecoreFactory.createEAttribute();quantity.setName("quantity");quantity.setType(ECorePackage.Literals.EINT);itemClass.getEStructuralFeatures().add(quantity);EAttribute price = ecoreFactory.createEAttribute();price.setName("price");price.setType(ECorePackage.Literals.EFLOAT);itemClass.getEStructuralFeatures().add(price);//设置引用EReference items = ecoreFactory.createEReference();items.setName("items");items.setEType(itemClass);//指向EClassitems.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);items.setContainment(true);purchaseOrderClass.getEStructuralFeatures().add(items);//添加到主类//创建packageEPackage poPackage = ecoreFactory.createEPackage();poPackage.setName("po");poPackage.setNsPrefix("po");poPackage.setNsURI(自己定义的地址);poPackage.getEClassifiers().add(purchaseOrderClass);poPackage.getEClassifiers().add(itemClass);至此,模型创建完毕。如何根据模型定义用戶層,请见下一篇文章
0 0
- 通过ECore创建EMF模型
- EMF-Ecore模型创建
- EMF-Ecore模型概述
- EMF动态ECORE
- 根据ECore元模型创建模型
- org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'taglib' not found
- 使用 EMF Query 查询 EMF 模型
- EMF模型保存时加密
- EMF
- EMF模型解析的策略分析
- 用动态 EMF 构建元模型
- 使用EMF持久化和WTP持久化EMF对象两种方案的模型区别
- 脱离eclipse的插件环境使用EMF模型
- 构建 Eclipse 插件在 EMF 模型中浏览内容
- 构建Eclipse插件在EMF模型中浏览内容
- 脱离eclipse的插件环境使用EMF模型
- 脱离eclipse的插件环境使用EMF模型
- 脱离eclipse的插件环境使用EMF模型
- LiveCD、LiveDVD和BinDVD区别在哪里
- 不同风格的网页登录界面设计学习
- Clojure实现的简单短网址服务(Compojure、Ring、Korma库示例)
- Cocos2dx 3.x多点触控问题
- Spring REST
- 通过ECore创建EMF模型
- “码农”刍议
- LeetCode 143. Reorder List
- 苹果会「抢跑」发布iPhone 6吗?
- 这些程序执行操作程序支持下载
- 模型驱动架构 (MDA)
- linux命令
- LeetCode 141. Linked List Cycle
- 给自己找了个写博客的理由