Set dynamically a property hosted in a /etc/config file

classic Classic list List threaded Threaded
3 messages Options
xav
Reply | Threaded
Open this post in threaded view
|

Set dynamically a property hosted in a /etc/config file

xav
Hi all,

I try to set dynamically a property associated at a bundle.
Explanation:

in /etc I have a configuration file for my x.y.z.MyBundle (x.y.z.MyBundle-default.cfg)
inside it there are some properties (key/value)

The goal is outside this MyBundle (an another) I would like update some properties of it.

I succeeded with this code
ConfigRepository configRepository;
Configuration[] configs = configRepository.getConfigAdmin().listConfigurations("(service.factoryPid=x.y.z.MyBundle)");

Dictionary props = configs[0].getProperties();
props.put("myKey", 20);
configs[0].update(props);

It's works perfectly, but the issue, is I don't know, how I can retrieve the factoryPid for an bundle
in fact I have the bundle object or the bundleContext, but????
I use Ipojo too

Thx for any help.

Regards

xav
Reply | Threaded
Open this post in threaded view
|

Re: Set dynamically a property hosted in a /etc/config file

xav
This post has NOT been accepted by the mailing list yet.
Hi all,

Any idea ??

Thx
xav
Reply | Threaded
Open this post in threaded view
|

Re: Set dynamically a property hosted in a /etc/config file

xav
Hi all,

I put a solution for anybody, and for challenge it.

I used bundle.getRegisteredServices(); to having all services registered by my bundle, and I keep the service.factoryPid key to having the value. here the code:

String returnValue = "";
ServiceReference<?>[] refs = bundle.getRegisteredServices();
if (refs != null) {
        boolean isFound = false;
        int size = refs.length;
        for (int i = 0; i < size && !isFound; i++) {
                String[] keys = refs[i].getPropertyKeys();
                for (String key : keys) {
                        if (!key.equalsIgnoreCase(Constants.OBJECTCLASS)) {
                                if ("service.factoryPid".equalsIgnoreCase(key)) {
                                        returnValue = refs[i].getProperty(key).toString();
                                        isFound = true;
                                        break;
                                }
                        }
                }
        }
}

regards