ecore模型分析
目前生成ecore模型主要由四种途径,如图:
这里我们采用从UML Model产生ecore模型,首先用Rose设计包emf,然后在包中新建如下类图:
生成的ecore模型如下
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="emf"
nsURI="http:///emf.ecore" nsPrefix="emf">
<eClassifiers xsi:type="ecore:EClass" name="Customer" eSuperTypes="#//Element">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="orders" upperBound="-1"
eType="#//Order" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Order" eSuperTypes="#//Element">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="price" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bool" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
</ecore:EPackage>
下面我们就来分析一下这个文件:
EPackage
eocre模型的顶层元素是EPackage,它和UML Model中的包(Package)匹配;
EPackage的nsURI和nsPrefix属性不能在UML Model中直接表示出来,这些属性的缺省值都是自动根据Package的名称产生;
EPackage的name属性和UML Model中Package的名称是一样的;
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="emf"
nsURI="http:///emf.ecore" nsPrefix="emf">
...
</ecore:EPackage>
EClass,EEnum,EDataType
UML Model中类(Class)和可以匹配EClass,EEnum,EDataType,具体匹配哪个,取决于类的版型(stereotype)。
l 如果UML中的类的版型为空或者为Interface,则匹配EClass;
l 如果UML中的类的版型为enumeration,则匹配EEnum;
l 如果UML中的类的版型为datatype,则匹配EDataType;
在我们的UML Model中,类Customer的版型为空,所以匹配EClass。
<eClassifiers xsi:type="ecore:EClass" name="Customer">
...
</eClassifiers>
类的名称就是name属性,
<eClassifiers xsi:type="ecore:EClass" name="Customer">
...
</eClassifiers>
如果这个类有父类,可以在属性eSuperTypes指定:
<eClassifiers xsi:type="ecore:EClass" name="Customer" eSuperTypes="#//Element">
...
</eClassifiers>
如果是抽象类,abstract属性为true,默认值为false
<eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true">
...
</eClassifiers>
如果类的版型是interface,interface属性为true,默认值为false
EAttribute 和EReference
UML 类中的每个属性和EAttribute匹配
UML中属性的name和EAttribute的name一样。
EAttribute 的eType属性来源于UML中属性的类型,这个类型必须是一个基本的 Java 类型,或者是在UML Model中定义的 EEnum 或者 EDataType。l.
UML类中每个有箭头的关联(navigable association)和Ereference匹配
<eStructuralFeatures xsi:type="ecore:EReference" name="orders" upperBound="-1"
eType="#//Order" containment="true"/>
EReference的lowerBound 和 upperBound属性值来自于UML 关联的阶元(multiplicty)。例如, 假如你指定阶元是 0..1,则属性lowerBound 是0 ,而 upperBound 是 1,假如阶元是 0..n, 则属性lowerBound 是 0 而upperBound 是 -1 (unbounded)。
如果UML 关联是聚合并且目标类的containment 是"by value",则EReference 的containment 属性为true ,缺省是false。
eOperations
在UML类图中每个操作和eOperations匹配,例如如果在Customer增加name的get和set方法,如图:
ecore模型的代码如下:
name属性对应着操作名,eType属性对应着操作返回值类型。
<eOperations name="setName">
<eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
eParameters子元素对应着操作的参数,它的name属性对应参数的名字,eType属性对应着参数类型。
分享到:
相关推荐
Eclipse Modeling Framework (EMF)是Eclipse 的一个基于Java语言的模型构建框架,它通过提供通用 的模型框架和自动代码生成工具,极大地简化了基于结 构化模型的Eclipse插件或者应用程序的开发
创建动态内存内核模型序列化动态模型反序列化/装载动态模型限制结束语下载参考资料通过本文可以了解如何使用DynamicEclipseModelingFramework(EMF)在不生成Java实现类的情况下根据需要构建动态的基于Ecore的模型。...
基于Eclipse的模型框架 它是Eclipse MDA(Model Driven Architecture)的一个重要组成部分 是Eclipse中许多项目的基础 e g GEF EMF可以将模型转换成高效的 正确的 和易于定制的Java代码
分析EMF文件结构的工具,包含源代码。对于EMF文件的编码操作有很高的知道作用
模型二分类.emf
NULL 博文链接:https://winseclone.iteye.com/blog/1797563
它是Eclipse MDA(Model Driven Architecture)的一个重要组成部分,是Eclipse中许多项目的基础( e.g, GEF), EMF可以将模型转换成高效的,正确的,和易于定制的Java代码。EMF项目的最初目标是要实现OMG(Object ...
emf文件是windows的一种打印格式,该资源可以对emf文件进行文本提取和推送打印机打印以及转换成图像
通过对123种不同的,较早发表的生物医学研究进行荟萃分析,分析了100种不同的EMF频率数据,揭示了这两种观察结果。 所研究的EM频率显示了12个有益(抗癌)频率和12个有害(促癌)频率的分形模式,形成了更广泛的自...
EMF读取XML
包含3个文件: 微软emf文件格式详解.pdf emf.hlp (Enhanced Metafiles in Win32) emfexplorer_src.zip
EMF 自学笔记
使用freehep将EMF转换为png,项目下载导入eclipse即可运行。
This is the API specification of the FreeHEP VectorGraphics package for converting emf to svg.
文件格式 EMF (Enhanced MetaFile) ——是在印刷工业中应用与Windows操作系统的文件格式。实际上EMF是原始WMF(Windows metafile)格式的32位版本。EMF格式的产生是为了解决WMF在印刷行业中的不足。EMF是设备独立性...
矢量格式转换程序,基于JAVA实现的SVG转EMF的的示例代码,下载后导入到eclipse即可运行。
emf转bmpemf
EMF-IncQuery-附加组件模型查询框架。 该存储库中的所有代码都可以在Eclipse Public License v1.0下获得: :
详细讲述了emf和gef的用法,和模型开发过程,有很多实例的