FELIX-3700: Improved configuration update: if the component factory is active, and 
if the config target filters don't satisfy anymore some required references, then deactivate
the component factory. 


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1399322 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
index bb26ce7..d4bcf3d 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
@@ -374,27 +374,32 @@
                 // We are now configured from config admin.
                 m_isConfigured = true;
                 
-                // if configuration is required and if we not active (that is: either disabled or unsatisfied),
-                // Then we then must activate our dependency target filters.
-                // Please check  AbstractComponentManager.enableDependencyManagers() method, which doesn't set
-                // target filters in case the configuration is required.
-                
                 log( LogService.LOG_INFO, "Current ComponentFactory state={0}", new Object[]
                     { getState() }, null );
 
-                if ( ( getState() == STATE_DISABLED || getState() == STATE_UNSATISFIED ) && configuration != null
-                    && getComponentMetadata().isConfigurationRequired() )
+                // Update our target filters.
+                log( LogService.LOG_DEBUG, "Updating target filters", null );                    
+                super.updateTargets( m_configuration ); 
+                                    
+                // If we are active, but if some config target filters don't match anymore 
+                // any required references, then deactivate.                
+                if ( getState() == STATE_FACTORY )
                 {
-                    // Enable dependency managers, and also update any target filters from config admin. 
-                    log( LogService.LOG_DEBUG, "Updating target filters", null );                    
-                    super.updateTargets( m_configuration ); 
+                    if ( !verifyDependencyManagers( getProperties() ) )
+                    {
+                        if ( ( getState() & STATE_DISPOSED ) == 0 )
+                        {
+                            log( LogService.LOG_DEBUG,
+                                "Component Factory target filters not satisfied anymore: deactivating", null );
+                            deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE );
+                        }
+                        return;
+                    }
                 }
-                
-                // unsatisfied component and required configuration may change targets
-                // to satisfy references. Or the configuration was just required.
-
-                if ( getState() == STATE_UNSATISFIED && configuration != null
-                    && getComponentMetadata().isConfigurationRequired() )
+                    
+                // Unsatisfied component and required configuration may change targets
+                // to satisfy references.
+                if ( getState() == STATE_UNSATISFIED && getComponentMetadata().isConfigurationRequired() )
                 {                   
                     // try to activate our component factory, if all dependnecies are satisfied
                     log( LogService.LOG_DEBUG, "Attempting to activate unsatisfied component", null );