Injecting the bundle context has been edited by Clement Escoffier (Apr 05, 2008).

(View changes)

Content:

Injecting the bundle context in a POJO

It is sometimes useful to inject the bundle context in your POJO. Then, your POJO is able to deal with the OSGi environment as regular OSGi applications. It is possible to a POJO to get its bundle context. A POJO can receive its bundle context as an argument of its constructor. The next code snippet shows an example:

public class ASimplePOJO{
	private BundleContext context;
	public ASimplePOJO(BundleContext bc) {
		context = bc;
		// do something...
	}}

As you see on the previous snippet, the bundle context is injected in the POJO. Then the POJO can use it as a 'normal' bundle context. The POJO code can:

  • load classes
  • register / unregister services
  • discover, track and use services
  • ...
    However, all these interactions are no more managed by the iPOJO container. So, be careful to manage the dynamism, listeners...


Reply via email to