Hi,
Am Dienstag, den 02.11.2010, 14:30 +0100 schrieb David Conde:
> Hi! I am getting problem when I try to update Configuration object.
>
>
>
> I am trying to use Configuration objects from Configuration Admin
> Service in the next way:
>
>
>
> conflist[i].getProperties().put("ACTIVE", Boolean.FALSE);
>
> conflist[i].update();
>
>
>
> if((Boolean) conflist[i].getProperties().get("ACTIVE"))
> {
>
> System.out.println("ERROR UPDATING CONFIGURATION OBJECT");
>
> }else {
>
> System.out.println("UPDATING IS DONE!");
>
> }
>
>
>
> Why I get the message "ERROR UPDATING CONFIGURATION OBJECT” if I am
> putting the value of ACTIVE key to FALSE in the previous line, is
> there any problem updating configurations object with updated method?
When you call the getProperties() method you get a private copy of the
Dictionary which you are changing. Thus the changes don't go into the
Configuration.
This is the first part of the problem. The second part is the real
cause, though: Calling the update() method (no args) just updates the
Configuration object from persistence. To actually update the
configuration with new data, you have to call the update(Dictionary)
method with the new or modified Dictionary object.
Thus:
Dictionary d = conflist[i].getProperties();
if (d == null) {
d = new Hashtable();
}
d.put("ACTIVE", Boolean.FALSE);
conflist[i].update(d);
Note the null check: If the configuration has just been created the
Dictionary you get back is actually null and must be created first.
Regards
Felix
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev