【发布时间】:2018-11-13 08:26:48
【问题描述】:
我一直在使用 OSGi 配置管理在我们的程序中实现一些基本的配置功能。我现在开始研究MetaType Service 规范,因为我需要每个配置属性的类型信息。
我不清楚这两种服务如何交互。配置管理员处理本质上无类型的键/值对。 MetaType 服务知道配置属性的名称和类型(除其他外),但不知道它们的值。我的目标是为所有具有配置和相应元类型信息的组件动态生成配置/首选项对话框。根据 MetaType Service 规范,该服务旨在涵盖这个确切的用例。所以我觉得应该不会太难
我可以使用以下示例代码检索元类型信息:
ServiceReference metatypeRef = bundleContext.getServiceReference(MetaTypeService.class.getName());
MetaTypeService service = (MetaTypeService) bundleContext.getService(metatypeRef);
MetaTypeInformation information = service.getMetaTypeInformation(myBundle);
在检索到所需捆绑包的 MetaTypeInformation 对象后,我可以访问元类型 XML 定义中包含的所有信息。特别是可以访问 ObjectClassDefinition:
ObjectClassDefinition ocd = information.getObjectClassDefinition(pid, null);
AttributeDefinition[] attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
我的问题是:
- 给定属性定义;如何检索基础财产的实际价值?我知道它的名字,但不知道它的价值。
- 如何枚举当前存在的所有捆绑包中的所有组件的元类型信息(活动和非活动)?我知道如何通过配置管理界面列出所有配置。也许有一种方法可以从配置中获取 MetaTypeInformation?
【问题讨论】:
标签: osgi