首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

服打工厂 - Bundle消费者返回不同的服务对象

2012-11-14 
服务工厂 - Bundle消费者返回不同的服务对象public?class?Activator?implements?BundleActivator?{??????S

服务工厂 - Bundle消费者返回不同的服务对象

          public?class?Activator?implements?BundleActivator?{??????ServiceRegistration?serviceRegistration;????????????public?void?start(BundleContext?context)?throws?Exception?{??????????//注册服务??????????HelloServiceFactory?helloServiceFactory?=?new?HelloServiceFactory();??????????serviceRegistration?=??context.registerService(HelloService.class.getName(),?helloServiceFactory,?null);????????????????????//获取服务(通过服务工厂取得)??????????ServiceReference?serviceReference?=?context.getServiceReference(HelloService.class.getName());??????????HelloService?selloService?=?(HelloService)context.getService(serviceReference);??????????System.out.println("1:?"?+?selloService.sayHello("cjm"));????????????????????//第二次取得的服务对象与之前取得的是同一个对象??????????serviceReference?=?context.getServiceReference(HelloService.class.getName());??????????selloService?=?(HelloService)context.getService(serviceReference);??????????System.out.println("2:?"?+?selloService.sayHello("cjm"));??????}????????????public?void?stop(BundleContext?context)?throws?Exception?{??????????serviceRegistration.unregister();??????}??}??

        ?

热点排行