Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda; |
| 2 | |
| 3 | /** |
| 4 | * Builds a Dependency Manager Aspect Component. |
| 5 | * The aspect will be applied to any service that matches the specified interface and filter (if any). For each matching service an aspect will be created based |
| 6 | * on the aspect implementation class. |
| 7 | * The aspect will be registered with the same interface and properties as the original service, plus any extra properties you supply here. |
| 8 | * Multiple Aspects of the same service are chained and ordered using aspect ranks. |
| 9 | * |
| 10 | * <p> Code example that provides a "LogService" aspect that performs spell-checking of each log message. |
| 11 | * The aspect decorates a LogService. The aspect also depends on an Dictionary service that is internally used to perform log spell checking. |
| 12 | * The LogService and Dictionary services are injected in the aspect implementation using reflection on class fields: |
| 13 | * |
| 14 | * <pre>{@code |
| 15 | * public class Activator extends DependencyManagerActivator { |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 16 | * public void init(BundleContext ctx, DependencyManager dm) throws Exception { |
| 17 | * aspect(LogService.class, asp -> asp.impl(SpellCheckLogAspect.class).rank(10).withSvc(Dictionary.class)); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 18 | * } |
| 19 | * }} </pre> |
| 20 | * |
| 21 | * Same example, but using callbacks for injecting LogService and Dictionary services in the aspect implementation class: |
| 22 | * |
| 23 | * <pre>{@code |
| 24 | * public class Activator extends DependencyManagerActivator { |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 25 | * public void init(BundleContext ctx, DependencyManager dm) throws Exception { |
| 26 | * aspect(LogService.class, asp -> asp |
| 27 | * .impl(SpellCheckLogAspect.class).rank(10) |
| 28 | * .add(SpellCheckLogAspect::setLogService) |
| 29 | * .withSvc(Dictionary.class, svc -> svc.add(SpellCheckLogAspect::setDictionary))); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 30 | * } |
| 31 | * }} </pre> |
| 32 | * |
| 33 | * @param <T> the aspect service |
| 34 | */ |
| 35 | public interface ServiceAspectBuilder<T> extends ComponentBuilder<ServiceAspectBuilder<T>>, ServiceCallbacksBuilder<T, ServiceAspectBuilder<T>> { |
| 36 | /** |
| 37 | * Specifies the aspect service filter. |
| 38 | * |
| 39 | * @param filter the filter condition to use with the service interface the aspect will apply on |
| 40 | * @return this builder |
| 41 | */ |
| 42 | ServiceAspectBuilder<T> filter(String filter); |
| 43 | |
| 44 | /** |
| 45 | * Specifies the aspect ranking. Aspects of a given service are ordered by their ranking property. |
| 46 | * |
| 47 | * @param ranking the aspect ranking |
| 48 | * @return this builder |
| 49 | */ |
| 50 | ServiceAspectBuilder<T> rank(int ranking); |
| 51 | |
| 52 | /** |
| 53 | * Injects the aspect in all fields matching the aspect type. |
| 54 | * @return this builder |
| 55 | */ |
| 56 | ServiceAspectBuilder<T> autoConfig(); |
| 57 | |
| 58 | /** |
| 59 | * Configures whether or not the aspect service can be injected in all fields matching the aspect type. |
| 60 | * |
| 61 | * @param autoConfig true if the aspect service can be injected in all fields matching the dependency type |
| 62 | * @return this builder |
| 63 | */ |
| 64 | ServiceAspectBuilder<T> autoConfig(boolean autoConfig); |
| 65 | |
| 66 | /** |
| 67 | * Injects the aspect service on the field with the given name. |
| 68 | * |
| 69 | * @param field the field name where the aspect service must be injected |
| 70 | * @return this builder |
| 71 | */ |
| 72 | ServiceAspectBuilder<T> autoConfig(String field); |
| 73 | } |