felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1731147 [7/7] - in /felix/trunk/dependencymanager: org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/ org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefact...
Date Thu, 18 Feb 2016 21:07:18 GMT
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java Thu Feb 18 21:07:16 2016
@@ -29,9 +29,10 @@ import org.apache.felix.dm.lambda.Depend
 import org.apache.felix.dm.lambda.FluentProperty;
 import org.apache.felix.dm.lambda.FutureDependencyBuilder;
 import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
+import org.apache.felix.dm.lambda.callbacks.Cb;
 import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbConsumer;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCb;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
 
 public class ComponentBuilderImpl implements ComponentBuilder<ComponentBuilderImpl> {
     private final List<DependencyBuilder<?>> m_dependencyBuilders = new ArrayList<>();
@@ -369,12 +370,12 @@ public class ComponentBuilderImpl implem
     }
 
     @Override
-    public ComponentBuilderImpl withSrv(Class<?> service, String filter) {
-        return withSrv(service, srv->srv.filter(filter));
+    public ComponentBuilderImpl withSvc(Class<?> service, String filter) {
+        return withSvc(service, srv->srv.filter(filter));
     }   
 
     @Override
-    public ComponentBuilderImpl withSrv(Class<?> ... services) {
+    public ComponentBuilderImpl withSvc(Class<?> ... services) {
         for (Class<?> s : services) {
             doWithService(s);
         }
@@ -387,7 +388,7 @@ public class ComponentBuilderImpl implem
     }
 
     @Override
-    public <U> ComponentBuilderImpl withSrv(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
+    public <U> ComponentBuilderImpl withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
         ServiceDependencyBuilder<U> dep = new ServiceDependencyBuilderImpl<>(m_component, service);
         consumer.accept(dep);
         m_dependencyBuilders.add(dep);
@@ -418,6 +419,11 @@ public class ComponentBuilderImpl implem
         return this;
     }
     
+    public ComponentBuilderImpl lifecycleCallbackInstance(Object callbackInstance) {
+        m_callbackInstance = callbackInstance;
+        return this;
+    }    
+
     public ComponentBuilderImpl init(String callback) {
         ensureHasNoLifecycleMethodRefs();
         m_init = callback;
@@ -442,132 +448,112 @@ public class ComponentBuilderImpl implem
         return this;
     }
     
-    public ComponentBuilderImpl init(Object callbackInstance, String callback) {
-        m_callbackInstance = callbackInstance;
-        return init(callback);
-    }    
-
-    public ComponentBuilderImpl start(Object callbackInstance, String callback) {
-        m_callbackInstance = callbackInstance;
-        return start(callback);
-    }    
-
-    public ComponentBuilderImpl stop(Object callbackInstance, String callback) {
-        m_callbackInstance = callbackInstance;
-        return stop(callback);
-    }    
-
-    public ComponentBuilderImpl destroy(Object callbackInstance, String callback) {
-        m_callbackInstance = callbackInstance;
-        return destroy(callback);
-    }    
-
     @SuppressWarnings("unchecked")
     @Override
-    public <U> ComponentBuilderImpl init(CbConsumer<U> callback) {
+    public <T> ComponentBuilderImpl init(Cb<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+            setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
         }
         return this;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public <U> ComponentBuilderImpl start(CbConsumer<U> callback) {
+    public <T> ComponentBuilderImpl start(Cb<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+            setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
         }
         return this;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public <U> ComponentBuilderImpl stop(CbConsumer<U> callback) {
+    public <T> ComponentBuilderImpl stop(Cb<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+            setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
         }
         return this;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public <U> ComponentBuilderImpl destroy(CbConsumer<U> callback) {
+    public <T> ComponentBuilderImpl destroy(Cb<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+            setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
         }
         return this;
     }
 
    @SuppressWarnings("unchecked")
    @Override
-    public <U> ComponentBuilderImpl init(CbTypeComponent<U> callback) {
+    public <T> ComponentBuilderImpl init(CbComponent<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+            setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
         }
         return this;
     }
             
    @SuppressWarnings("unchecked")
    @Override
-    public <U> ComponentBuilderImpl start(CbTypeComponent<U> callback) {
+    public <T> ComponentBuilderImpl start(CbComponent<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+            setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
         }
         return this;
     }
             
    @SuppressWarnings("unchecked")
    @Override
-    public <U> ComponentBuilderImpl stop(CbTypeComponent<U> callback) {
+    public <T> ComponentBuilderImpl stop(CbComponent<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+            setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
         }
         return this;
     }
             
    @SuppressWarnings("unchecked")
    @Override
-    public <U> ComponentBuilderImpl destroy(CbTypeComponent<U> callback) {
+    public <T> ComponentBuilderImpl destroy(CbComponent<T> callback) {
         if (callback != null) {
-            setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+            setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
         }
         return this;
     }
             
     @Override
-    public ComponentBuilderImpl initInstance(Runnable callback) {
+    public ComponentBuilderImpl initInstance(InstanceCb callback) {
         if (callback != null) {
-            setInstanceCallbackRef(INIT, (inst, component) -> callback.run());
+            setInstanceCallbackRef(INIT, (inst, component) -> callback.cb());
         }
         return this;
     }
     
     @Override
-    public ComponentBuilderImpl startInstance(Runnable callback) {
+    public ComponentBuilderImpl startInstance(InstanceCb callback) {
         if (callback != null) {
-            setInstanceCallbackRef(START, (inst, component) -> callback.run());
+            setInstanceCallbackRef(START, (inst, component) -> callback.cb());
         }
         return this;
     }
 
     @Override
-    public ComponentBuilderImpl stopInstance(Runnable callback) {
+    public ComponentBuilderImpl stopInstance(InstanceCb callback) {
         if (callback != null) {
-            setInstanceCallbackRef(STOP, (inst, component) -> callback.run());
+            setInstanceCallbackRef(STOP, (inst, component) -> callback.cb());
         }
         return this;
     }
 
     @Override
-    public ComponentBuilderImpl destroyInstance(Runnable callback) {
+    public ComponentBuilderImpl destroyInstance(InstanceCb callback) {
         if (callback != null) {
-            setInstanceCallbackRef(DESTROY, (inst, component) -> callback.run());
+            setInstanceCallbackRef(DESTROY, (inst, component) -> callback.cb());
         }
         return this;
     }
         
     @Override
-    public ComponentBuilderImpl initInstance(CbComponent callback) {
+    public ComponentBuilderImpl initInstance(InstanceCbComponent callback) {
         if (callback != null) {
             setInstanceCallbackRef(INIT, (inst, component) -> callback.accept(component));
         }
@@ -575,7 +561,7 @@ public class ComponentBuilderImpl implem
     }
   
     @Override
-    public ComponentBuilderImpl startInstance(CbComponent callback) {
+    public ComponentBuilderImpl startInstance(InstanceCbComponent callback) {
         if (callback != null) {
             setInstanceCallbackRef(START, (inst, component) -> callback.accept(component));
         }
@@ -583,7 +569,7 @@ public class ComponentBuilderImpl implem
     }
 
     @Override
-    public ComponentBuilderImpl stopInstance(CbComponent callback) {
+    public ComponentBuilderImpl stopInstance(InstanceCbComponent callback) {
         if (callback != null) {
             setInstanceCallbackRef(STOP, (inst, component) -> callback.accept(component));
         }
@@ -591,7 +577,7 @@ public class ComponentBuilderImpl implem
     }
 
     @Override
-    public ComponentBuilderImpl destroyInstance(CbComponent callback) {
+    public ComponentBuilderImpl destroyInstance(InstanceCbComponent callback) {
         if (callback != null) {
             setInstanceCallbackRef(DESTROY, (inst, component) -> callback.accept(component));
         }

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java Thu Feb 18 21:07:16 2016
@@ -8,23 +8,28 @@ import java.util.stream.Stream;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.ConfigurationDependency;
+import org.apache.felix.dm.context.ComponentContext;
 import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
 import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
 
 public class ConfigurationDependencyBuilderImpl implements ConfigurationDependencyBuilder {
     private String m_pid;
     private boolean m_propagate;
     private final Component m_component;
-    private String m_updateMethodName;
+    private String m_updateMethodName = "updated";
     private Object m_updateCallbackInstance;
     private boolean m_hasMethodRefs;
     private boolean m_hasReflectionCallback;
     private final List<MethodRef<Object>> m_refs = new ArrayList<>();
     private boolean m_hasComponentCallbackRefs;
-    private boolean m_needsInstance = false;
+    private Class<?> m_configType;
     
     @FunctionalInterface
     interface MethodRef<I> {
@@ -40,13 +45,7 @@ public class ConfigurationDependencyBuil
         m_pid = pid;
         return this;
     }
-
-    @Override
-    public ConfigurationDependencyBuilder pid(Class<?> pidClass) {
-        m_pid = pidClass.getName();
-        return this;
-    }
-
+    
     @Override
     public ConfigurationDependencyBuilder propagate() {
         m_propagate = true;
@@ -59,58 +58,107 @@ public class ConfigurationDependencyBuil
         return this;
     }
 
-    public ConfigurationDependencyBuilder cb(String update) {
+    public ConfigurationDependencyBuilder update(String update) {
         checkHasNoMethodRefs();
         m_hasReflectionCallback = true;
         m_updateMethodName = update;
         return this;
     }
     
-    public ConfigurationDependencyBuilder cbi(Object callbackInstance, String update) {
+    public ConfigurationDependencyBuilder update(Class<?> configType, String updateMethod) {
+        m_configType = configType;
+        return update(updateMethod);
+    }
+
+    public ConfigurationDependencyBuilder update(Object callbackInstance, String update) {
         m_updateCallbackInstance = callbackInstance;
-        cb(update);
+        update(update);
         return this;
     }
+    
+    public ConfigurationDependencyBuilder update(Class<?> configType, Object callbackInstance, String update) {
+        m_updateCallbackInstance = callbackInstance;
+        return update(callbackInstance, update);        
+    }
 
-    public ConfigurationDependencyBuilder needsInstance(boolean needsInstance) {
-        m_needsInstance = needsInstance;
-        return this;
+    @Override
+    public <T> ConfigurationDependencyBuilder update(CbDictionary<T> callback) {
+        Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+        return setComponentCallbackRef(componentType, (instance, component, props) -> { 
+            callback.accept((T) instance, props);
+        }); 
     }
 
     @Override
-    public <T> ConfigurationDependencyBuilder cb(CbTypeDictionary<T>  callback) {
-        Class<T> type = Helpers.getLambdaArgType(callback, 0);
-        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props); });
+    public <T> ConfigurationDependencyBuilder update(CbDictionaryComponent<T> callback) {
+        Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+        return setComponentCallbackRef(componentType, (instance, component, props) -> { 
+            callback.accept((T) instance, props, component);
+        }); 
     }
 
     @Override
-    public <T> ConfigurationDependencyBuilder cb(CbTypeComponentDictionary<T>  callback) {
-        Class<T> type = Helpers.getLambdaArgType(callback, 0);
-        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, component, props); });
+    public <T, U> ConfigurationDependencyBuilder update(Class<U> configClass, CbConfiguration<T, U> callback) {
+        Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+        m_pid = m_pid == null ? configClass.getName() : m_pid;
+        return setComponentCallbackRef(componentType, (instance, component, props) -> { 
+            U configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);            
+            callback.accept((T) instance, configProxy);
+        }); 
     }
 
     @Override
-    public ConfigurationDependencyBuilder cbi(CbDictionary callback) {
-        return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props); });
+    public <T, U> ConfigurationDependencyBuilder update(Class<U> configClass, CbConfigurationComponent<T, U> callback) {
+        Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+        m_pid = m_pid == null ? configClass.getName() : m_pid;
+        return setComponentCallbackRef(componentType, (instance, component, props) -> { 
+            U configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);            
+            callback.accept((T) instance, configProxy, component);
+        }); 
     }
-    
+
     @Override
-    public ConfigurationDependencyBuilder cbi(CbComponentDictionary callback) {
-        return setInstanceCallbackRef((instance, component, props) -> { callback.accept(component, props); });
+    public ConfigurationDependencyBuilder update(InstanceCbDictionary callback) {
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            callback.accept(props);
+        });
     }
 
     @Override
+    public ConfigurationDependencyBuilder update(InstanceCbDictionaryComponent callback) {
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            callback.accept(props, component);
+        });
+    }
+
+    public <T> ConfigurationDependencyBuilder update(Class<T> configClass, InstanceCbConfiguration<T> updated) {
+        m_pid = m_pid == null ? configClass.getName() : m_pid;
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            T configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+            updated.accept(configProxy);
+        });
+    }
+    
+    public <T> ConfigurationDependencyBuilder update(Class<T> configClass, InstanceCbConfigurationComponent<T> updated) {
+        m_pid = m_pid == null ? configClass.getName() : m_pid;
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            T configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+            updated.accept(configProxy, component);
+        });
+    }
+    
+    @Override
     public ConfigurationDependency build() {
+        String pid = m_pid == null ? (m_configType != null ? m_configType.getName() : null) : m_pid;
+        if (pid == null) {
+            throw new IllegalStateException("Pid not specified");
+        }
         ConfigurationDependency dep = m_component.getDependencyManager().createConfigurationDependency();
         Objects.nonNull(m_pid);
-        dep.setPid(m_pid);
+        dep.setPid(pid);
         dep.setPropagate(m_propagate);
         if (m_updateMethodName != null) {
-            if (m_updateCallbackInstance != null) {
-                dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_needsInstance);
-            } else {
-                dep.setCallback(m_updateMethodName);
-            }
+            dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_configType);
         } else if (m_refs.size() > 0) {
             // setup an internal callback object. When config is updated, we have to call each registered 
             // method references. 
@@ -121,7 +169,7 @@ public class ConfigurationDependencyBuil
                 void updated(Component comp, Dictionary<String, Object> props) {
                     m_refs.forEach(mref -> mref.accept(null, comp, props));
                 }
-            }, "updated", m_hasComponentCallbackRefs||m_needsInstance);
+            }, "updated", m_hasComponentCallbackRefs);
         }
         return dep;
     }
@@ -129,6 +177,7 @@ public class ConfigurationDependencyBuil
     private <T> ConfigurationDependencyBuilder setInstanceCallbackRef(MethodRef<T> ref) {
         checkHasNoReflectionCallbacks();
         m_hasMethodRefs = true;
+        m_updateMethodName = null;
         m_refs.add((instance, component, props) -> ref.accept(null, component, props));
         return this;
     }
@@ -136,6 +185,7 @@ public class ConfigurationDependencyBuil
     @SuppressWarnings("unchecked")
     private <T> ConfigurationDependencyBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) {
         checkHasNoReflectionCallbacks();
+        m_updateMethodName = null;
         m_hasMethodRefs = true;
         m_hasComponentCallbackRefs = true;
         m_refs.add((instance, component, props) -> {

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java Thu Feb 18 21:07:16 2016
@@ -9,12 +9,17 @@ import java.util.stream.Stream;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.context.ComponentContext;
 import org.apache.felix.dm.lambda.ComponentBuilder;
 import org.apache.felix.dm.lambda.FactoryPidAdapterBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
 import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
 
 public class FactoryPidAdapterBuilderImpl implements AdapterBase<FactoryPidAdapterBuilder>, FactoryPidAdapterBuilder {
     private String m_factoryPid;
@@ -27,6 +32,7 @@ public class FactoryPidAdapterBuilderImp
     private boolean m_hasReflectionCallback;
     private Consumer<ComponentBuilder<?>> m_compBuilder = (componentBuilder -> {});
     private final List<MethodRef<Object>> m_refs = new ArrayList<>();
+    private Class<?> m_configType;
 
     @FunctionalInterface
     interface MethodRef<I> {
@@ -58,12 +64,6 @@ public class FactoryPidAdapterBuilderImp
     }
 
     @Override
-    public FactoryPidAdapterBuilder factoryPid(Class<?> pidClass) {
-        m_factoryPid = pidClass.getName();
-        return this;
-    }
-
-    @Override
     public FactoryPidAdapterBuilder propagate() {
         m_propagate = true;
         return this;
@@ -75,39 +75,91 @@ public class FactoryPidAdapterBuilderImp
         return this;
     }
 
-    public FactoryPidAdapterBuilder cb(String update) {
+    @Override
+    public FactoryPidAdapterBuilder update(String update) {
         checkHasNoMethodRefs();
         m_hasReflectionCallback = true;
         m_updateMethodName = update;
         return this;
     }
     
-    public FactoryPidAdapterBuilder cb(Object callbackInstance, String update) {
-        cb(update);
+    @Override
+    public FactoryPidAdapterBuilder update(Class<?> configType, String updateMethod) {
+        update(updateMethod);
+        m_configType = configType;
+        return this;
+    }
+    
+    @Override
+    public FactoryPidAdapterBuilder update(Object callbackInstance, String update) {
+        update(update);
         m_updateCallbackInstance = callbackInstance;
         return this;
     }
     
     @Override
-    public <U> FactoryPidAdapterBuilder cb(CbTypeDictionary<U> callback) {
-        Class<U> type = Helpers.getLambdaArgType(callback, 0);
-        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((U) instance, props); });
+    public FactoryPidAdapterBuilder update(Class<?> configType, Object callbackInstance, String updateMethod) {
+        update(callbackInstance, updateMethod);
+        m_configType = configType;
+        return this;
+    }
+    
+    @Override
+    public <T> FactoryPidAdapterBuilder update(CbDictionary<T> callback) {
+        Class<T> type = Helpers.getLambdaArgType(callback, 0);
+        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props); });
+    }
+    
+    @Override
+    public <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfiguration<T, U> callback) {
+        Class<T> type = Helpers.getLambdaArgType(callback, 0);
+        m_factoryPid = m_factoryPid == null ? configType.getName() : m_factoryPid;
+        return setComponentCallbackRef(type, (instance, component, props) -> {
+            U configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);            
+            callback.accept((T) instance, configProxy); 
+        });
     }
     
     @Override
-    public <U> FactoryPidAdapterBuilder cb(CbTypeComponentDictionary<U> callback) {
-        Class<U> type = Helpers.getLambdaArgType(callback, 0);
-        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((U) instance, component, props); });
+    public <T> FactoryPidAdapterBuilder update(CbDictionaryComponent<T> callback) {
+        Class<T> type = Helpers.getLambdaArgType(callback, 0);
+        return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props, component); });
+    }
+
+    @Override
+    public <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfigurationComponent<T, U> callback) {
+        Class<T> type = Helpers.getLambdaArgType(callback, 0);
+        m_factoryPid = m_factoryPid == null ? configType.getName() : m_factoryPid;
+        return setComponentCallbackRef(type, (instance, component, props) -> { 
+            U configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);            
+            callback.accept((T) instance, configProxy, component); 
+        });
     }
 
     @Override
-    public FactoryPidAdapterBuilder cbi(CbDictionary callback) {
+    public FactoryPidAdapterBuilder update(InstanceCbDictionary callback) {
         return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props); });
     }
+    
+    @Override
+    public <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfiguration<T> callback) {
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            T configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);            
+            callback.accept(configProxy);
+        });
+    }
 
     @Override
-    public FactoryPidAdapterBuilder cbi(CbComponentDictionary callback) {
-        return setInstanceCallbackRef((instance, component, props) -> { callback.accept(component, props); });
+    public FactoryPidAdapterBuilder update(InstanceCbDictionaryComponent callback) {
+        return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props, component); });
+    }
+
+    @Override
+    public <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfigurationComponent<T> callback) {
+        return setInstanceCallbackRef((instance, component, props) -> { 
+            T configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);            
+            callback.accept(configProxy, component);
+        });
     }
 
     @Override
@@ -124,14 +176,14 @@ public class FactoryPidAdapterBuilderImp
             };
             c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, "updated", m_propagate, wrapCallback);
         } else {
-            c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, m_updateMethodName, m_propagate, m_updateCallbackInstance);
+            c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, m_updateMethodName, m_propagate, m_updateCallbackInstance, m_configType);
         }
         ComponentBuilderImpl cb = new ComponentBuilderImpl(c, false);
         m_compBuilder.accept (cb);
         return cb.build();
     }
     
-    private <U> FactoryPidAdapterBuilder setInstanceCallbackRef(MethodRef<U> ref) {
+    private <T> FactoryPidAdapterBuilder setInstanceCallbackRef(MethodRef<T> ref) {
         checkHasNoReflectionCallbacks();
         m_hasMethodRefs = true;
         m_refs.add((instance, component, props) -> ref.accept(null, component, props));
@@ -139,7 +191,7 @@ public class FactoryPidAdapterBuilderImp
     }
     
     @SuppressWarnings("unchecked")
-    private <U> FactoryPidAdapterBuilder setComponentCallbackRef(Class<U> type, MethodRef<U> ref) {
+    private <T> FactoryPidAdapterBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) {
         checkHasNoReflectionCallbacks();
         m_hasMethodRefs = true;
         m_refs.add((instance, component, props) -> {
@@ -147,7 +199,7 @@ public class FactoryPidAdapterBuilderImp
                 .filter(impl -> Helpers.getClass(impl).equals(type))
                 .findFirst()
                 .orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes."));
-            ref.accept((U) componentImpl, component, props);
+            ref.accept((T) componentImpl, component, props);
         });
         return this;
     }

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java Thu Feb 18 21:07:16 2016
@@ -12,6 +12,7 @@ import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 import org.apache.felix.dm.Component;
+import org.apache.felix.dm.context.ComponentContext;
 import org.apache.felix.dm.lambda.callbacks.SerializableLambda;
 
 /**
@@ -19,8 +20,31 @@ import org.apache.felix.dm.lambda.callba
  */
 public class Helpers {
 	private final static Pattern LAMBDA_INSTANCE_METHOD_TYPE = Pattern.compile("(L[^;]+)+");
+	private final static String DEFAULT_DEPENDENCY_MODE = "org.apache.felix.dependencymanager.lambda.dependencymode";
+	private final static String REQUIRED = "required";
+	private final static String OPTIONAL = "optional";
 
 	/**
+	 * Tests if a dependency is required by default.
+	 * By default, a dependency is required, but you can configure the mode of a dependency, by configure the
+	 * DEFAULT_DEPENDENCY_MODE property in the bundle context properties. This property can take as value:
+	 * <ul><li>"required" meaning that dependencies are required by default,
+	 * <li>"optional" meaning that dependencies are optional by default.
+	 * </ul>
+	 * By default, a dependency is required.
+	 */
+	static boolean isDependencyRequiredByDefault(Component component) {
+	    String property = ((ComponentContext) component).getBundleContext().getProperty(DEFAULT_DEPENDENCY_MODE);
+	    if (REQUIRED.equalsIgnoreCase(property)) {
+	        return true;
+	    } else if (OPTIONAL.equalsIgnoreCase(property)) {
+	        return false;
+	    } else {
+	        return true;
+	    }
+	}
+	
+	/**
 	 * Gets the class name of a given object.
 	 * @param obj the object whose class has to be returned.
 	 */

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java Thu Feb 18 21:07:16 2016
@@ -4,38 +4,30 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
 import java.util.stream.Stream;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.lambda.ServiceCallbacksBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbRef;
-import org.apache.felix.dm.lambda.callbacks.CbRefService;
 import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefServiceComponent;
 import org.apache.felix.dm.lambda.callbacks.CbService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponentRef;
 import org.apache.felix.dm.lambda.callbacks.CbServiceDict;
 import org.apache.felix.dm.lambda.callbacks.CbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.CbServiceRef;
 import org.apache.felix.dm.lambda.callbacks.CbServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceDict;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceMap;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponentRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceDict;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceServiceComponent;
 import org.osgi.framework.ServiceReference;
 
 /**
@@ -119,39 +111,29 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;
     }
 	
-    public B cb(String ... callbacks) {
-        return cbi(null, callbacks);
-    }
-    
-    public B cbi(Object callbackInstance, String ... callbacks) {
-        Objects.nonNull(callbacks);
-        switch (callbacks.length) {
-        case 1:
-            cb(callbackInstance, callbacks[0], null, null, null);
-            break;
-            
-        case 2:
-            cb(callbackInstance, callbacks[0], null, callbacks[1], null);
-            break;
-            
-        case 3:
-            cb(callbackInstance, callbacks[0], callbacks[1], callbacks[2], null);
-            break;
-            
-        case 4:
-            cb(callbackInstance, callbacks[0], callbacks[1], callbacks[2], callbacks[3]);
-            break;
-            
-        default:
-            throw new IllegalArgumentException("wrong number of arguments: " + callbacks.length + ". " +
-                "Possible arguments: [add], [add, remove], [add, change, remove], or [add, change, remove, swap]");
-        }
+    public B callbackInstance(Object callbackInstance) {
+        m_callbackInstance = callbackInstance;
         return (B) this;
     }
     
-    private B cb(Object callbackInstance, String added, String changed, String removed, String swapped) {
+    public B add(String add) {
+        return callbacks(add, null, null, null);
+    }
+        
+    public B change(String change) {
+        return callbacks(null, change, null, null);
+    }
+        
+    public B remove(String remove) {
+        return callbacks(null, null, remove, null);
+    }
+        
+    public B swap(String swap) {
+        return callbacks(null, null, null, swap);
+    }
+        
+    private B callbacks(String added, String changed, String removed, String swapped) {
 		requiresNoMethodRefs();
-        m_callbackInstance = callbackInstance;
 		m_added = added != null ? added : m_added;
 		m_changed = changed != null ? changed : m_changed;
 		m_removed = removed != null ? removed : m_removed;
@@ -160,15 +142,19 @@ public class ServiceCallbacksBuilderImpl
 		return (B) this;
 	}
 
-    public <T> B cb(CbTypeService<T, S> add) {
-        return cb(add, null, null);
+    public <T> B add(CbService<T, S> add) {
+        return callbacks(add, null, null);
+    }
+    
+    public <T> B change(CbService<T, S> change) {
+        return callbacks(null, change, null);
     }
     
-    public <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> remove) {
-        return cb(add, null, remove);
+    public <T> B remove(CbService<T, S> remove) {
+        return callbacks(null, null, remove);
     }
     
-    public <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> change, CbTypeService<T, S> remove) {
+    private <T> B callbacks(CbService<T, S> add, CbService<T, S> change, CbService<T, S> remove) {
         if (add != null)
             setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv));
         if (change != null)
@@ -178,15 +164,19 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;
     }
 
-    public B cbi(CbService<S> add) {
-        return cbi(add, null, null);
+    public B add(InstanceCbService<S> add) {
+        return callbacks(add, null, null);
     }
     
-    public B cbi(CbService<S> add, CbService<S> remove) {
-        return cbi(add, null, remove);
+    public B change(InstanceCbService<S> change) {
+        return callbacks(null, change, null);
+    }
+
+    public B remove(InstanceCbService<S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbService<S> add, CbService<S> change, CbService<S> remove) {
+    public B callbacks(InstanceCbService<S> add, InstanceCbService<S> change, InstanceCbService<S> remove) {
         if (add != null)
             setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv));
         if (change != null)
@@ -196,15 +186,19 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;        
     }
     
-    public <T> B cb(CbTypeServiceMap<T, S> add) {
-        return cb(add, null, null);
+    public <T> B add(CbServiceMap<T, S> add) {
+        return callbacks(add, null, null);
     }
     
-    public <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> remove) {
-        return cb(add, null, remove);
+    public <T> B change(CbServiceMap<T, S> change) {
+        return callbacks(null, change, null);
     }
-
-    public <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> change, CbTypeServiceMap<T, S> remove) {
+    
+    public <T> B remove(CbServiceMap<T, S> remove) {
+        return callbacks(null, null, remove);
+    }
+    
+    public <T> B callbacks(CbServiceMap<T, S> add, CbServiceMap<T, S> change, CbServiceMap<T, S> remove) {
         if (add != null)
             setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, new SRefAsMap(ref)));
         if (change != null)
@@ -214,15 +208,19 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;        
     }
     
-    public B cbi(CbServiceMap<S> add) {
-        return cbi(add, null, null);
+    public B add(InstanceCbServiceMap<S> add) {
+        return callbacks(add, null, null);
     }
     
-    public B cbi(CbServiceMap<S> add, CbServiceMap<S> remove) {
-        return cbi(add, null, remove);
+    public B change(InstanceCbServiceMap<S> change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbServiceMap<S> add, CbServiceMap<S> change, CbServiceMap<S> remove) {
+    public B remove(InstanceCbServiceMap<S> remove) {
+        return callbacks(null, null, remove);
+    }
+
+    public B callbacks(InstanceCbServiceMap<S> add, InstanceCbServiceMap<S> change, InstanceCbServiceMap<S> remove) {
         if (add != null)
             setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, new SRefAsMap(ref)));   
         if (change != null)
@@ -232,15 +230,19 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;        
     }
 
-    public <T> B cb(CbTypeServiceDict<T, S> add) {
-        return cb(add, null, null);
+    public <T> B add(CbServiceDict<T, S> add) {
+        return callbacks(add, null, null);
     }
-
-    public <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> remove) {
-        return cb(add, null, remove);
+    
+    public <T> B change(CbServiceDict<T, S> change) {
+        return callbacks(null, change, null);
     }
     
-    public <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> change, CbTypeServiceDict<T, S> remove) {
+    public <T> B remove(CbServiceDict<T, S> remove) {
+        return callbacks(null, null, remove);
+    }
+    
+    public <T> B callbacks(CbServiceDict<T, S> add, CbServiceDict<T, S> change, CbServiceDict<T, S> remove) {
         if (add != null)
             setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, new SRefAsDictionary(ref)));
         if (change != null) 
@@ -250,15 +252,19 @@ public class ServiceCallbacksBuilderImpl
         return (B) this;  
     }
 
-    public B cbi(CbServiceDict<S> add) {
-        return cbi(add, null, null);
+    public B add(InstanceCbServiceDict<S> add) {
+        return callbacks(add, null, null);
     }
     
-    public B cbi(CbServiceDict<S> add, CbServiceDict<S> remove) {
-        return cbi(add, null, remove);
+    public B change(InstanceCbServiceDict<S> change) {
+        return callbacks(null, change, null);
+    }
+
+    public B remove(InstanceCbServiceDict<S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbServiceDict<S> add, CbServiceDict<S> change, CbServiceDict<S> remove) {
+    public B callbacks(InstanceCbServiceDict<S> add, InstanceCbServiceDict<S> change, InstanceCbServiceDict<S> remove) {
         if (add != null)
             setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, new SRefAsDictionary(ref)));   
         if (change != null)
@@ -267,261 +273,178 @@ public class ServiceCallbacksBuilderImpl
             setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, new SRefAsDictionary(ref)));
         return (B) this;        
     }
-
-    public <T> B cb(CbTypeRefService<T, S> add) {
-        return cb(add, null, null);
-    }
-
-    public <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> remove) {
-        return cb(add, null, remove);
-    }
-
-    public <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> change, CbTypeRefService<T, S> remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, ref, srv)); 
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, ref, srv)); 
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, ref, srv)); 
-        return (B) this;
+    
+    public <T> B add(CbServiceRef<T, S> add) {
+        return callbacks(add, null, null);
     }
 
-    public B cbi(CbRefService<S> add) {
-        return cbi(add, null, null);
+    public <T> B change(CbServiceRef<T, S> change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbRefService<S> add, CbRefService<S> remove) {
-        return cbi(add, null, remove);
+    public <T> B remove(CbServiceRef<T, S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbRefService<S> add, CbRefService<S> change, CbRefService<S> remove) {
+    public <T> B callbacks(CbServiceRef<T, S> add, CbServiceRef<T, S> change, CbServiceRef<T, S> remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(ref, srv)); 
+            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, ref));
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(ref, srv)); 
+            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, ref)); 
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(ref, srv)); 
+            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, ref)); 
         return (B) this;
     }
-    
-    public <T> B cb(CbTypeRef<T, S> add) {
-        return cb(add, null, null);
-    }
 
-    public <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> remove) {
-        return cb(add, null, remove);
+    public B add(InstanceCbServiceRef<S> add) {
+        return callbacks(add, null, null);
     }
 
-    public <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> change, CbTypeRef<T, S> remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, ref));
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, ref)); 
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, ref)); 
-        return (B) this;
-    }
-
-    public B cbi(CbRef<S> add) {
-        return cbi(add, null, null);
+    public B change(InstanceCbServiceRef<S> change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbRef<S> add, CbRef<S> remove) {
-        return cbi(add, null, remove);
+    public B remove(InstanceCbServiceRef<S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbRef<S> add, CbRef<S> change, CbRef<S> remove) {
+    public B callbacks(InstanceCbServiceRef<S> add, InstanceCbServiceRef<S> change, InstanceCbServiceRef<S> remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(ref)); 
+            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, ref)); 
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(ref)); 
+            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, ref)); 
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(ref)); 
+            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, ref)); 
         return (B) this;
     }
-
-    public <T> B cb(CbTypeComponent<T> add) {
-        return cb(add, null, null);
-    }
-
-    public <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> remove) {
-        return cb(add, null, remove);
-    }
-
-    public <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> change, CbTypeComponent<T> remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp));              
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp));              
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp)); 
-        return (B) this;
+    
+    public <T> B add(CbServiceComponent<T, S>  add) {
+        return callbacks(add, null, null);
     }
 
-    public B cbi(CbComponent add) {
-        return cbi(add, null, null);
+    public <T> B change(CbServiceComponent<T, S>  change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbComponent add, CbComponent remove) {
-        return cbi(add, null, remove);
+    public <T> B remove(CbServiceComponent<T, S>  remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbComponent add, CbComponent change, CbComponent remove) {
+    private <T> B callbacks(CbServiceComponent<T, S>  add, CbServiceComponent<T, S>  change, CbServiceComponent<T, S>  remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp)); 
+            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, comp)); 
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp)); 
+            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, comp)); 
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp)); 
+            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, comp)); 
         return (B) this;
     }
 
-    public <T> B cb(CbTypeComponentRef<T, S>  add) {
-        return cb(add, null, null);
-    }
-
-    public <T> B cb(CbTypeComponentRef<T, S>  add, CbTypeComponentRef<T, S>  remove) {
-        return cb(add, null, remove);
-    }
-
-    public <T> B cb(CbTypeComponentRef<T, S>  add, CbTypeComponentRef<T, S>  change, CbTypeComponentRef<T, S>  remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, ref));              
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, ref)); 
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, ref)); 
-        return (B) this;      
+    public B add(InstanceCbServiceComponent<S> add) {
+        return callbacks(add, null, null);
     }
 
-    public B cbi(CbComponentRef<S> add) {
-        return cbi(add, null, null);
+    public B change(InstanceCbServiceComponent<S> change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbComponentRef<S> add, CbComponentRef<S> remove) {
-        return cbi(add, null, remove);
+    public B remove(InstanceCbServiceComponent<S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbComponentRef<S> add, CbComponentRef<S> change, CbComponentRef<S> remove) {
+    public B callbacks(InstanceCbServiceComponent<S> add, InstanceCbServiceComponent<S> change, InstanceCbServiceComponent<S> remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, ref));
+            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, comp));
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, ref));
+            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, comp));
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, ref));
+            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, comp));
         return (B) this;
     }
 
-    public <T> B cb(CbTypeComponentService<T, S>  add) {
-        return cb(add, null, null);
-    }
-
-    public <T> B cb(CbTypeComponentService<T, S>  add, CbTypeComponentService<T, S>  remove) {
-        return cb(add, null, remove);
-    }
-
-    public <T> B cb(CbTypeComponentService<T, S>  add, CbTypeComponentService<T, S>  change, CbTypeComponentService<T, S>  remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, srv)); 
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, srv)); 
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, srv)); 
-        return (B) this;
+    public <T> B add(CbServiceComponentRef<T, S>  add) {
+        return callbacks(add, null, null);
     }
 
-    public B cbi(CbComponentService<S> add) {
-        return cbi(add, null, null);
+    public <T> B change(CbServiceComponentRef<T, S>  change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbComponentService<S> add, CbComponentService<S> remove) {
-        return cbi(add, null, remove);
+    public <T> B remove(CbServiceComponentRef<T, S>  remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbComponentService<S> add, CbComponentService<S> change, CbComponentService<S> remove) {
+    private <T> B callbacks(CbServiceComponentRef<T, S>  add, CbServiceComponentRef<T, S>  change, CbServiceComponentRef<T, S>  remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, srv));
+            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, comp, ref)); 
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, srv));
+            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, comp, ref)); 
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, srv));
+            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, comp, ref)); 
         return (B) this;
     }
 
-    public <T> B cb(CbTypeComponentRefService<T, S>  add) {
-        return cb(add, null, null);
-    }
-
-    public <T> B cb(CbTypeComponentRefService<T, S>  add, CbTypeComponentRefService<T, S>  remove) {
-        return cb(add, null, remove);
-    }
-
-    public <T> B cb(CbTypeComponentRefService<T, S>  add, CbTypeComponentRefService<T, S>  change, CbTypeComponentRefService<T, S>  remove) {
-        if (add != null)
-            setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, ref, srv)); 
-        if (change != null)
-            setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, ref, srv)); 
-        if (remove != null)
-            setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, ref, srv)); 
-        return (B) this;
+    public B add(InstanceCbServiceComponentRef<S> add) {
+        return callbacks(add, null, null);
     }
 
-    public B cbi(CbComponentRefService<S> add) {
-        return cbi(add, null, null);
+    public B change(InstanceCbServiceComponentRef<S> change) {
+        return callbacks(null, change, null);
     }
 
-    public B cbi(CbComponentRefService<S> add, CbComponentRefService<S> remove) {
-        return cbi(add, null, remove);
+    public B remove(InstanceCbServiceComponentRef<S> remove) {
+        return callbacks(null, null, remove);
     }
 
-    public B cbi(CbComponentRefService<S> add, CbComponentRefService<S> change, CbComponentRefService<S> remove) {
+    public B callbacks(InstanceCbServiceComponentRef<S> add, InstanceCbServiceComponentRef<S> change, InstanceCbServiceComponentRef<S> remove) {
         if (add != null)
-            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, ref, srv));
+            setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, comp, ref));
         if (change != null)
-            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, ref, srv));
+            setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, comp, ref));
         if (remove != null)
-            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, ref, srv));
+            setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, comp, ref));
         return (B) this;
     }
 
-    public <T> B sw(CbTypeServiceService<T, S> swap) {
+    public <T> B swap(CbServiceService<T, S> swap) {
         Class<T> type = Helpers.getLambdaArgType(swap, 0);
         return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
             swap.accept((T) inst, oserv, nserv));                              
     }
 
-    public <T> B sw(CbTypeComponentServiceService<T, S> swap) {
+    @Override
+    public <T> B swap(CbServiceServiceComponent<T, S> swap) {
         Class<T> type = Helpers.getLambdaArgType(swap, 0);
         return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
-            swap.accept((T) inst, component, oserv, nserv));                              
+            swap.accept((T) inst, oserv, nserv, component));                              
     }
 
-    public <T> B sw(CbTypeRefServiceRefService<T, S> swap) {
+    public <T> B swap(CbRefServiceRefService<T, S> swap) {
         Class<T> type = Helpers.getLambdaArgType(swap, 0);
         return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
             swap.accept((T) inst, oref, oserv, nref, nserv));                              
     }
     
-    public <T> B sw(CbTypeComponentRefServiceRefService<T, S> swap) {
+    public <T> B swap(CbRefServiceRefServiceComponent<T, S> swap) {
         Class<T> type = Helpers.getLambdaArgType(swap, 0);
         return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
-            swap.accept((T) inst, component, oref, oserv, nref, nserv));                              
+            swap.accept((T) inst, oref, oserv, nref, nserv, component));                              
     }
     
-    public B swi(CbServiceService<S> swap) {
+    public B swap(InstanceCbServiceService<S> swap) {
         return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oserv, nserv));
     }
 
-    public B swi(CbComponentServiceService<S> swap) {
-        return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(component, oserv, nserv));
+    public B swap(InstanceCbServiceServiceComponent<S> swap) {
+        return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oserv, nserv, component));
     }
 
-    public B swi(CbRefServiceRefService<S> swap) {
+    public B swap(InstanceCbRefServiceRefService<S> swap) {
         return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oref, oserv, nref, nserv));
     }
     
-    public B swi(CbComponentRefServiceRefService<S> swap) {
-        return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(component, oref, oserv, nref, nserv));
+    public B swap(InstanceCbRefServiceRefServiceComponent<S> swap) {
+        return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oref, oserv, nref, nserv, component));
     }
     
     protected <I> B setComponentCallbackRef(Cb cbType, Class<I> type, MethodRef<I, S> ref) {

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java?rev=1731147&r1=1731146&r2=1731147&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java Thu Feb 18 21:07:16 2016
@@ -27,6 +27,7 @@ public class ServiceDependencyBuilderImp
         super(service);
         m_serviceIface = service;
         m_component = component;
+        m_required = Helpers.isDependencyRequiredByDefault(component);
     }
 
     public ServiceDependencyBuilder<S> filter(String filter) {



Mime
View raw message