blob: 3ac90665750bd9697d9e2b5901d0ef7fa37ec471 [file] [log] [blame]
Pierre De Rop6e8f9212016-02-20 21:44:59 +00001/*
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 Ropfaca2892016-01-31 23:27:05 +000019package org.apache.felix.dm.lambda.impl;
20
21import java.util.Dictionary;
22import java.util.concurrent.CompletableFuture;
23import java.util.function.Consumer;
24import java.util.function.Function;
25import java.util.function.Supplier;
26
27import org.apache.felix.dm.lambda.BundleDependencyBuilder;
28import org.apache.felix.dm.lambda.ComponentBuilder;
29import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
Pierre De Rop0aac1362016-02-02 19:46:08 +000030import org.apache.felix.dm.lambda.FluentProperty;
Pierre De Ropfaca2892016-01-31 23:27:05 +000031import org.apache.felix.dm.lambda.FutureDependencyBuilder;
32import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
Pierre De Rop11527502016-02-18 21:07:16 +000033import org.apache.felix.dm.lambda.callbacks.Cb;
Pierre De Ropfaca2892016-01-31 23:27:05 +000034import org.apache.felix.dm.lambda.callbacks.CbComponent;
Pierre De Rop11527502016-02-18 21:07:16 +000035import org.apache.felix.dm.lambda.callbacks.InstanceCb;
36import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
Pierre De Ropfaca2892016-01-31 23:27:05 +000037
38/**
39 * Methods common to extended components like adapters or aspects.
40 *
41 * TODO javadoc
42 */
43@SuppressWarnings({"unchecked"})
44public interface AdapterBase<B extends ComponentBuilder<B>> extends ComponentBuilder<B> {
45
46 void andThenBuild(Consumer<ComponentBuilder<?>> builder);
47
48 default B impl(Object impl) {
49 andThenBuild(compBuilder -> compBuilder.impl(impl));
50 return (B) this;
51 }
52
53 default <U> B impl(Class<U> implClass) {
54 andThenBuild(compBuilder -> compBuilder.impl(implClass));
55 return (B) this;
56 }
57
58 default B factory(Object factory, String createMethod) {
59 andThenBuild(compBuilder -> compBuilder.factory(factory, createMethod));
60 return (B) this;
61 }
62
63 default B factory(Supplier<?> create) {
64 andThenBuild(compBuilder -> compBuilder.factory(create));
65 return (B) this;
66 }
67
68 default <U, V> B factory(Supplier<U> factory, Function<U, V> create) {
69 andThenBuild(compBuilder -> compBuilder.factory(factory, create));
70 return (B) this;
71 }
72
73 default B factory(Supplier<?> factory, Supplier<Object[]> getComposition) {
74 andThenBuild(compBuilder -> compBuilder.factory(factory, getComposition));
75 return (B) this;
76 }
77
78 default <U> B factory(Supplier<U> factory, Function<U, ?> create, Function<U, Object[]> getComposition) {
79 andThenBuild(compBuilder -> compBuilder.factory(factory, create, getComposition));
80 return (B) this;
81 }
82
83 default B provides(Class<?> iface) {
84 andThenBuild(compBuilder -> compBuilder.provides(iface));
85 return (B) this;
86 }
87
88 default B provides(Class<?> iface, String name, Object value, Object ... rest) {
89 andThenBuild(compBuilder -> compBuilder.provides(iface, name, value, rest));
90 return (B) this;
91 }
92
Pierre De Rop0aac1362016-02-02 19:46:08 +000093 default B provides(Class<?> iface, FluentProperty ... properties) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000094 andThenBuild(compBuilder -> compBuilder.provides(iface, properties));
95 return (B) this;
96 }
97
98 default B provides(Class<?> iface, Dictionary<?,?> properties) {
99 andThenBuild(compBuilder -> compBuilder.provides(iface, properties));
100 return (B) this;
101 }
102
103 default B provides(Class<?>[] ifaces) {
104 andThenBuild(compBuilder -> compBuilder.provides(ifaces));
105 return (B) this;
106 }
107
108 default B provides(Class<?>[] ifaces, String name, Object value, Object ... rest) {
109 andThenBuild(compBuilder -> compBuilder.provides(ifaces, name, value, rest));
110 return (B) this;
111 }
112
Pierre De Rop0aac1362016-02-02 19:46:08 +0000113 default B provides(Class<?>[] ifaces, FluentProperty ... properties) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000114 andThenBuild(compBuilder -> compBuilder.provides(ifaces, properties));
115 return (B) this;
116 }
117
118 default B provides(Class<?>[] ifaces, Dictionary<?,?> properties) {
119 andThenBuild(compBuilder -> compBuilder.provides(ifaces, properties));
120 return (B) this;
121 }
122
123 default B provides(String iface) {
124 andThenBuild(compBuilder -> compBuilder.provides(iface));
125 return (B) this;
126 }
127
128 default B provides(String iface, String name, Object value, Object ... rest) {
129 andThenBuild(compBuilder -> compBuilder.provides(iface, name, value, rest));
130 return (B) this;
131 }
132
Pierre De Rop0aac1362016-02-02 19:46:08 +0000133 default B provides(String iface, FluentProperty ... properties) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000134 andThenBuild(compBuilder -> compBuilder.provides(iface, properties));
135 return (B) this;
136 }
137
138 default B provides(String iface, Dictionary<?,?> properties) {
139 andThenBuild(compBuilder -> compBuilder.provides(iface, properties));
140 return (B) this;
141 }
142
143 default B provides(String[] ifaces) {
144 andThenBuild(compBuilder -> compBuilder.provides(ifaces));
145 return (B) this;
146 }
147
148 default B provides(String[] ifaces, String name, Object value, Object ... rest) {
149 andThenBuild(compBuilder -> compBuilder.provides(ifaces, name, value, rest));
150 return (B) this;
151 }
152
Pierre De Rop0aac1362016-02-02 19:46:08 +0000153 default B provides(String[] ifaces, FluentProperty ... properties) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000154 andThenBuild(compBuilder -> compBuilder.provides(ifaces, properties));
155 return (B) this;
156 }
157
158 default B provides(String[] ifaces, Dictionary<?,?> properties) {
159 andThenBuild(compBuilder -> compBuilder.provides(ifaces, properties));
160 return (B) this;
161 }
162
163 default B properties(Dictionary<?, ?> properties) {
164 andThenBuild(compBuilder -> compBuilder.properties(properties));
165 return (B) this;
166 }
167
168 default B properties(String name, Object value, Object ... rest) {
169 andThenBuild(compBuilder -> compBuilder.properties(name, value, rest));
170 return (B) this;
171 }
172
Pierre De Rop0aac1362016-02-02 19:46:08 +0000173 default B properties(FluentProperty ...properties) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000174 andThenBuild(compBuilder -> compBuilder.properties(properties));
175 return (B) this;
176 }
177
Pierre De Rop11527502016-02-18 21:07:16 +0000178 default B withSvc(Class<?> service, String filter) {
179 andThenBuild(compBuilder -> compBuilder.withSvc(service, filter));
Pierre De Ropfaca2892016-01-31 23:27:05 +0000180 return (B) this;
181 }
182
Pierre De Rop11527502016-02-18 21:07:16 +0000183 default B withSvc(Class<?> ... services) {
184 andThenBuild(compBuilder -> compBuilder.withSvc(services));
Pierre De Ropfaca2892016-01-31 23:27:05 +0000185 return (B) this;
186 }
187
Pierre De Rop11527502016-02-18 21:07:16 +0000188 default <U> B withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
189 andThenBuild(compBuilder -> compBuilder.withSvc(service, consumer));
Pierre De Ropfaca2892016-01-31 23:27:05 +0000190 return (B) this;
191 }
192
193 default B withCnf(Consumer<ConfigurationDependencyBuilder> consumer) {
194 andThenBuild(compBuilder -> compBuilder.withCnf(consumer));
195 return (B) this;
196 }
197
198 default B withBundle(Consumer<BundleDependencyBuilder> consumer) {
199 andThenBuild(compBuilder -> compBuilder.withBundle(consumer));
200 return (B) this;
201 }
202
203 default <U> B withFuture(CompletableFuture<U> future, Consumer<FutureDependencyBuilder<U>> consumer) {
204 andThenBuild(compBuilder -> compBuilder.withFuture(future, consumer));
205 return (B) this;
206 }
207
Pierre De Rop11527502016-02-18 21:07:16 +0000208 default B lifecycleCallbackInstance(Object lifecycleCallbackInstance) {
209 andThenBuild(compBuilder -> compBuilder.lifecycleCallbackInstance(lifecycleCallbackInstance));
210 return (B) this;
211 }
212
Pierre De Ropfaca2892016-01-31 23:27:05 +0000213 default B init(String callback) {
214 andThenBuild(compBuilder -> compBuilder.init(callback));
215 return (B) this;
216 }
217
218 default B start(String callback) {
219 andThenBuild(compBuilder -> compBuilder.start(callback));
220 return (B) this;
221 }
222
223 default B stop(String callback) {
224 andThenBuild(compBuilder -> compBuilder.stop(callback));
225 return (B) this;
226 }
227
228 default B destroy(String callback) {
229 andThenBuild(compBuilder -> compBuilder.destroy(callback));
230 return (B) this;
231 }
Pierre De Rop11527502016-02-18 21:07:16 +0000232
233 default <U> B init(Cb<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000234 andThenBuild(compBuilder -> compBuilder.init(callback));
235 return (B) this;
236 }
237
Pierre De Rop11527502016-02-18 21:07:16 +0000238 default <U> B start(Cb<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000239 andThenBuild(compBuilder -> compBuilder.start(callback));
240 return (B) this;
241 }
242
Pierre De Rop11527502016-02-18 21:07:16 +0000243 default <U> B stop(Cb<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000244 andThenBuild(compBuilder -> compBuilder.stop(callback));
245 return (B) this;
246 }
247
Pierre De Rop11527502016-02-18 21:07:16 +0000248 default <U> B destroy(Cb<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000249 andThenBuild(compBuilder -> compBuilder.destroy(callback));
250 return (B) this;
251 }
252
Pierre De Rop11527502016-02-18 21:07:16 +0000253 default <U> B init(CbComponent<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000254 andThenBuild(compBuilder -> compBuilder.init(callback));
255 return (B) this;
256 }
257
Pierre De Rop11527502016-02-18 21:07:16 +0000258 default <U> B start(CbComponent<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000259 andThenBuild(compBuilder -> compBuilder.start(callback));
260 return (B) this;
261 }
262
Pierre De Rop11527502016-02-18 21:07:16 +0000263 default <U> B stop(CbComponent<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000264 andThenBuild(compBuilder -> compBuilder.stop(callback));
265 return (B) this;
266 }
267
Pierre De Rop11527502016-02-18 21:07:16 +0000268 default <U> B destroy(CbComponent<U> callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000269 andThenBuild(compBuilder -> compBuilder.destroy(callback));
270 return (B) this;
271 }
272
Pierre De Rop11527502016-02-18 21:07:16 +0000273 default B initInstance(InstanceCb callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000274 andThenBuild(compBuilder -> compBuilder.initInstance(callback));
275 return (B) this;
276 }
277
Pierre De Rop11527502016-02-18 21:07:16 +0000278 default B startInstance(InstanceCb callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000279 andThenBuild(compBuilder -> compBuilder.startInstance(callback));
280 return (B) this;
281 }
282
Pierre De Rop11527502016-02-18 21:07:16 +0000283 default B stopInstance(InstanceCb callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000284 andThenBuild(compBuilder -> compBuilder.stopInstance(callback));
285 return (B) this;
286 }
287
Pierre De Rop11527502016-02-18 21:07:16 +0000288 default B destroyInstance(InstanceCb callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000289 andThenBuild(compBuilder -> compBuilder.destroyInstance(callback));
290 return (B) this;
291 }
292
Pierre De Rop11527502016-02-18 21:07:16 +0000293 default B initInstance(InstanceCbComponent callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000294 andThenBuild(compBuilder -> compBuilder.initInstance(callback));
295 return (B) this;
296 }
297
Pierre De Rop11527502016-02-18 21:07:16 +0000298 default B startInstance(InstanceCbComponent callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000299 andThenBuild(compBuilder -> compBuilder.startInstance(callback));
300 return (B) this;
301 }
302
Pierre De Rop11527502016-02-18 21:07:16 +0000303 default B stopInstance(InstanceCbComponent callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000304 andThenBuild(compBuilder -> compBuilder.stopInstance(callback));
305 return (B) this;
306 }
307
Pierre De Rop11527502016-02-18 21:07:16 +0000308 default B destroyInstance(InstanceCbComponent callback) {
Pierre De Ropfaca2892016-01-31 23:27:05 +0000309 andThenBuild(compBuilder -> compBuilder.destroyInstance(callback));
310 return (B) this;
311 }
312
313 default B autoConfig(Class<?> clazz, boolean autoConfig) {
314 andThenBuild(compBuilder -> compBuilder.autoConfig(clazz, autoConfig));
315 return (B) this;
316 }
317
318 default B autoConfig(Class<?> clazz, String field) {
319 andThenBuild(compBuilder -> compBuilder.autoConfig(clazz, field));
320 return (B) this;
321 }
322
323 default B debug(String label) {
324 andThenBuild(compBuilder -> compBuilder.debug(label));
325 return (B) this;
326 }
327
328 default B composition(String getCompositionMethod) {
329 andThenBuild(compBuilder -> compBuilder.composition(getCompositionMethod));
330 return (B) this;
331 }
332
333 default B composition(Object instance, String getCompositionMethod) {
334 andThenBuild(compBuilder -> compBuilder.composition(instance, getCompositionMethod));
335 return (B) this;
336 }
337
338 default B composition(Supplier<Object[]> getCompositionMethod) {
339 andThenBuild(compBuilder -> compBuilder.composition(getCompositionMethod));
340 return (B) this;
341 }
342}