blob: 95dd012705789e62d9603956736ed94adc4346e8 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda;
2
3/**
4 * Builds a Dependency Manager Service Adapter Component.
5 * The adapter will be applied to any service that matches the specified interface and filter. For each matching service an adapter will be created
6 * based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original
7 * service plus any extra properties you supply here.<p>
8 *
9 * Code example that adapts a "Device" service to an HttpServlet service. The adapter is created using a ServiceAdapterBuilder that is passed to the lambda.
10 *
11 * <pre> {@code
12 * public class Activator extends DependencyManagerActivator {
Pierre De Rop11527502016-02-18 21:07:16 +000013 * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
Pierre De Ropfaca2892016-01-31 23:27:05 +000014 * adapter(Device.class, adapt -> adapt.impl(DeviceServlet.class).provides(HttpServlet.class).properties(alias -> "/device");
15 * }
16 * }}</pre>
17 *
18 * @param <T> the adaptee service
19 */
20public interface ServiceAdapterBuilder<T> extends ComponentBuilder<ServiceAdapterBuilder<T>>, ServiceCallbacksBuilder<T, ServiceAdapterBuilder<T>> {
21 /**
22 * Specifies the filter used to match a given adapted service.
23 *
24 * @param adapteeFilter the filter used to match a given adapted service
25 * @return this builder
26 */
27 ServiceAdapterBuilder<T> filter(String adapteeFilter);
28
29 /**
30 * Specifies whether or not the adapted service properties must be propagated to the adapter service (true by default).
31 *
32 * @param propagate true if the adapted service properties must be propagated to the adapter service (true by default).
33 * @return this builder
34 */
35 ServiceAdapterBuilder<T> propagate(boolean propagate);
36
37 /**
38 * Injects this adapted service in all fields matching the adapted service type.
39 *
40 * @return this builder
41 */
42 ServiceAdapterBuilder<T> autoConfig();
43
44 /**
45 * Configures whether or not the adapted service can be injected in all fields matching the adapted service type.
46 *
47 * @param autoConfig true if the adapted service can be injected in all fields matching the adapted service type
48 * @return this builder
49 */
50 ServiceAdapterBuilder<T> autoConfig(boolean autoConfig);
51
52 /**
53 * Injects this adapted service on the field matching the given name
54 *
55 * @param field the field name where the adapted service must be injected to.
56 * @return this builder
57 */
58 ServiceAdapterBuilder<T> autoConfig(String field);
59}