felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r981772 - in /felix/trunk/scr: ./ src/main/java/org/apache/felix/scr/ src/main/java/org/apache/felix/scr/impl/ src/main/java/org/apache/felix/scr/impl/config/ src/main/java/org/apache/felix/scr/impl/manager/ src/test/java/org/apache/felix/s...
Date Tue, 03 Aug 2010 08:21:13 GMT
Author: fmeschbe
Date: Tue Aug  3 08:21:13 2010
New Revision: 981772

URL: http://svn.apache.org/viewvc?rev=981772&view=rev
Log:
FEKLIX-2288 Fix handling of the component ID: The ID is now only generated and assigned to
a component while the component is enabled. To still access components without an assigned
ID, ScrService gets a new method getComponent(String name) to access components by their name.

Modified:
    felix/trunk/scr/pom.xml
    felix/trunk/scr/src/main/java/org/apache/felix/scr/Component.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrService.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolder.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/UnconfiguredComponentHolder.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/pom.xml?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/pom.xml (original)
+++ felix/trunk/scr/pom.xml Tue Aug  3 08:21:13 2010
@@ -158,7 +158,7 @@
                             org.apache.felix.scr.impl.Activator
                         </Bundle-Activator>
                         <Export-Package>
-                            org.apache.felix.scr;version=1.4,
+                            org.apache.felix.scr;version=1.5,
                             org.osgi.service.component
                         </Export-Package>
                         <Private-Package>

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/Component.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/Component.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/Component.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/Component.java Tue Aug  3 08:21:13
2010
@@ -84,9 +84,11 @@ public interface Component
     static final int STATE_REGISTERED = 32;
 
     /**
-     * The Component is a Component Factory ready to manage Component instances
-     * from configuration data received from the Configuration Admin Service
-     * (value is 64).
+     * The Component is a Component Factory ready to create Component instances
+     * with the <code>ComponentFactory.newInstance(Dictionary)</code> method
+     * or (if enabled with the <code>ds.factory.enabled</code> configuration)
to
+     * manage Component instances from configuration data received from the
+     * Configuration Admin Service (value is 64).
      */
     static final int STATE_FACTORY = 64;
 
@@ -133,7 +135,9 @@ public interface Component
 
     /**
      * Returns the component ID of this component. This ID is managed by the
-     * SCR.
+     * SCR. If the component is not currently enabled the ID might not be
+     * assigned to the component (yet) and this method will return -1 in this
+     * case.
      */
     long getId();
 

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrService.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrService.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrService.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrService.java Tue Aug  3 08:21:13
2010
@@ -55,6 +55,24 @@ public interface ScrService
 
 
     /**
+     * Returns the components whose <code>component.name</code> matches the
+     * given <code>componentName</code> or <code>null</code> if no
component
+     * with the given name is currently managed.
+     * <p>
+     * If the component name refers to a component factory component or a
+     * component configured with multiple factory configurations this method
+     * returns multiple component instances.
+     *
+     * @param componentName The name of the component to return
+     *
+     * @return The indicated components or <code>null</code> if no such
+     *      component exists.
+     * @since 1.5 (Apache Felix Declarative Services 1.4.2)
+     */
+    Component[] getComponents( String componentName );
+
+
+    /**
      * Reuturns an array of all components managed by this SCR instance on
      * behalf of the given bundle. The components are returned in ascending
      * order of their component.id. If there are no components managed by the

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java Tue Aug
 3 08:21:13 2010
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.felix.scr.Component;
@@ -119,47 +118,58 @@ public class ComponentRegistry implement
 
     public Component[] getComponents()
     {
-        synchronized ( m_componentsById )
+        Object[] holders = getComponentHolders();
+        ArrayList list = new ArrayList();
+        for ( int i = 0; i < holders.length; i++ )
         {
-            if ( m_componentsById.isEmpty() )
+            if ( holders[i] instanceof ComponentHolder )
             {
-                return null;
+                Component[] components = ( ( ComponentHolder ) holders[i] ).getComponents();
+                for ( int j = 0; j < components.length; j++ )
+                {
+                    list.add( components[j] );
+                }
             }
-
-            return ( org.apache.felix.scr.Component[] ) m_componentsById.values().toArray(
-                new Component[m_componentsById.size()] );
         }
-    }
-
 
-    public Component[] getComponents( Bundle bundle )
-    {
-        Component[] all = getComponents();
-        if ( all == null || all.length == 0 )
+        // nothing to return
+        if ( list.isEmpty() )
         {
             return null;
         }
 
-        // compare the bundle by its id
-        long bundleId = bundle.getBundleId();
+        return ( Component[] ) list.toArray( new Component[list.size()] );
+    }
+
 
-        // scan the components for the the desired components
-        List perBundle = new ArrayList();
-        for ( int i = 0; i < all.length; i++ )
+    public Component[] getComponents( Bundle bundle )
+    {
+        Object[] holders = getComponentHolders();
+        ArrayList list = new ArrayList();
+        for ( int i = 0; i < holders.length; i++ )
         {
-            if ( all[i].getBundle().getBundleId() == bundleId )
+            if ( holders[i] instanceof ComponentHolder )
             {
-                perBundle.add( all[i] );
+                ComponentHolder holder = ( ComponentHolder ) holders[i];
+                BundleComponentActivator activator = holder.getActivator();
+                if ( activator != null && activator.getBundleContext().getBundle()
== bundle )
+                {
+                    Component[] components = holder.getComponents();
+                    for ( int j = 0; j < components.length; j++ )
+                    {
+                        list.add( components[j] );
+                    }
+                }
             }
         }
 
         // nothing to return
-        if ( perBundle.isEmpty() )
+        if ( list.isEmpty() )
         {
             return null;
         }
 
-        return ( org.apache.felix.scr.Component[] ) perBundle.toArray( new Component[perBundle.size()]
);
+        return ( Component[] ) list.toArray( new Component[list.size()] );
     }
 
 
@@ -172,6 +182,18 @@ public class ComponentRegistry implement
     }
 
 
+    public Component[] getComponents( String componentName )
+    {
+        final ComponentHolder holder = getComponentHolder( componentName );
+        if ( holder != null )
+        {
+            return holder.getComponents();
+        }
+
+        return null;
+    }
+
+
     //---------- ComponentManager registration by component Id
 
     /**

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java Tue
Aug  3 08:21:13 2010
@@ -21,6 +21,7 @@ package org.apache.felix.scr.impl.config
 
 import java.util.Dictionary;
 
+import org.apache.felix.scr.Component;
 import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.manager.ImmediateComponentManager;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -69,6 +70,10 @@ public interface ComponentHolder
      */
     void configurationUpdated( String pid, Dictionary props );
 
+    /**
+     * Returns all <code>Component</code> instances held by this holder.
+     */
+    Component[] getComponents();
 
     /**
      * Enables all components of this holder.

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolder.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolder.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolder.java
Tue Aug  3 08:21:13 2010
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.felix.scr.Component;
 import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.manager.ImmediateComponentManager;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -239,6 +240,14 @@ public class ConfiguredComponentHolder e
     }
 
 
+    public Component[] getComponents()
+    {
+        Component[] components = getComponentManagers( false );
+        return ( components != null ) ? components : new Component[]
+            { m_singleComponent };
+    }
+
+
     public void enableComponents()
     {
         final ImmediateComponentManager[] cms = getComponentManagers( false );

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/UnconfiguredComponentHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/UnconfiguredComponentHolder.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/UnconfiguredComponentHolder.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/UnconfiguredComponentHolder.java
Tue Aug  3 08:21:13 2010
@@ -21,6 +21,7 @@ package org.apache.felix.scr.impl.config
 
 import java.util.Dictionary;
 
+import org.apache.felix.scr.Component;
 import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.manager.ImmediateComponentManager;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -55,6 +56,13 @@ public class UnconfiguredComponentHolder
     }
 
 
+    public Component[] getComponents()
+    {
+        return new Component[]
+            { m_component };
+    }
+
+
     public void enableComponents()
     {
         m_component.enable();

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Tue Aug  3 08:21:13 2010
@@ -80,9 +80,7 @@ public abstract class AbstractComponentM
     {
         m_activator = activator;
         m_componentMetadata = metadata;
-
-        // for some testing, the activator may be null
-        m_componentId = ( activator != null ) ? activator.registerComponentId( this ) : -1;
+        m_componentId = -1;
 
         m_state = Disabled.getInstance();
         m_dependencyManagers = loadDependencyManagers( metadata );
@@ -116,6 +114,32 @@ public abstract class AbstractComponentM
     }
 
 
+    //---------- Component ID management
+
+    void registerComponentId()
+    {
+        final BundleComponentActivator activator = getActivator();
+        if ( activator != null )
+        {
+            this.m_componentId = activator.registerComponentId( this );
+        }
+    }
+
+
+    void unregisterComponentId()
+    {
+        if ( this.m_componentId >= 0 )
+        {
+            final BundleComponentActivator activator = getActivator();
+            if ( activator != null )
+            {
+                activator.unregisterComponentId( this );
+            }
+            this.m_componentId = -1;
+        }
+    }
+
+
     //---------- Asynchronous frontend to state change methods ----------------
     /**
      * Enables this component and - if satisfied - also activates it. If
@@ -869,7 +893,7 @@ public abstract class AbstractComponentM
         void enable( AbstractComponentManager acm )
         {
             acm.changeState( Enabling.getInstance() );
-
+            acm.registerComponentId();
             try
             {
                 acm.enableDependencyManagers();
@@ -881,6 +905,7 @@ public abstract class AbstractComponentM
                 // one of the reference target filters is invalid, fail
                 acm.log( LogService.LOG_ERROR, "Failed enabling Component", ise );
                 acm.disableDependencyManagers();
+                acm.unregisterComponentId();
                 acm.changeState( Disabled.getInstance() );
             }
         }
@@ -994,6 +1019,9 @@ public abstract class AbstractComponentM
             // dispose and recreate dependency managers
             acm.disableDependencyManagers();
 
+            // reset the component id now (a disabled component has none)
+            acm.unregisterComponentId();
+
             // we are now disabled, ready for re-enablement or complete destroyal
             acm.changeState( Disabled.getInstance() );
 

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
Tue Aug  3 08:21:13 2010
@@ -24,6 +24,7 @@ import java.util.Hashtable;
 import java.util.IdentityHashMap;
 import java.util.Map;
 
+import org.apache.felix.scr.Component;
 import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.config.ComponentHolder;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -320,6 +321,26 @@ public class ComponentFactoryImpl extend
     }
 
 
+    public Component[] getComponents()
+    {
+        ImmediateComponentManager[] instances = getComponentManagers( m_componentInstances
);
+        ImmediateComponentManager[] services = getComponentManagers( m_configuredServices
);
+        int size = instances.length + services.length;
+
+        if ( size > 0 )
+        {
+            Component[] result = new Component[size + 1];
+            result[0] = this;
+            System.arraycopy( instances, 0, result, 1, instances.length );
+            System.arraycopy( services, 0, result, instances.length + 1, services.length
);
+            return result;
+        }
+
+        return new Component[]
+            { this };
+    }
+
+
     /**
      * A component factory component holder enables the held components by
      * enabling itself.

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Tue Aug  3 08:21:13 2010
@@ -300,6 +300,20 @@ public class ImmediateComponentManager e
     }
 
 
+    void registerComponentId()
+    {
+        super.registerComponentId();
+        this.m_properties = null;
+    }
+
+
+    void unregisterComponentId()
+    {
+        super.unregisterComponentId();
+        this.m_properties = null;
+    }
+
+
     /**
      * Returns the (private copy) of the Component properties to be used
      * for the ComponentContext as well as eventual service registration.

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
Tue Aug  3 08:21:13 2010
@@ -261,14 +261,36 @@ public class ComponentConfigurationTest 
         final Component[] twoConfigs = findComponentsByName( factoryPid );
         TestCase.assertNotNull( twoConfigs );
         TestCase.assertEquals( 2, twoConfigs.length );
-        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
-        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[1].getState() );
+
+        // find the active and inactive configs, fail if none
+        int activeConfig;
+        int inactiveConfig;
+        if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
+        {
+            // [0] is active, [1] expected disabled
+            activeConfig = 0;
+            inactiveConfig = 1;
+        }
+        else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
+        {
+            // [1] is active, [0] expected disabled
+            activeConfig = 1;
+            inactiveConfig = 0;
+        }
+        else
+        {
+            TestCase.fail( "One of two components expected active" );
+            return; // eases the compiler...
+        }
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState()
);
+        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState()
);
         TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId()
) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId()
) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId()
) );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId()
) );
 
         // enable second component
-        twoConfigs[1].enable();
+        twoConfigs[inactiveConfig].enable();
         delay();
 
         // ensure both components active
@@ -288,8 +310,7 @@ public class ComponentConfigurationTest 
         TestCase.assertEquals( 1, oneConfig.length );
         TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
         TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId()
) );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId()
) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId()
) );
 
         // delete second configuration
         deleteConfig( pid1 );
@@ -301,8 +322,6 @@ public class ComponentConfigurationTest 
         TestCase.assertEquals( 1, configsDeleted.length );
         TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState()
);
         TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId()
) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId()
) );
     }
 
     @Test

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
Tue Aug  3 08:21:13 2010
@@ -76,14 +76,36 @@ public class ComponentDisposeTest extend
         final Component[] twoConfigs = findComponentsByName( factoryPid );
         TestCase.assertNotNull( twoConfigs );
         TestCase.assertEquals( 2, twoConfigs.length );
-        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
-        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[1].getState() );
+
+        // find the active and inactive configs, fail if none
+        int activeConfig;
+        int inactiveConfig;
+        if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
+        {
+            // [0] is active, [1] expected disabled
+            activeConfig = 0;
+            inactiveConfig = 1;
+        }
+        else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
+        {
+            // [1] is active, [0] expected disabled
+            activeConfig = 1;
+            inactiveConfig = 0;
+        }
+        else
+        {
+            TestCase.fail( "One of two components expected active" );
+            return; // eases the compiler...
+        }
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState()
);
+        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState()
);
         TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId()
) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId()
) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId()
) );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId()
) );
 
         // enable second component
-        twoConfigs[1].enable();
+        twoConfigs[inactiveConfig].enable();
         delay();
 
         // ensure both components active
@@ -106,8 +128,7 @@ public class ComponentDisposeTest extend
         TestCase.assertEquals( 1, oneConfig.length );
         TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
         TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId()
) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( anInstance.m_id ) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId()
) );
 
         final SimpleComponent instance = SimpleComponent.INSTANCES.values().iterator().next();
 

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=981772&r1=981771&r2=981772&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Tue Aug  3 08:21:13 2010
@@ -29,10 +29,8 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Field;
-import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
-import java.util.List;
 import junit.framework.TestCase;
 
 import org.apache.felix.scr.Component;
@@ -162,16 +160,10 @@ public abstract class ComponentTestBase
 
     protected Component findComponentByName( String name )
     {
-        Component[] components = getComponents();
-        if ( components != null )
+        Component[] components = findComponentsByName( name );
+        if ( components != null && components.length > 0 )
         {
-            for ( Component component : components )
-            {
-                if ( name.equals( component.getName() ) )
-                {
-                    return component;
-                }
-            }
+            return components[0];
         }
 
         return null;
@@ -180,22 +172,10 @@ public abstract class ComponentTestBase
 
     protected Component[] findComponentsByName( String name )
     {
-        List<Component> cList = new ArrayList<Component>();
-        Component[] components = getComponents();
-        if ( components != null )
-        {
-            for ( Component component : components )
-            {
-                if ( name.equals( component.getName() ) )
-                {
-                    cList.add( component );
-                }
-            }
-        }
-
-        if ( !cList.isEmpty() )
+        ScrService scr = ( ScrService ) scrTracker.getService();
+        if ( scr != null )
         {
-            return cList.toArray( new Component[cList.size()] );
+            return scr.getComponents( name );
         }
 
         return null;



Mime
View raw message