Pierre De Rop | 6e8f921 | 2016-02-20 21:44:59 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 19 | package org.apache.felix.dm.lambda; |
| 20 | |
| 21 | /** |
| 22 | * Builds a Dependency Manager Service Adapter Component. |
Pierre De Rop | 6e8f921 | 2016-02-20 21:44:59 +0000 | [diff] [blame^] | 23 | * <p> The adapter will be applied to any service that matches the specified interface and filter. For each matching service an adapter will be created |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 24 | * based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original |
| 25 | * service plus any extra properties you supply here.<p> |
| 26 | * |
| 27 | * Code example that adapts a "Device" service to an HttpServlet service. The adapter is created using a ServiceAdapterBuilder that is passed to the lambda. |
| 28 | * |
| 29 | * <pre> {@code |
| 30 | * public class Activator extends DependencyManagerActivator { |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 31 | * public void init(BundleContext ctx, DependencyManager dm) throws Exception { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 32 | * adapter(Device.class, adapt -> adapt.impl(DeviceServlet.class).provides(HttpServlet.class).properties(alias -> "/device"); |
| 33 | * } |
| 34 | * }}</pre> |
| 35 | * |
| 36 | * @param <T> the adaptee service |
| 37 | */ |
| 38 | public interface ServiceAdapterBuilder<T> extends ComponentBuilder<ServiceAdapterBuilder<T>>, ServiceCallbacksBuilder<T, ServiceAdapterBuilder<T>> { |
| 39 | /** |
| 40 | * Specifies the filter used to match a given adapted service. |
| 41 | * |
| 42 | * @param adapteeFilter the filter used to match a given adapted service |
| 43 | * @return this builder |
| 44 | */ |
| 45 | ServiceAdapterBuilder<T> filter(String adapteeFilter); |
| 46 | |
| 47 | /** |
| 48 | * Specifies whether or not the adapted service properties must be propagated to the adapter service (true by default). |
| 49 | * |
| 50 | * @param propagate true if the adapted service properties must be propagated to the adapter service (true by default). |
| 51 | * @return this builder |
| 52 | */ |
| 53 | ServiceAdapterBuilder<T> propagate(boolean propagate); |
| 54 | |
| 55 | /** |
| 56 | * Injects this adapted service in all fields matching the adapted service type. |
| 57 | * |
| 58 | * @return this builder |
| 59 | */ |
| 60 | ServiceAdapterBuilder<T> autoConfig(); |
| 61 | |
| 62 | /** |
| 63 | * Configures whether or not the adapted service can be injected in all fields matching the adapted service type. |
| 64 | * |
| 65 | * @param autoConfig true if the adapted service can be injected in all fields matching the adapted service type |
| 66 | * @return this builder |
| 67 | */ |
| 68 | ServiceAdapterBuilder<T> autoConfig(boolean autoConfig); |
| 69 | |
| 70 | /** |
| 71 | * Injects this adapted service on the field matching the given name |
| 72 | * |
| 73 | * @param field the field name where the adapted service must be injected to. |
| 74 | * @return this builder |
| 75 | */ |
| 76 | ServiceAdapterBuilder<T> autoConfig(String field); |
| 77 | } |