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 | import org.apache.felix.dm.lambda.callbacks.SerializableLambda; |
| 22 | |
| 23 | /** |
| 24 | * Lambda allowing to define fluent service properties. Property names are deduces from the lambda parameter name. |
| 25 | * |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame] | 26 | * <p> Example of a component which provides fluent properties {"foo"="bar"; "foo2"=Integer(123)}: |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 27 | * |
| 28 | * <pre>{@code |
| 29 | * public class Activator extends DependencyManagerActivator { |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 30 | * public void init(BundleContext ctx, DependencyManager dm) throws Exception { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 31 | * component(comp -> comp.impl(MyComponentImpl.class).provides(MyService.class, foo->"bar", foo2 -> 123)); |
| 32 | * } |
| 33 | * } |
| 34 | * }</pre> |
| 35 | * |
| 36 | * <b>Caution: Fluent properties requires the usage of the "-parameter" javac option.</b> |
| 37 | * |
| 38 | * Under eclipse, you can enable this option using: |
| 39 | * |
| 40 | * <pre>{@code |
| 41 | * Windows -> Preference -> Compiler -> Classfile Generation -> Store information about method parameters. |
| 42 | * }</pre> |
| 43 | */ |
| 44 | @FunctionalInterface |
Pierre De Rop | 0aac136 | 2016-02-02 19:46:08 +0000 | [diff] [blame] | 45 | public interface FluentProperty extends SerializableLambda { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 46 | /** |
| 47 | * Represents a fluent property |
| 48 | * |
| 49 | * @param name the property name. The parameter used by the lambda will be intropsected and will be used as the actual property name. |
| 50 | * @return the property value |
| 51 | */ |
| 52 | public Object apply(String name); |
| 53 | } |