使用单接口多逻辑方式实现方式实现父子 bundle一、父子 bundle 功能以用户管理模块为例用户管理-普通用户管理-管理员用户管理-VIP 用户管理1、 父 bundle 启动后,需要已经启动的子 bundle,如,需要子 bundle 提供菜单名称,用于显示在页面上。2、 父 bundle 停止,所有的子 bundle 也需要停止3、 子 bundle 启动,父 bundle 可以得到子 bundle 中的信息(菜单链接等)4、 子 bundle 停止,父 bundle 删除相关的信息(菜单链接等)5、 父 bundle 需要提供公共的处理方法,如,当用户没有权限管理某菜单时,则不显示菜单6、 父 bundle 停止时,无法启动子 bundle(//TODO ?)二、父子 bundle 代码解释1、net.oupu.base.common,基本 bundlenet.oupu.base.common.ParentChildLink 提供公共的父子 bundle 接口父类模板net.oupu.base.common.Constant 类中的 BUNDLECONTEXT 变量提供全局的 bundleContext用于管理所有 bundle 及 getBundleIdByName 方法提供根据 bundle 名称得到 id 的功能2、父 bundle net.oupu.demo.parentnet.oupu.demo.parent. ParentChildLink 继承至 net.oupu.base.common.ParentChildLink,实现添加自己的方法,如,添加方法 getMenuName 得到子 bundle 需要显示在父 bundle 中的菜单net.oupu.demo.parent.listener. ChildLister 类,用于监听所有的子 bundle 的添加、删除等。META-INF/spirng/ applicationContext.xml 中
META-INF/spirng/springOsgi.xml中
将 所 有 子 bundle 中 实 现 了 net.oupu.demo.parent.ParentChildLink 接 口 的 实 现 类 以List
的形式注入到 ChildLister 对应的 bean 中。OnBinds 用于处理子 bundle 的添加/启动OnUnbinds 用于处理子 bundle 的删除/停用3、子 bundle net.oupu.demo.childa(/b、/c)net.oupu.demo.child. ParentImplA 实现 net.oupu.demo.parent.ParentChildLink 接口,并提供给父 bundle 一些关于子 bundle 的信息META-INF/spirng/ applicationContext.xml 中META-INF/spirng/springOsgi.xml中声明 childa 对应的 bean 实现了接口 net.oupu.demo.parent.ParentChildLink,并导出服务