Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda.callbacks; |
| 2 | |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 3 | import java.util.Dictionary; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 4 | import java.util.Objects; |
| 5 | |
| 6 | import org.apache.felix.dm.Component; |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 7 | import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Represents a callback(Configuration, Component) which accepts a configuration type for wrapping properties |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 11 | * behind a dynamic proxy interface. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 12 | * |
| 13 | * <p> The T generic parameter represents the type of the class on which the callback is invoked on. |
| 14 | * <p> The U generic parameter represents the type of the configuration class passed to the callback argument. |
| 15 | * |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 16 | * <p> Using such callback provides a way for creating type-safe configurations from the actual {@link Dictionary} that is |
| 17 | * normally injected by Dependency Manager. |
| 18 | * For more information about configuration types, please refer to {@link ConfigurationDependencyBuilder}. |
| 19 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 20 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 21 | */ |
| 22 | @FunctionalInterface |
| 23 | public interface CbConfigurationComponent<T, U> extends SerializableLambda { |
| 24 | /** |
| 25 | * Handles the given arguments |
| 26 | * @param instance the Component implementation instance on which the callback is invoked on. |
| 27 | * @param configuration the configuration proxy |
| 28 | * @param component the callback Component |
| 29 | */ |
| 30 | void accept(T instance, U configuration, Component component); |
| 31 | |
| 32 | default CbConfigurationComponent<T, U> andThen(CbConfigurationComponent<T, U> after) { |
| 33 | Objects.requireNonNull(after); |
| 34 | return (T instance, U configuration, Component component) -> { |
| 35 | accept(instance, configuration, component); |
| 36 | after.accept(instance, configuration, component); |
| 37 | }; |
| 38 | } |
| 39 | } |