假设我有一个包含类 X 的 OSGI Bundle。假设这个类包含对特定服务的 OSGI 引用。像这样的东西:
ServiceReference[] references = context.getServiceReferences (serviceSpecification,someFilter);
有没有一种方法可以动态识别引用所连接的服务规范?有没有办法也识别服务过滤器(上面的第二个参数)?
例如,像这样:
System.out.println(references[0].getServiceSpecification);
System.out.println(references[0].getServiceFilter);
我需要在包外的代码中找出这些值。
迄今为止完成的工作:
我使用 iPOJO 通过创建 bundle 的 iPOJO 组件实例来获取引用属性,然后获取其属性描述,如下所示:
ComponentInstance componentInstance = factory.createComponentInstance(configuration);
instanceDescription= (PrimitiveInstanceDescription) componentInstance.getInstanceDescription();
PropertyDescription[] propertyDescription = instanceDescription.getProperties();
我可以使用上面的方法获取引用名称、类型、值propertyDescription
,但是该值作为对象返回,我无法得到我需要的东西。有人可以帮忙吗?谢谢。