您的位置:首页 > 编程语言 > Java开发

Eclipse自动插件依赖的一种配置解决方式

2013-08-15 23:30 288 查看
Eclipse的插件具有以下特点:

(1)每一个插件有自己独立的classloader

(2)插件资源的交互通过MENIFEST.MF中"Export-Package, Require-Bundle, Import-Package"等属性控制

(3)插件不能相互依赖

最近开发的系统需要进行权限控制,控制粒度到视图的定义、命令的定义等等。当系统启动的时候,需要根据配置(数据库保存)加载当前用户可用的配置,这样问题就来了:

Eclipse的插件是需要依赖的,才能引用。例如B依赖A,则B可以引用A,但A不依赖B,A不能调用B的资源。这意味着,如果A作为权限检测并加载插件配置的类,是不能引用B的类的。一种解决方案,就是A加入对B的依赖。但是当系统变大,不可能是一个开发组开发时,A怎么会知道到底有些什么插件呢?显然它不可能先知先觉。因此存在问题。

幸好,Eclipse提供了对MENIFEST文件的扩展,扩展了Eclipse-BuddyPolicy指令。

网址:http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fbundle_manifest.html 给出了此指令的介绍

The Eclipse-BuddyPolicy header is used to specify the buddy classloading policies for a bundle.The Eclipse-BuddyPolicy header must use the following syntax:

Eclipse-BuddyPolicy ::= ( policy-name ) ( ',' policy-name ) *
policy-name ::= ( 'dependent' | 'global' | 'registered' |
'app' | 'ext' | 'boot' | 'parent' )


registered - indicates that the buddy mechanism will consult bundlesthat have been registered to it. Bundle willing to be registered to a particular bundle add in their manifest: "Eclipse-RegisterBuddy: <bundleSymbolicName>";
dependent - indicates that the classes/resources will be looked uptransitively in all the dependent of the bundle;
global - indicates that the classes/resources will be looked up in theglobal pool of exported package;
app - indicates that the application classloader will be consulted;
ext - indicates that the extensiont classloader will be consulted;
boot - indicates that the boot classloader will be consulted.

于是根据上述描述,在A插件MENIFEST文件中插入
Eclipse-BuddyPolicy: global

指令,然后B引用A,A不需要引用B,但是在A中需要调用的B的资源,需要在B中Export出来。这样,就可以在A中使用B的资源了。
通过这种方式,实现了根据用户角色,过滤界面的功能,很好地实现了界面部分权限的控制。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐