5. 模型扩展
5.1 创建GAEDataSource外部类型
Google App Engine的数据储存代表一个新的数据源,因此在这里我们需要创建一个新的EGL版型GAEDataSource来表示它。
在插件org.eclipse.edt.compiler中新建一个EGL包eglx.gae,并创建一个外部类型(ExternalType)。这个外部类型用于定义一个DataSource,用于和其他DataSource进行区分。
- externalType GAEDataSource extends DataSource type NativeType
- end

GAEDataSource的程序目录结构
创建完外部类型以后,需要运行tools/build-CompilerEGLAR.xml的ANT脚本来在lib目录下编译生成相应的EGLAR文件edtCompiler.eglar。
接下来需要在插件org.eclipse.edt.runtime.java中添加一个空实现的Java类eglx.gae.GAEDataSource.java。具体的程序结构读者可以自行参考附件中的样例程序。
5.2 扩展EGL Model
在创建完GAEDataSource以后,需要扩展相应的EGL Model来标识和Google AppEngine数据储存相关的模型。在本文中,我们仅给出add语句的样例,读者可以参考这个实现来实现其他的抽象语句(如get, replace, delete)。
首先在EDT中创建一个插件项目org.eclipse.edt.mof.eglx.gae,右击该项目,在右键菜单中选择Configure -> Convert to EGL Project,这样该项目就转换成一个EGL插件项目。
在该项目中创建一个EGL源文件GAEActionStatement.egl:
- externalType GAEActionStatement extends IOStatement type MofClass
- end
- externalType GAEAddStatement extends GAEActionStatement, AddStatement type MofClass
- end

org.eclipse.edt.mof.eglx.gae插件
运行tools/build-MofEglMOFAR.xml生成egllib下面的mofar和eglar包:gae.eglar和gae.mofar(读者可以拷贝样例程序中的Ant脚本到该项目中)。
这个插件的作用类似于源代码中的org.eclipse.edt.mof.eglx.services插件,具体的Java接口和实现读者可以参考这个插件。
5.3 注册扩展EGL模型
创建完EGL Model以后,我们需要在EGL的Compiler插件org.eclipse.edt.compiler注册这些模型,使得Compiler可以识别这些新定义的EGL Model。
- 在插件org.eclipse.edt.compiler添加类org.eclipse.edt.compiler.internal.egl2mof.eglx.gae.GAEActionStatementGenerator。这个类作用类似于org.eclipse.edt.compiler.internal.egl2mof.eglx.services.ServicesActionStatementGenerator用来把新定义的外部类型和EGL compiler链接在一起。具体的源码读者可以参考附件中的样例程序 。
- 把类GAEActionStatement注册到类org.eclipse.edt.compiler.EDTCompiler。加入
- path +=SystemEnvironmentUtil.getSystemLibraryPath(GAEActionStatement.class,"egllib");
- 把插件org.eclipse.edt.mof.eglx.gae 注册到类org.eclipse.edt.ide.compiler.IDEEDTCompiler。加入
- path +=getPathToPluginDirectory("org.eclipse.edt.mof.eglx.gae","egllib");
- 把类GAEActionStatementGenerator注册到类org.eclipse.edt.compiler.internal.egl2mof.Egl2MofStatement。加入
- IOStatementGenerator.Registry.put("eglx.gae",GAEActionStatementGenerator.class);
