Last time, I said I have ported the sample code to NetBeans Platform in the form of 4 modules getting plugged into the NetBeans Platform Application and I named it PizzaBeans. Today, we will just setup the service provider API and its service providers…
Service Provider Interfaces
Pizza Center Services (pizzacenter.services)
This module contains Builder and Product classes inside a package which is not exported by default, so I had to go the Project Properties and select API Versioning to make that package public, which would then be used by service provider modules to implement the desired functionality, i.e. to build the specific type of Pizza.
To quote from one of the John O’ Conner’s articles (see References);
“Define a service provider by implementing the service provider API. Usually, you will create a JAR file to hold your provider. To register your provider, you must create a provider configuration file in the JAR file’s META-INF/services directory.”
Here the Lookup API will come to the rescue, you will soon get to know how it enables loose-coupling amongst our modules and facilitates high cohesion. Although, I am creating probably the easiest of examples..
“The configuration file name should be the fully qualified binary name of the service’s type. The binary name is simply the fully qualified class name in which each component of the name is separated by a
. character, and nested classes are separated by a
The following two modules does the same and hence, through Lookup API one can get to know what all pizzas can be built…
Hawaiian Pizza (pizzacenter.spone)
Create the configuration file with a name as that of the service provider API class (i.e. Builder class) inside the “META-INF/services/” and add the fully qualified name of the above ConcreteBuilder class to the file.
Spicy Pizza (pizzacenter.sptwo)
Similarly, this module contains a ConcreteBuilder class as the service provider class (the implementation of Builder class). So, this will be registered in the similar way, as done for the Hawaiian Pizza module.
John O’ Conner‘s article on Creating Extensible Applications With the Java Platform is a must read, also refer to the resources I had earlier pointed to.
To be continued…