Rename component holder registration and unregistration methods to reflect that they act on ComponentHolder instances and not Component instances

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@981223 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java b/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
index 31de35e..eb3344b 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
@@ -244,7 +244,7 @@
                     ComponentHolder holder = m_componentRegistry.createComponentHolder( this, metadata );
 
                     // register the component after validation
-                    m_componentRegistry.registerComponent( metadata.getName(), holder );
+                    m_componentRegistry.registerComponentHolder( metadata.getName(), holder );
                     m_managers.add( holder );
 
                     // enable the component
@@ -260,7 +260,7 @@
                     log( LogService.LOG_ERROR, "Cannot register Component", metadata, t );
 
                     // make sure the name is not reserved any more
-                    m_componentRegistry.unregisterComponent( metadata.getName() );
+                    m_componentRegistry.unregisterComponentHolder( metadata.getName() );
                 }
             }
         }
@@ -325,7 +325,7 @@
             }
             finally
             {
-                m_componentRegistry.unregisterComponent( holder.getComponentMetadata().getName() );
+                m_componentRegistry.unregisterComponentHolder( holder.getComponentMetadata().getName() );
             }
 
         }
@@ -498,7 +498,7 @@
             return ( ComponentHolder[] ) m_managers.toArray( new ComponentHolder[m_managers.size()] );
         }
 
-        if ( m_componentRegistry.getComponent( name ) != null )
+        if ( m_componentRegistry.getComponentHolder( name ) != null )
         {
             // otherwise just find it
             Iterator it = m_managers.iterator();
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 5b4f3c1..731a6f8 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
@@ -61,10 +61,10 @@
      * {@link ComponentHolder}.
      *
      * @see #checkComponentName(String)
-     * @see #registerComponent(String, ComponentHolder)
-     * @see #unregisterComponent(String)
+     * @see #registerComponentHolder(String, ComponentHolder)
+     * @see #unregisterComponentHolder(String)
      */
-    private final Map m_componentsByName;
+    private final Map m_componentHoldersByName;
 
     /**
      * Map of components by component ID. This map indexed by the component
@@ -92,7 +92,7 @@
 
     protected ComponentRegistry( BundleContext context )
     {
-        m_componentsByName = new HashMap();
+        m_componentHoldersByName = new HashMap();
         m_componentsById = new HashMap();
         m_componentCounter = -1;
 
@@ -233,12 +233,12 @@
     {
         // register the name if no registration for that name exists already
         final Object existingRegistration;
-        synchronized ( m_componentsByName )
+        synchronized ( m_componentHoldersByName )
         {
-            existingRegistration = m_componentsByName.get( name );
+            existingRegistration = m_componentHoldersByName.get( name );
             if ( existingRegistration == null )
             {
-                m_componentsByName.put( name, name );
+                m_componentHoldersByName.put( name, name );
             }
         }
 
@@ -280,18 +280,18 @@
      * @throws ComponentException if the name has not been reserved through
      *      {@link #checkComponentName(String)} yet.
      */
-    final void registerComponent( String name, ComponentHolder component )
+    final void registerComponentHolder( String name, ComponentHolder component )
     {
-        synchronized ( m_componentsByName )
+        synchronized ( m_componentHoldersByName )
         {
             // only register the component if there is a m_registration for it !
-            if ( !name.equals( m_componentsByName.get( name ) ) )
+            if ( !name.equals( m_componentHoldersByName.get( name ) ) )
             {
                 // this is not expected if all works ok
                 throw new ComponentException( "The component name '" + name + "' has already been registered." );
             }
 
-            m_componentsByName.put( name, component );
+            m_componentHoldersByName.put( name, component );
         }
     }
 
@@ -300,12 +300,12 @@
      * Returns the component registered under the given name or <code>null</code>
      * if no component is registered yet.
      */
-    public final ComponentHolder getComponent( String name )
+    public final ComponentHolder getComponentHolder( String name )
     {
         Object entry;
-        synchronized ( m_componentsByName )
+        synchronized ( m_componentHoldersByName )
         {
-            entry = m_componentsByName.get( name );
+            entry = m_componentHoldersByName.get( name );
         }
 
         // only return the entry if non-null and not a reservation
@@ -319,16 +319,31 @@
 
 
     /**
+     * Returns an array of all values currently stored in the component holders
+     * map. The entries in the array are either String types for component
+     * name reservations or {@link ComponentHolder} instances for actual
+     * holders of components.
+     */
+    private Object[] getComponentHolders()
+    {
+        synchronized ( m_componentHoldersByName )
+        {
+            return m_componentHoldersByName.values().toArray();
+        }
+    }
+
+
+    /**
      * Removes the component registered under that name. If no component is
      * yet registered but the name is reserved, it is unreserved.
      * <p>
      * After calling this method, the name can be reused by other components.
      */
-    final void unregisterComponent( String name )
+    final void unregisterComponentHolder( String name )
     {
-        synchronized ( m_componentsByName )
+        synchronized ( m_componentHoldersByName )
         {
-            m_componentsByName.remove( name );
+            m_componentHoldersByName.remove( name );
         }
     }
 
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
index 01976af..81e55a8 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
@@ -46,7 +46,6 @@
     // the service m_registration of the ConfigurationListener service
     private ServiceRegistration m_registration;
 
-
     public ConfigurationComponentRegistry( final BundleContext context )
     {
         super( context );
@@ -104,25 +103,32 @@
             final ConfigurationAdmin ca = ( ConfigurationAdmin ) bundleContext.getService( caRef );
             if ( ca != null )
             {
-                final Configuration[] factory = findFactoryConfigurations( ca, name );
-                if ( factory != null )
+                try
                 {
-                    for ( int i = 0; i < factory.length; i++ )
+                    final Configuration[] factory = findFactoryConfigurations( ca, name );
+                    if ( factory != null )
                     {
-                        final String pid = factory[i].getPid();
-                        final Dictionary props = getConfiguration( ca, pid, bundleLocation );
-                        holder.configurationUpdated( pid, props );
+                        for ( int i = 0; i < factory.length; i++ )
+                        {
+                            final String pid = factory[i].getPid();
+                            final Dictionary props = getConfiguration( ca, pid, bundleLocation );
+                            holder.configurationUpdated( pid, props );
+                        }
+                    }
+                    else
+                    {
+                        // check for configuration and configure the holder
+                        final Configuration singleton = findSingletonConfiguration( ca, name );
+                        if ( singleton != null )
+                        {
+                            final Dictionary props = getConfiguration( ca, name, bundleLocation );
+                            holder.configurationUpdated( name, props );
+                        }
                     }
                 }
-                else
+                finally
                 {
-                    // check for configuration and configure the holder
-                    final Configuration singleton = findSingletonConfiguration( ca, name );
-                    if ( singleton != null )
-                    {
-                        final Dictionary props = getConfiguration( ca, name, bundleLocation );
-                        holder.configurationUpdated( name, props );
-                    }
+                    bundleContext.ungetService( caRef );
                 }
             }
         }
@@ -141,11 +147,11 @@
         final ComponentHolder cm;
         if ( factoryPid == null )
         {
-            cm = getComponent( pid );
+            cm = getComponentHolder( pid );
         }
         else
         {
-            cm = getComponent( factoryPid );
+            cm = getComponentHolder( factoryPid );
         }
 
         if ( cm != null && !cm.getComponentMetadata().isConfigurationIgnored() )