XSD to Ecore connection Mapping
关键字: xsd emf ecore在MBI的intern主题就是做关于Model driven的工作,其中大部分是插件、rcp的开发,用的技术也主要是EMF,GEF和GMF。其中,EMF是基础,领域模型总是要放在最前面。EMF的对建模提供了好几种方式,用UML工具、java annotation,xmi,xsd等。当然,用UML工具,如EclipseUML是最方便的了。可是如果应用要涉及到xml的话,还是用xml schema吧,而且xml schema也是比较简单的。
虽然xsd的学习成本不大,不过对于xsd和ecore的映射问题,我感觉还是有必要学一下。因为用xsd gen ecore的话,为了得到一个比较满意的ecore,就要用一些ecore的标签。如果想详细了解xsd 的ecore标签,google一下“XML Schema to Ecore Mapping”,介绍的比较详细,我这里只想介绍一点关于connection的知识。
实际上,从xsd到ecore,大部分的映射还是比较简单的。像
(1)聚集
A类里有个属性名为container的Elist(注意,如果使用在UML建模的话,以EclipseUML为例,建立关系的时候,要把Property中的Containment设为true)。在xsd里,如何表达这种关系呢。如下:
- <xsd:complexType name="A">
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
- name="container" type="demo:B" />
- xsd:sequence>
- xsd:complexType>
- <xsd:complexType name="B">
- xsd:complexType>
和普通的xsd定义没什么区别。
(2)关联
对于这种方式的联系,EClass会有EReference生成,EReference是non-containment的,所以就不用设置Containment属性了(默认为false)。xsd定义如下:
- <xsd:complexType name="C">
- <xsd:attribute ecore:reference="demo:D" type="xsd:IDREFS"
- name="container"/>
- xsd:complexType>
- <xsd:complexType name="D">
- xsd:complexType>
可以看到ecore:reference标签的使用,它会生成一个属性为container的Elist
双向关联
在这种双向关联中,如果使用EclipseUML,在生成的ecore模型中,C中会有一个名称为ds的Elist
- <xsd:complexType name="C">
- <xsd:attribute ecore:reference="demo:D" type="xsd:IDREF"
- name="ds" ecore:opposite="cs"/>
- xsd:complexType>
- <xsd:complexType name="D">
- <xsd:attribute ecore:reference="demo:C"
- name="cs" ecore:opposite="ds">
- <xsd:simpleType>
- <xsd:list itemType="xsd:anyURI" />
- xsd:simpleType>
- xsd:attribute>
- xsd:complexType>
可以看出,比较单向关联,双向关联增加了
从我个人来讲,比起EclipseUML,我更喜欢直接定义xsd,再gen model。这样在将来的应用中可以更方便的处理xml了。不过这样也会要缺点,尤其是在用到GMF时,可能会产生一些error。
- 19:58
- 浏览 (291)
- 评论 (0)
- 分类: eclipse开发
- 进入论坛
- 发布在 Eclipse PlugIns&RCP&OSGI 圈子
- 相关推荐
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 10176 次
- 性别:


- 详细资料
搜索本博客
最新评论
-
java中的Observer模式
恩,很好,谢谢
-- by xiaobai1023 -
python 字符串中的中文识 ...
s = u'中华人民共和国(北京)'
-- by harry -
java中的Observer模式
不错,思路简单易懂!
-- by James Zhao -
python 字符串中的中文识 ...
# -*- coding: utf-8 -*-s = '中华人民共和国(北京)' ...
-- by MountLion -
python 字符串中的中文识 ...
# -*- coding: gb18030 -*- # -*- codi ...
-- by guotie






评论排行榜