Step 2: Updating the Hotdog Vendor Bundle to Export a Service with Registered Properties

In this step the Hotdog Vendor bundle is updated to export an implementation of the VendorService with a property that describes its spiciness.

  1. In the Package Explorer find the org.eclipse.soda.sat.tutorial.vendor.hotdog project.
  2. Find the bundle activator and update it as follows. The updates are highlighted in bold.
    package org.eclipse.soda.sat.tutorial.vendor.hotdog.bundle;
    
    import java.util.Dictionary;
    import java.util.Hashtable;
    
    import org.eclipse.soda.sat.core.framework.BaseBundleActivator;
    import org.eclipse.soda.sat.core.util.LogUtility;
    import org.eclipse.soda.sat.tutorial.vendor.hotdog.HotdogVendor;
    import org.eclipse.soda.sat.tutorial.vendor.service.VendorService;
    
    public class Activator extends BaseBundleActivator {
      protected void activate() {
        LogUtility.logInfo("The Hotdog Vendor bundle has been activated");  //$NON-NLS-1$
        addExportedVendorService();
      }
    
      private void addExportedVendorService() {
        VendorService service = new HotdogVendor();
        Dictionary properties = new Hashtable(11);
        properties.put(VendorService.SPICINESS_PROPERTY, new Integer(10));
        addExportedService(VendorService.SERVICE_NAME, service, properties);
      }
    
      protected void deactivate() {
        LogUtility.logInfo("The Hotdog Vendor bundle has been deactivated");  //$NON-NLS-1$
      }
    }
    
  3. As you can see, the addExportedVendorService() methods has been updated to create a Dictionary of properties that is passed to the addExportedService(String, Object, Dictionary) method when the VendorService is exported. In this case the single property key VendorService.SPICINESS_PROPERTY is registered with the value new Integer(10).
  4. Defining a property key such as SPICINESS_PROPERTY in the service interface, in this case VendorService, is a useful technique since it defines a common property key that can be used by all bundles that implement the interface and register a service.
  5. Notice that unlike System.setProperty(String, String), registered service properties are instances of Object not just a String.