【java emf】学习EMF过程中一些知识点

来源:互联网 发布:阿里小号 淘宝绑定 编辑:程序博客网 时间:2024/06/06 17:03

1、meta-model是什么?


2、XLM schema文件用来做什么?


3、EMF、UML、XML之间的关系:http://www.cnblogs.com/jpcflyer/archive/2012/05/29/2517678.html


4、EMF手册:http://www.vogella.com/articles/EclipseEMF/article.html


5、在创建模型时,ereference中有一个属性为:containment。containment(包含)与reference(引用)的区别为:

Reference: A reference is a plain "A knows B" relation. Separate references do not influence each other. A can know B and B can know C. Hence, if you have A, you can go to C over B. If you remove the reference, A, B and C will still exist, they just don't know each other any more.

Containment: A containment is the "A has B" kind of relation. Usually used for lists, e.g. "A has multiple B". ECore/EMF can then perform atomic commands on such collections, such as move all objects from one containment to another. It can also enforce constraints, such as a minimum amount of contained objects or a maximum amount of contained objects, or ensuring that the contained object is not contained in any other containment.

Example:

Assume you have an object called ShoppingCart with a reference called Customer and a containment called OrderedProducts. The OrderedProducts has a reference to a Product.

What does this model tell you?

  • You can assign a Customer to the ShoppingCart. If you remove the Customer from the ShoppingCart, the Customer object itself will still exist (e.g. in the database)
  • The OrderedProduct objects need a ShoppingCart to exist. If you remove one from the ShoppingCart, it will cease to exist.
  • Each OrderedProduct has a reference to an existing Product in the database. If you remove one of the OrderedProducts from the ShoppingCart, the Product in the database will still be there - just the order of that product for that specific customer is gone

reference:A 可以引用B,如果从A被删除了,那么B还是存在的。

        containment: A 包含B,如果A被删除了,B就没有了,B需要在A中存在


6、.ecore文件的Ns prefix和Ns URI必须进行设置,否则generate模型出错。

     Ns URI其实属于XML的一个命名空间规则,在GMF中用来保证各个工程项目的类是唯一的,就如同网址一样,不同的公司如果使用了同一网址,当其他IP地址来访问该网址时,会造成URI定位到两个IP地址,而不唯一。当相同的URI数目达到上万个时,肯定是难以忍受的,所以URI必须是唯一定位。

不同ecore工程的URI必须不同


7、利用模型可生产edit和editor代码

     ecore模型可产生模型、edit和editor三部分代码

第一个项目是模型部分,主要包含你定义的ecore模型里各类型(EClass,在ecore元模型里类型称为EClass,属性称为 EAttribute)对应的java接口和缺省的实现类代码,例如Product.java和ProductImpl.java,它们分别被放置在 com.my.shop和com.my.shop.impl包里;一个工厂类(ShopFactory)使用工厂模式创建新的模型实例;一个 Package类(ShopPackage)维护关于元模型的信息,提供了一堆静态成员变量;此外还生成了ShopAdapterFactory和 ShopSwitch这两个类,它们是可选的,它们俩的作用这里卖个关子暂时先不说。

第二个项目是.edit部分,这里面包含了一系列ItemProvider类,用来为在jface的各种查看器(Viewer)里显示这些模型对象 提供便利,以CategoryItemProvider为例,它实现了IStructuredItemContentProvider、 ITreeItemContentProvider和IItemLabelProvider这些接口,注意把这些接口名字中的"Item"去掉就是 jface里需要的Provider,可以把这些带有"Item"字样的Provider想象成对jface相应Provider的包装。有了这些 Provider,在应用程序里使用jface的TreeViewer、TableViewer等查看器就很方便了。(前面讲GEF的一个帖子里曾利用 EMF构造模型,当时使用的就仅仅是模型部分,因为并未用到jface查看器。所以视你的应用程序而定,可以只生成模型部分来用,.edit部分依赖模型部分,而反之不然。)

第三个项目是编辑器,这个部分依赖.edit部分,主要包含了几个UI方面的类。EMF为我们生成的这个编辑器有两个用途:一是让我们可以不用从零开始,而是在这个编辑器的基础上进行修改得到自己的编辑器; 二是通过这些代码展示怎样在应用程序里使用前两个项目里的那些类,编辑器包含那么多Tab正是为了演示各种查看器的用法。下面来说一下怎样定制生成的应用 程序。

一、修改ecore模型和genmodel模型

                    EMF.edit位于EMF.editorEMF.Ecore之间,他起了一个中介者的作用。他负责把来自EMF.editorUI相关的请求转换成符合EMF.EcoreUI无关的调用。他需要提供以下四个功能:实现用于支持Viewer显示的ContentProviderLabelProvider;实现用于支持属性显示的IPropertySource;实现用于支持对模型进行操作的CommandFramework;实现用于支持修改通知的Framework


8、EMF介绍系列:别人的帖子:

http://www.cnblogs.com/bjzhanghao/archive/2005/11/12/275024.html

原创粉丝点击