`
yiliner
  • 浏览: 211181 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

EMF中的ecore模型分析

    博客分类:
  • EMF
阅读更多
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)匹配;
 
EPackagensURInsPrefix属性不能在UML Model中直接表示出来,这些属性的缺省值都是自动根据Package的名称产生;
 
EPackagename属性和UML ModelPackage的名称是一样的;
<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)和可以匹配EClassEEnumEDataType,具体匹配哪个,取决于类的版型(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>
如果类的版型是interfaceinterface属性为true,默认值为false
 
EAttribute 和EReference
UML 类中的每个属性和EAttribute匹配
 
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
 
UML中属性的name和EAttribute的name一样。
 
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
 
EAttribute 的eType属性来源于UML中属性的类型,这个类型必须是一个基本的 Java 类型,或者是在UML Model中定义的 EEnum 或者 EDataType。l.
 
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
 
UML类中每个有箭头的关联(navigable association)和Ereference匹配
<eStructuralFeatures xsi:type="ecore:EReference" name="orders" upperBound="-1"
        eType="#//Order" containment="true"/>
 
EReferencelowerBound 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模型的代码如下:
<eOperations name="getName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
 
name属性对应着操作名,eType属性对应着操作返回值类型。
 
<eOperations name="setName">
      <eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eOperations>
 
eParameters子元素对应着操作的参数,它的name属性对应参数的名字,eType属性对应着参数类型。
 

 

 

分享到:
评论

相关推荐

    使用EMF开发基于模型的Eclipse插件

    Eclipse Modeling Framework (EMF)是Eclipse 的一个基于Java语言的模型构建框架,它通过提供通用 的模型框架和自动代码生成工具,极大地简化了基于结 构化模型的Eclipse插件或者应用程序的开发

    用动态EMF构建元模型

    创建动态内存内核模型序列化动态模型反序列化/装载动态模型限制结束语下载参考资料通过本文可以了解如何使用DynamicEclipseModelingFramework(EMF)在不生成Java实现类的情况下根据需要构建动态的基于Ecore的模型。...

    EMF for Eclipse 4.4插件

    基于Eclipse的模型框架 它是Eclipse MDA(Model Driven Architecture)的一个重要组成部分 是Eclipse中许多项目的基础 e g GEF EMF可以将模型转换成高效的 正确的 和易于定制的Java代码

    分析EMF文件的工具以及源代码

    分析EMF文件结构的工具,包含源代码。对于EMF文件的编码操作有很高的知道作用

    模型二分类.emf

    模型二分类.emf

    EMF模型文件对比/比较(emf.compare)

    NULL 博文链接:https://winseclone.iteye.com/blog/1797563

    emf-sdo-runtime-2.2.0.zip

    它是Eclipse MDA(Model Driven Architecture)的一个重要组成部分,是Eclipse中许多项目的基础( e.g, GEF), EMF可以将模型转换成高效的,正确的,和易于定制的Java代码。EMF项目的最初目标是要实现OMG(Object ...

    EMF文件提取文本,预览,打印

    emf文件是windows的一种打印格式,该资源可以对emf文件进行文本提取和推送打印机打印以及转换成图像

    论文研究 - 癌症中有利和不利的EMF频率模式:改善治疗和预防的观点

    通过对123种不同的,较早发表的生物医学研究进行荟萃分析,分析了100种不同的EMF频率数据,揭示了这两种观察结果。 所研究的EM频率显示了12个有益(抗癌)频率和12个有害(促癌)频率的分形模式,形成了更广泛的自...

    EMF读取XML

    EMF读取XML

    emf文件格式详解

    包含3个文件: 微软emf文件格式详解.pdf emf.hlp (Enhanced Metafiles in Win32) emfexplorer_src.zip

    EMF 自学笔记5

    EMF 自学笔记

    将EMF图片格式转换成PNG

    使用freehep将EMF转换为png,项目下载导入eclipse即可运行。

    emf2svg-FreeHEP

    This is the API specification of the FreeHEP VectorGraphics package for converting emf to svg.

    微软emf文件格式详解

    文件格式 EMF (Enhanced MetaFile) ——是在印刷工业中应用与Windows操作系统的文件格式。实际上EMF是原始WMF(Windows metafile)格式的32位版本。EMF格式的产生是为了解决WMF在印刷行业中的不足。EMF是设备独立性...

    SVG转EMF的示例代码

    矢量格式转换程序,基于JAVA实现的SVG转EMF的的示例代码,下载后导入到eclipse即可运行。

    emf转bmp代码

    emf转bmpemf

    EMF-IncQuery-Addons:EMF-IncQuery模型查询框架的附加组件

    EMF-IncQuery-附加组件模型查询框架。 该存储库中的所有代码都可以在Eclipse Public License v1.0下获得: :

    eclipse emf&gef

    详细讲述了emf和gef的用法,和模型开发过程,有很多实例的

Global site tag (gtag.js) - Google Analytics