Create an OSGi-compliant class that implements a plugin interface

Before you begin

Procedure

  1. If you have not previously generated the Java libraries, without Guidewire Studio or IntelliJ IDEA with OSGi editor open, type the following command at a command prompt in the PolicyCenter root directory.
    gwb genJavaApi
  2. If IntelliJ with OSGi Editor is not open, type the following command at a command prompt in the PolicyCenter root directory.
    gwb pluginStudio
  3. In IntelliJ IDEA with OSGi Editor, navigate under your OSGi module to the src directory.
  4. Create new subpackages as necessary by right-clicking src and choosing New > Package.
    For example, create a mycompany package.
  5. Create an OSGi-compliant class that implements a plugin interface.
    1. Right-click the package for your class.
    2. Choose New > New OSGi plugin.
      IntelliJ IDEA with OSGi Editor opens a dialog.
    3. In the Plugin class name field, enter the name of the Java class that you want to create.
      For example, type DemoStartablePlugin.
    4. In the Plugin interface field, enter the fully qualified name of the plugin interface that you want to implement. Alternatively, to choose from a list, click the ellipsis (...) button. Type some of the name or scroll to the required plugin interface. Select the interface and then click OK.
      For example, type IStartablePlugin.
      IntelliJ IDEA with OSGi Editor displays a dialog Select Methods to Implement. By default, all methods are selected.
    5. Click OK.
      IntelliJ IDEA with OSGi Editor displays your new class with stub versions of all required methods.
  6. If the top of the Java class editor has a yellow banner that says Project SDK is not defined, you must set your project SDK to a JDK. If the SDK settings are uninitialized or incorrect, your project shows many compilation errors in your new Java class.
  7. Add code to the stub methods.
    For example, use the code in Example startable plugin in Java using OSGi.

Results

Your class is ready for compiling and installing.

What to do next

If you have several tightly related OSGi plugin implementations, you can optionally deploy them in the same OSGi bundle. To implement additional plugins in this project, repeat this procedure for each plugin implementation class. For example:

A messaging destination implements the MessageTransport interface. A single messaging destination optionally also implements the MessageReply plugin interface. If these related plugin implementations have shared code and third-party libraries, you could deploy them in the same OSGi bundle that encapsulates messaging code for a messaging destination.