Interface ServiceAdapterBuilder<T>

Type Parameters:
T - the adaptee service
All Superinterfaces:
ComponentBuilder<ServiceAdapterBuilder<T>>, ServiceCallbacksBuilder<T,ServiceAdapterBuilder<T>>

public interface ServiceAdapterBuilder<T> extends ComponentBuilder<ServiceAdapterBuilder<T>>, ServiceCallbacksBuilder<T,ServiceAdapterBuilder<T>>
Builds a Dependency Manager Service Adapter Component.

The adapter will be applied to any service that matches the specified interface and filter. For each matching service an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original service plus any extra properties you supply here.

Code example that adapts a "Device" service to an HttpServlet service. The adapter is created using a ServiceAdapterBuilder that is passed to the lambda.

 
 public class Activator extends DependencyManagerActivator {
    public void init(BundleContext ctx, DependencyManager dm) throws Exception { 
        adapter(Device.class, adapt -> adapt.impl(DeviceServlet.class).provides(HttpServlet.class).properties(alias -> "/device");                    
    }
 }
  • Method Details

    • filter

      ServiceAdapterBuilder<T> filter(String adapteeFilter)
      Specifies the filter used to match a given adapted service.
      Parameters:
      adapteeFilter - the filter used to match a given adapted service
      Returns:
      this builder
    • propagate

      ServiceAdapterBuilder<T> propagate(boolean propagate)
      Specifies whether or not the adapted service properties must be propagated to the adapter service (true by default).
      Parameters:
      propagate - true if the adapted service properties must be propagated to the adapter service (true by default).
      Returns:
      this builder
    • autoConfig

      ServiceAdapterBuilder<T> autoConfig()
      Injects this adapted service in all fields matching the adapted service type.
      Returns:
      this builder
    • autoConfig

      ServiceAdapterBuilder<T> autoConfig(boolean autoConfig)
      Configures whether or not the adapted service can be injected in all fields matching the adapted service type.
      Parameters:
      autoConfig - true if the adapted service can be injected in all fields matching the adapted service type
      Returns:
      this builder
    • autoConfig

      ServiceAdapterBuilder<T> autoConfig(String field)
      Injects this adapted service on the field matching the given name
      Parameters:
      field - the field name where the adapted service must be injected to.
      Returns:
      this builder