4 Assemble an Adapter or Event Bean

You typically bundle custom adapters and event beans in the same application JAR file that contains the other EPN components. Alternately, you can bundle the custom adapter and its factory or the event bean and its factory in their own respective JAR file so that you can reference them from other application bundles.

For example, when two different applications read data coming from the same data feed provider and both applications have the same event types, it can make sense to share a single adapter implementation. With this approach, you do not have to duplicate the custom adapter implementation in two different applications.

This chapter includes the following sections:

4.1 Assemble a Custom Adapter in its Own Bundle

When you assemble a custom adapter in its own bundle, do not declare it in the assembly file with the wlevs:adapter element. You use this element to declare the custom adapter in the assembly file of the application bundle that uses it.

  1. Create an OSGI bundle that contains the following Java classes: The custom adapter class, its JavaBean event type class, and its adapter factory class.

    In this procedure, this bundle is called GlobalAdapter.

  2. In the GlobalAdapter bundle assembly file:
    • Register the adapter factory as an OSGi service.

    • Register the custom adapter JavaBean event type class as an OSGi service.

  3. In the MANIFEST.MF, export the JavaBean event type class with the Export-Package header.
  4. Assemble and deploy the GlobalAdapter bundle.
  5. In the assembly file of the application that is going to use the custom adapter, declare the custom adapter component as Configure a Custom Adapter describes.

    You still use the provider attribute to specify the OSGI-registered adapter factory, although in this case the OSGi registration happens in a different assembly file (of the GlobalAdapter bundle) from the assembly file that actually uses the adapter.

  6. If you have exported the JavaBean event type into the GlobalAdapter bundle, you must explicitly import it into the application that is going to use it.

    You do this by adding the package to the Import-Package header of the MANIFEST.MF file of the application bundle.

4.2 Assemble an Event Bean in its Own Bundle

When you assemble an event bean in its own bundle, do not declare it in the assembly file with the wlevs:event-bean element. You use this element to declare the custom event bean in the assembly file of the application bundle that uses them.

  1. Create an OSGi bundle that contains the following Java classes: The event bean Java class and its event bean factory class.

    In this procedure, this bundle is called GlobalEventBean.

  2. In the GlobalEventBean assembly file register the event bean factory as an OSGi service.
  3. Assemble and deploy the GlobalEventBean bundle.
  4. In the assembly file of the application that is going to use the event bean, declare the custom event bean component.

    You still use the provider attribute to specify the OSGi-registered event bean factory, although in this case the OSGi registration happens in a different assembly file (of the GlobalEventBean bundle) from the assembly file that actually uses the event bean.