Injecting iPOJOs

Let's modify our use case bundles to use the iPOJO functionality. Here's the plan:

  • Modify the bookshelf-inventory-impl-mock bundle, adding an iPOJO descriptor for the component and its instance and removing the bundle activator.
  • Modify the bookshelf-service bundle to have the inventory field injected instead of it performing a lookup in the service and declare it in its descriptor.
  • Modify the bookshelf-service-tui commands to have as bookshelf service field injected and have them instantiated and registered through iPOJO, here too no longer needing to keep the activator.

As we will soon see, iPOJO allows configuration in XML and using annotations on the component. To practice both technologies, we will modify the bookshelf-inventory-impl-mock and bookshelf-service bundles to use XML-only and the bookshelf-service-tui bundle to use both.

The step-by-step learning of iPOJO will be as follows:

  1. The first example (bookshelf-inventory-impl-mock) only requires the publishing of a service using XML only.
  2. The second example (bookshelf-service) requires both the injection of dependencies and the publishing of a service using XML only.
  3. The third example combines two extensions, one for Gogo and the other for iPOJO and requires the injection of dependencies and the publishing of a service. It is also configured for iPOJO using a combination of XML-based and annotation-based declarations.

But first let's install the iPOJO bundle on our Felix framework.

Install the iPOJO service bundle

We'll start the Apache Felix iPOJO bundle directly from the registered Felix OBR, just like we did previously with the other bundles, with the obr:deploy command (including the -s option):

g! deploy -s "Apache Felix iPOJO"
Target resource(s):
-------------------
Apache Felix iPOJO (1.6.4)

Deploying...done.

The service should now be ready for use. The next thing we need to do is to update our bundles to use it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.159.178