Time for action - updating the BookshelfServiceProxyImpl

Edit the BookshelfServiceProxyImpl class. We will walk through the changes step-by-step.

The @Component annotation at class level declares this class as a component definition, and sets its name. The @Provides annotation flags this component as providing a service (in this can it's the BookshelfServiceProxy service).

@Component(name="BookshelfServiceProxy")
@Provides
public class BookshelfServiceProxyImpl
implements BookshelfServiceProxy
{

We have dropped the BundleContext field, since we're going to have iPOJO inject the BookshelfService instance into this newly added bookshelf field. It is tagged as a requirement of the component:

@Requires
private BookshelfService bookshelf;

Then, when we define the service properties, those properties will be attached to the service at registration time:

@ServiceProperty(name = "osgi.command.scope", value=SCOPE)
String gogoScope;
@ServiceProperty(
name = "osgi.command.function", value=FUNCTIONS_STR)
String[] gogoFunctions;

The FUNCTIONS_STR is a new constant added to the BookshelfServiceProxy interface, with the value "[search]". It is needed because the annotation value for a service property is a String.

The constructor is updated removing its BundleContext parameter and the lookupService() method is updated to return the bookshelf field value.

public BookshelfServiceProxyImpl() {
}
protected BookshelfService lookupService() {
return this.bookshelf;
}
// ...
}

The remainder of the class remains unchanged.

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

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