On Wed, Jun 3, 2009 at 5:48 PM, Guido Spadotto <[email protected]> wrote:
> Agemo Cui wrote:
>
> [snip]
> The right way for you to solve your problem is to write a class to
> implement the interface ServiceListener.
> And then add the its instance to BundleContext as follows:
>
> bundleContext.addServiceListener(yourServiceListener);
>
> If you want to filter the event by the service type, then create a filter
> String filter = "(" + org.osgi.framework.Constants.OBJECTCLASS +
> "=xxx.xxx.xxx.interfacename)"; and add it to the BundleContext along with
> your ServiceListener as follows:
>
> bundleContext.addServiceListener(yourServiceListener, filter);
>
> Thanks Agemo for your quick answer.
> I'm going to try writing a component that implemets the ServiceListener
> interface, and that
> registers itself as a ServiceListener in its own BundleContext (I don't
> know if this is "sane",
> but I'm going to try it anyway) using this method:
> /** This method is called when the component is activated */
> protected void activate(ComponentContext context) {
> context.getBundleContext().addServiceListener(this);
> }
>
> I also have to check if the filter selects also classes that implement
> sub-interfaces/sub-classes of the one specified in the filter.
> The quickest way of doing this is to try it ;)
>
*No, * *I don't think so unless the names of those
sub-interfaces/sub-classes* *are also used to register the service. And then
you can create a complicate fiter like
"(|(objectClass=xxxxx)(objectClass=xxxxx))". If the prefix of the interfaces
are the same, then the filter could be easy to create like
"(objectClass=xxxx.xxxx.xxx.SameName*)"* *by using wildcard.*
>
>
> Thanks again.
> --
> [image: Logo] Guido Spadotto
> Soluta.net, Italy
> http://www.soluta.net
>
>
>