FELIX-5104: Call a conf dependency callback Instance with an instantiated component


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1714673 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd b/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd
index 488b022..0478ad2 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd
+++ b/dependencymanager/org.apache.felix.dependencymanager/bnd.bnd
@@ -14,11 +14,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
--buildpath:  \
+-buildpath: \
 	osgi.core;version=4.2,\
 	osgi.cmpn;version=4.2,\
 	org.mockito.mockito-all;version=1.9,\
-	${junit}
+	${junit},\
+	biz.aQute.bndlib;version=3.0
 Private-Package: \
 	org.apache.felix.dm.impl,\
 	org.apache.felix.dm.impl.index,\
@@ -35,7 +36,7 @@
 	META-INF/=${workspace}/release/resources/changelog.txt
 Import-Package: !org.junit,!org.mockito.*,*
 Bundle-Activator: org.apache.felix.dm.impl.Activator
-Bundle-Version: 4.1.2
+Bundle-Version: 4.2.0
 Bundle-Name: Apache Felix Dependency Manager
 Bundle-Description: Provides dynamic service and component dependency management
 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
diff --git a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java
index c9a3a43..4c58059 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java
+++ b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.dm;
 
+import aQute.bnd.annotation.ProviderType;
+
 /**
  * Configuration dependency that can track the availability of a (valid) configuration. To use
  * it, specify a PID for the configuration. The dependency is always required, because if it is
@@ -50,12 +52,15 @@
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
+@ProviderType
 public interface ConfigurationDependency extends Dependency, ComponentDependencyDeclaration {
     /**
      * Sets the name of the callback method that should be invoked when a configuration
      * is available. The contract for this method is identical to that of
      * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>.
      * By default, if this method is not called, the callback name is "updated".
+     * The callback is always invoked with an already instantiated component (the component implementation class(es) are
+     * always instantiated before the updated callback is invoked).
      * 
      * @param callback the name of the callback method
      */
@@ -65,6 +70,8 @@
      * Sets the name of the callback method that should be invoked when a configuration
      * is available. The contract for this method is identical to that of
      * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>.
+     * The callback is called with a component that is not yet instantiated. This allows factory objects to get
+     * injected with a configuration before its <code>create</code> method is called.
      * 
      * @param instance the instance to call the callbacks on
      * @param callback the name of the callback method
@@ -72,6 +79,19 @@
     ConfigurationDependency setCallback(Object instance, String callback);
 
     /**
+     * Sets the name of the callback method that should be invoked when a configuration
+     * is available. The contract for this method is identical to that of
+     * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>.
+     * The component instance is instantiated before the callback is invoked only the the <code>needsInstance</code> parameter is set to true.
+     * 
+     * @param instance the instance to call the callback on
+     * @param callback the name of the callback method
+     * @param needsInstance true if the component implementation class(es) must be created before the
+     *        callback instance is invoked, else false.
+     */
+    ConfigurationDependency setCallback(Object instance, String callback, boolean needsInstance);
+    
+    /**
      * Sets the <code>service.pid</code> of the configuration you are depending
      * on.
      */
diff --git a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
index 31e6850..e367247 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
@@ -51,6 +51,7 @@
 	private final AtomicBoolean m_updateInvokedCache = new AtomicBoolean();
 	private final Logger m_logger;
 	private final BundleContext m_context;
+	private boolean m_needsInstance = true;
 
     public ConfigurationDependencyImpl() {
         this(null, null);
@@ -69,6 +70,7 @@
 	    m_pid = prototype.m_pid;
 	    m_logger = prototype.m_logger;
         m_metaType = prototype.m_metaType != null ? new MetaTypeProviderImpl(prototype.m_metaType, this, null) : null;
+        m_needsInstance = prototype.needsInstance();
 	}
 	
     @Override
@@ -87,13 +89,18 @@
     }
     
     public ConfigurationDependencyImpl setCallback(Object instance, String callback) {
+    	return setCallback(instance, callback, false);
+    }
+
+    public ConfigurationDependencyImpl setCallback(Object instance, String callback, boolean needsInstance) {
         super.setCallbacks(instance, callback, null);
+        m_needsInstance = needsInstance;
         return this;
     }
 
     @Override
     public boolean needsInstance() {
-        return m_callbackInstance == null;
+        return m_needsInstance;
     }
 
     @Override
diff --git a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo
index 6ae0565..5d87717 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo
+++ b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo
@@ -1 +1 @@
-version 4.1.0
\ No newline at end of file
+version 4.2.0
\ No newline at end of file