2014-11-06 69 views
1

我有一個組件聲明:更新動態瞄準提供商iPOJO

<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

現在,我想更新(值= 「A」)到(價值=「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組件不能更新「你好」實例的值「A」(由「AA」)實現的組件。

如何修改此ControllerReconfiguration組件?

謝謝你的幫助。

回答

0

謝謝克萊門特,

它工作正常!!!!! :)我使用Factory訪問InstanceManager。

實施例中,爲了訪問組件的InstanceManager 「hello.call.CallHello」

@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); 
}