Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > EMF 生成的Model Code阅读笔记(一)
【标  题】:EMF 生成的Model Code阅读笔记(一)
【关键字】:EMF,Model,Code
【来  源】:http://www.blogjava.net/JetGeng/archive/2005/12/18/24474.html

EMF 生成的Model Code阅读笔记(一)

Your Ad Here

在八进制的中讲述了从模型到应用程序的生成过程。我通过类似的方法生成了一个应用程序。

代码生成后,我就想看看EMF为我生成了什么样的代码。我如果需要修改的话该如何修改。

我的“Hellow world”是采用的“Using EMF”文中的模型。
familytree.JPG
根据这个模型建立了一个EMF Model
family model.gif
根据这个模型生成model class的结构如下图所示:
class code.gif

从图中我们可以看到有三个包:

他们分别是:family,family.implfamily.util

familyfamily.impl包之间的差别就是一个是Interface,另外一个是这些Interface的实现。

我们先来看看我们模型中出现过的类:

Family,FamilyTree,Female,Male以及Individual

由于我是采用Annotated Java的方式生成的模型。所以在family包中的代码并没有太多的变化。
/**
     * Return the father
     * 
@return the father
     * @model
     
*/
    Male getFather();
    
    
/**
     * Sets the value of the '{
@link com.jet.swt.emf.family.Family#getFather <em>Father</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
@param value the new value of the '<em>Father</em>' reference.
     * 
@see #getFather()
     * @generated
     
*/
    
void setFather(Male value);

他只是为我提供了Set方法。接口的继承也没有做修改。但是他对应的实现类就有了很多变化。

首先从类的申明来看:

public class FamilyImpl extends EDataObjectImpl implements Family {
我们可以看到我们的FamilyImpl是从EdataObjectImpl类继承而来。处于好奇我有在Hiberarchy中打开他的继承关系看了一下。hiberarchy.gif

这里有一张图可以清晰的说明这个继承关系的职能。

hiberachyfunction.gif
我例子中的Business Layer是FamilyImpl类。

这样我们的就可以不写一行代码就可以使我们的对象具有Notification/Common的功能(关于NotificationCommon的功能到底是怎样的,我会在后续的学习笔记中记下来。呵呵,是不是很爽啊)。另外在《Eclipse Modeling Framework: A Developer's Guide》一书的第二章也有提到这部分的内容,不过由于他讲解的EMF的版本比较老和我现在使用的版本有点出入,不过基本的功能还是讲到了。

好了,看完申明我们就来继续往下看吧。

Family下面有三个属性,father,motherchildren

EMF给我们生成的对应的代码为:

protected Male father = null;

    
/**
     * The cached value of the '{
@link #getMother() <em>Mother</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
@see #getMother()
     * @generated
     * @ordered
     
*/
    
protected Female mother = null;

    
/**
     * The cached value of the '{
@link #getChildren() <em>Children</em>}' containment reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
@see #getChildren()
     * @generated
     * @ordered
     
*/
    
protected EList children = null;

以及一些getset方法。

对于set方法中除了基本的赋值以外还加上了向所有对这次变动感兴趣观察者发送一个变更消息:

public void setFather(Male newFather) {
        Male oldFather 
= father;
        father 
= newFather;
        
if (eNotificationRequired())
            eNotify(
new ENotificationImpl(this, Notification.SET, FamilyPackage.FAMILY__FATHER, oldFather, father));
    }

对于get方法要分基本类型还是对象这两种类型来处理。

如果是基本类型,直接返回就好了。

如:

public String getName() {
        
return name;
    }
如果是对象的话就有点麻烦了。先要判断该对象是否使用了代理(这一部分我还不是太清楚)如果是的话就获得他的代理对象,并判断获得代理对象是否和当前对象是否相等,如果不等就发送一个变更消息。最终返回对象(肯能是一个代理对象)。
public Male getFather() {
        
if (father != null && ((EObject)father).eIsProxy()) {
            Male oldFather 
= father;
            father 
= (Male)eResolveProxy((InternalEObject)father);
            
if (father != oldFather) {
                
if (eNotificationRequired())
                    eNotify(
new ENotificationImpl(this, Notification.RESOLVE, FamilyPackage.FAMILY__FATHER, oldFather, father));
            }
        }
        
return father;
    }

还有其他类将在下一篇记下。

1、  Using EMF,  Author :Catherine Griffin

2、   EMF介绍系列(二、从模型生成应用程序) Author:八进制

3、  Mastering Eclipse Modeling FrameworkAuthor:Vladimir Bacvanski(Vladimir@inferdata.com) Petter Graff(petter@inferdata.com)

Eclipse Modeling Framework: A Developer's Guide Author:Frank Budinsky, David Steinberg, Ed Merks, Raymond Ellersick, Timothy J. Grose
使用Eclipse + MyEclipse开发Web Service的示例!(录像教程):【上一篇】
Applet之间的通讯:【下一篇】
【相关文章】
  • emf&gef之二nodetest
  • emf&gef之三nodenew
  • Code: Google Code Jam China 2005
  • 用GDI+转BMP为WMF、EXIF、EMF格式
  • an EMF-based implementation of the UML 2.0 metamodel for the Eclipse platform
  • Graphical Modeling Framework (翻译)
  • Code::Blocks
  • 简化Spring(2)--Model层
  • 由于cnblogs的独特性以及我的浏览器的问题,本人决定将blog迁往一个兼容性好一点的地方 codelphi
  • 在Code-Behind中操作WebUserControl
  • 【随机文章】
  • 14.8 Shift operators
  • Java Web开发基础入门(二)——Servlet简介
  • Windows下的字幕平滑滚屏
  • 防范DDoS攻击 七种IP拥塞控制算法需改进
  • ACE_Message_Queue的超时设置
  • 实施MPLS-VPN网络运营新商机
  • 港湾网络IP DSLAM技术特性
  • The checklist before Oracle ias 10g installation
  • 自编辑Compiere2.53b系统
  • 恶意代码与网络安全(1)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.