JimJim2000 JimJim2000 - 1 year ago 66
Java Question

OSGI: getting property information from DS

I have the following declarative service:

immediate = false,
public class ServiceImpl implements ServiceI{...}

And this the code I do to find this service(manually) by propA:

String filter = "(&(objectClass=" + ServiceI.class.getName() + ")(propA=valueA))";
ServiceReference[] serviceReferences = bundleContext.getServiceReferences((String)null,filter);
ServiceI service=(ServiceI) bundleContext.getService(serviceReferences[0]);

How can I get valueB of propB and valueC of propC of found service?

Answer Source

You can use the getProperty of a ServiceReference instance :

Object propBValue = serviceReference.getProperty("propB");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download