我有一个组件声明为:
<ipojo>
<component classname="HelloClass" name="helloCom" immediate="true">
<requires field="delayService" id="id1">
</requires>
</component>
<instance component="helloCom" name="hello">
<property name="requires.from">
<property name="id1" value="A"/>
</property>
</instance>
</ipojo>
这个组件的jar文件:helloComponent.jar
现在,我想将(value="A")更新为(value="AA")。因此,我使用ConfigurationAdmin实现了一个组件来更新这个属性
public class ControllerReconfiguration {
private ConfigurationAdmin m_configAdmin;
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reconfigure() throws IOException {
Configuration configuration = m_configAdmin.getConfiguration("hello","file:./helloComponent.jar");
configuration.setBundleLocation("file:./helloComponent.jar");
Properties props = new Properties();
//Dictionary props = new Hashtable();
props.put("id1", "AA");
configuration.update(props);
System.out.println("Update");
}
}
但是,此ControllerReconfiguration组件无法更新"hello"实例中的值"A"(通过"AA")。
请如何修改此ControllerReconfiguration组件?
谢谢你的帮助。
不幸的是,您不能像这样推送新的"from"配置。
但是,您可以直接使用iPOJO内省API:http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html
- 检索实例的体系结构服务
- 检索InstanceDescription和DependencyDescription
- 调用setFilter方法
感谢的Clement
它运行良好!!!!:)我使用Factory访问InstanceManager。
例如,为了访问组件"hello.call.CallHello"的InstanceManager
@require
private Factory[] factories;
for (Factory factory : factories) {
/*
* "hello.call.CallHello" is a component name
* note: it is not component instance name
*/
if (factory.getName().equals("hello.call.CallHello")) {
/*
* a component can have many instances
* if there is only one instance.
* get(0) return the first instance.
*/
InstanceManager im = (InstanceManager) factory.getInstances().get(0);
}