FELIX-2824 Besides setting the configuration support object up
when the Configuration Admin service is registered after starting
Declarative Services the support should also be setup if the
Configuration Admin service is already available before Declarative
Services is started

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1067309 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
index 36bd41f..6ab57b6 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
@@ -113,13 +113,20 @@
         // keep me informed on ConfigurationAdmin state changes
         try
         {
-            context.addServiceListener( this, "(objectclass=" + CONFIGURATION_ADMIN + ")" );
+            context.addServiceListener(this, "(objectclass=" + CONFIGURATION_ADMIN + ")");
         }
-        catch ( InvalidSyntaxException ise )
+        catch (InvalidSyntaxException ise)
         {
             // not expected (filter is tested valid)
         }
 
+        // If the Configuration Admin Service is already registered, setup
+        // configuration support immediately
+        if (context.getServiceReference(CONFIGURATION_ADMIN) != null)
+        {
+            getOrCreateConfigurationSupport();
+        }
+
         // register as ScrService
         Dictionary props = new Hashtable();
         props.put( Constants.SERVICE_DESCRIPTION, "Declarative Services Management Agent" );
@@ -448,7 +455,7 @@
     {
         if (event.getType() == ServiceEvent.REGISTERED)
         {
-            this.configurationSupport = new ConfigurationSupport(this.m_bundleContext, this);
+            ConfigurationSupport configurationSupport = getOrCreateConfigurationSupport();
 
             final ServiceReference caRef = event.getServiceReference();
             final Object service = m_bundleContext.getService(caRef);
@@ -456,7 +463,7 @@
             {
                 try
                 {
-                    this.configurationSupport.configureComponentHolders(caRef, service);
+                    configurationSupport.configureComponentHolders(caRef, service);
                 }
                 finally
                 {
@@ -466,11 +473,7 @@
         }
         else if (event.getType() == ServiceEvent.UNREGISTERING)
         {
-            if (configurationSupport != null)
-            {
-                this.configurationSupport.dispose();
-                this.configurationSupport = null;
-            }
+            disposeConfigurationSupport();
         }
     }
 
@@ -517,4 +520,22 @@
         // fall back: bundle is not considered active
         return false;
     }
+
+    private ConfigurationSupport getOrCreateConfigurationSupport()
+    {
+        if (configurationSupport == null)
+        {
+            configurationSupport = new ConfigurationSupport(m_bundleContext, this);
+        }
+        return configurationSupport;
+    }
+
+    private void disposeConfigurationSupport()
+    {
+        if (configurationSupport != null)
+        {
+            this.configurationSupport.dispose();
+            this.configurationSupport = null;
+        }
+    }
 }