Fix the issue Felix-686.
The dependency handler can now inject Collections and Sets containing service objects. 


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@686744 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
index 47e1364..ce8a205 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
@@ -25,7 +25,9 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.Vector;
 
 import org.apache.felix.ipojo.FieldInterceptor;
@@ -467,7 +469,7 @@
                     }
                     usage.m_object = objs;
                 }
-            } else if (m_type == 1) {
+            } else if (m_type == DependencyHandler.LIST) {
                 if (refs == null) {
                     usage.m_object = new ArrayList(0); // Create an empty list.
                 } else {
@@ -479,7 +481,7 @@
                     }
                     usage.m_object = objs;
                 }
-            } else if (m_type == 2) {
+            } else if (m_type == DependencyHandler.VECTOR) {
                 if (refs == null) {
                     usage.m_object = new Vector(0); // Create an empty vector.
                 } else {
@@ -491,6 +493,18 @@
                     }
                     usage.m_object = objs;
                 }
+            } else if (m_type == DependencyHandler.SET) {
+                if (refs == null) {
+                    usage.m_object = new HashSet(0); // Create an empty vector.
+                } else {
+                   // Use a vector to store service objects
+                    Set objs = new HashSet(refs.length); 
+                    for (int i = 0; refs != null && i < refs.length; i++) {
+                        ServiceReference ref = refs[i];
+                        objs.add(getService(ref));
+                    }
+                    usage.m_object = objs;
+                }
             }
         }
     }
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index dcc9fb9..93b3a6c 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -18,9 +18,11 @@
  */
 package org.apache.felix.ipojo.handlers.dependency;
 
+import java.util.Collection;
 import java.util.Comparator;
 import java.util.Dictionary;
 import java.util.List;
+import java.util.Set;
 import java.util.Vector;
 
 import org.apache.felix.ipojo.ConfigurationException;
@@ -56,6 +58,12 @@
      * The dependency will be injected as a list.
      */
     protected static final int LIST = 1;
+    
+    /**
+     * Dependency Field Type : Set.
+     * The dependency will be injected as a set.
+     */
+    protected static final int SET = 3;
 
     /**
      * List of dependencies of the component.
@@ -212,12 +220,15 @@
                 // Set the dependency to multiple
                 dep.setAggregate(true);
                 type = type.substring(0, type.length() - 2);
-            } else if (type.equals(List.class.getName())) {
+            } else if (type.equals(List.class.getName()) || type.equals(Collection.class.getName())) {
                 dep.setType(LIST);
                 type = null;
             } else if (type.equals(Vector.class.getName())) {
                 dep.setType(VECTOR);
                 type = null;
+            } else if (type.equals(Set.class.getName())) {
+                dep.setType(SET);
+                type = null;
             } else {
                 if (dep.isAggregate()) {
                     throw new ConfigurationException("A required service is not correct : the field "
diff --git a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckService.java b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckService.java
new file mode 100644
index 0000000..fa429f2
--- /dev/null
+++ b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckService.java
@@ -0,0 +1,164 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Collection;

+import java.util.Iterator;

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService;

+import org.osgi.framework.ServiceReference;

+

+public class CollectionCheckService implements CheckService {

+

+    Collection fs;

+

+    int simpleB = 0;

+

+    int objectB = 0;

+

+    int refB = 0;

+

+    int bothB = 0;

+

+    int simpleU = 0;

+

+    int objectU = 0;

+

+    int refU = 0;

+

+    int bothU = 0;

+

+    public boolean check() {

+        boolean r = fs.size() != 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r & ((FooService) it.next()).foo();

+        }

+        return r;

+    }

+

+    private boolean getBoolean() {

+        return check();

+    }

+

+    private int getInt() {

+        int r = 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getInt();

+        }

+        return r;

+    }

+

+    private long getLong() {

+        long r = 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getLong();

+        }

+        return r;

+    }

+

+    private double getDouble() {

+        double r = 0.0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getLong();

+        }

+        return r;

+    }

+

+    protected Object doNothing(Object o, String s) {

+        return null;

+    }

+

+    // private Object getObject() {

+    // boolean r = true;

+    // for(int i = 0; i < fs.length; i++) {

+    // r = r && ((Boolean) fs[i].getObject()).booleanValue();

+    // }

+    // return new Boolean(r);

+    // }

+

+    public Properties getProps() {

+        Properties props = new Properties();

+        props.put("result", new Boolean(check()));

+        props.put("voidB", new Integer(simpleB));

+        props.put("objectB", new Integer(objectB));

+        props.put("refB", new Integer(refB));

+        props.put("bothB", new Integer(bothB));

+        props.put("voidU", new Integer(simpleU));

+        props.put("objectU", new Integer(objectU));

+        props.put("refU", new Integer(refU));

+        props.put("bothU", new Integer(bothU));

+        props.put("boolean", new Boolean(getBoolean()));

+        props.put("int", new Integer(getInt()));

+        props.put("long", new Long(getLong()));

+        props.put("double", new Double(getDouble()));

+

+        return props;

+    }

+

+    public void voidBind() {

+        simpleB++;

+    }

+

+    public void voidUnbind() {

+        simpleU++;

+    }

+

+    public void objectBind(FooService o) {

+        if (o != null && o instanceof FooService) {

+            objectB++;

+        }

+    }

+

+    public void objectUnbind(FooService o) {

+        if (o != null && o instanceof FooService) {

+            objectU++;

+        }

+    }

+

+    public void refBind(ServiceReference sr) {

+        if (sr != null) {

+            refB++;

+        }

+    }

+

+    public void refUnbind(ServiceReference sr) {

+        if (sr != null) {

+            refU++;

+        }

+    }

+

+    public void bothBind(FooService o, ServiceReference sr) {

+        if (o != null && o instanceof FooService && sr != null) {

+            bothB++;

+        }

+    }

+

+    public void bothUnbind(FooService o, ServiceReference sr) {

+        if (o != null && o instanceof FooService && sr != null) {

+            bothU++;

+        }

+    }

+

+}

diff --git a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SetCheckService.java b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SetCheckService.java
new file mode 100644
index 0000000..8fbbc11
--- /dev/null
+++ b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/component/SetCheckService.java
@@ -0,0 +1,164 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Iterator;

+import java.util.Properties;

+import java.util.Set;

+

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService;

+import org.osgi.framework.ServiceReference;

+

+public class SetCheckService implements CheckService {

+

+    Set fs;

+

+    int simpleB = 0;

+

+    int objectB = 0;

+

+    int refB = 0;

+

+    int bothB = 0;

+

+    int simpleU = 0;

+

+    int objectU = 0;

+

+    int refU = 0;

+

+    int bothU = 0;

+

+    public boolean check() {

+        boolean r = fs.size() != 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r & ((FooService) it.next()).foo();

+        }

+        return r;

+    }

+

+    private boolean getBoolean() {

+        return check();

+    }

+

+    private int getInt() {

+        int r = 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getInt();

+        }

+        return r;

+    }

+

+    private long getLong() {

+        long r = 0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getLong();

+        }

+        return r;

+    }

+

+    private double getDouble() {

+        double r = 0.0;

+        Iterator it = fs.iterator();

+        while(it.hasNext()) {

+            r = r + ((FooService) it.next()).getLong();

+        }

+        return r;

+    }

+

+    protected Object doNothing(Object o, String s) {

+        return null;

+    }

+

+    // private Object getObject() {

+    // boolean r = true;

+    // for(int i = 0; i < fs.length; i++) {

+    // r = r && ((Boolean) fs[i].getObject()).booleanValue();

+    // }

+    // return new Boolean(r);

+    // }

+

+    public Properties getProps() {

+        Properties props = new Properties();

+        props.put("result", new Boolean(check()));

+        props.put("voidB", new Integer(simpleB));

+        props.put("objectB", new Integer(objectB));

+        props.put("refB", new Integer(refB));

+        props.put("bothB", new Integer(bothB));

+        props.put("voidU", new Integer(simpleU));

+        props.put("objectU", new Integer(objectU));

+        props.put("refU", new Integer(refU));

+        props.put("bothU", new Integer(bothU));

+        props.put("boolean", new Boolean(getBoolean()));

+        props.put("int", new Integer(getInt()));

+        props.put("long", new Long(getLong()));

+        props.put("double", new Double(getDouble()));

+

+        return props;

+    }

+

+    public void voidBind() {

+        simpleB++;

+    }

+

+    public void voidUnbind() {

+        simpleU++;

+    }

+

+    public void objectBind(FooService o) {

+        if (o != null && o instanceof FooService) {

+            objectB++;

+        }

+    }

+

+    public void objectUnbind(FooService o) {

+        if (o != null && o instanceof FooService) {

+            objectU++;

+        }

+    }

+

+    public void refBind(ServiceReference sr) {

+        if (sr != null) {

+            refB++;

+        }

+    }

+

+    public void refUnbind(ServiceReference sr) {

+        if (sr != null) {

+            refU++;

+        }

+    }

+

+    public void bothBind(FooService o, ServiceReference sr) {

+        if (o != null && o instanceof FooService && sr != null) {

+            bothB++;

+        }

+    }

+

+    public void bothUnbind(FooService o, ServiceReference sr) {

+        if (o != null && o instanceof FooService && sr != null) {

+            bothU++;

+        }

+    }

+

+}

diff --git a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/CollectionMultipleDependencies.java b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/CollectionMultipleDependencies.java
new file mode 100644
index 0000000..1271576
--- /dev/null
+++ b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/CollectionMultipleDependencies.java
@@ -0,0 +1,248 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.service.dependency;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class CollectionMultipleDependencies extends OSGiTestCase {

+

+	ComponentInstance instance1, instance2;

+	ComponentInstance fooProvider1, fooProvider2;

+	

+	public void setUp() {

+		try {

+			Properties prov = new Properties();

+			prov.put("name", "FooProvider1");

+			fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);

+			fooProvider1.stop();

+		

+			Properties prov2 = new Properties();

+			prov2.put("name", "FooProvider2");

+			fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);

+			fooProvider2.stop();

+		

+			Properties i1 = new Properties();

+			i1.put("name", "Simple");

+			instance1 = Utils.getFactoryByName(context, "SimpleCollectionCheckServiceProvider").createComponentInstance(i1);

+			

+			Properties i2 = new Properties();

+            i2.put("name", "Optional");

+            instance2 = Utils.getFactoryByName(context, "OptionalCollectionCheckServiceProvider").createComponentInstance(i2);

+		} catch(Exception e) { fail(e.getMessage()); }

+		

+	}

+	

+	public void tearDown() {

+		instance1.dispose();

+		instance2.dispose();

+		fooProvider1.dispose();

+		fooProvider2.dispose();

+		instance1 = null;

+		instance2 = null;

+		fooProvider1 = null;

+		fooProvider2 = null;

+	}

+	

+	public void testSimple() {

+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());

+		assertNotNull("Check architecture availability", arch_ref);

+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);

+		

+		fooProvider1.start();

+		

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);

+		

+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		CheckService cs = (CheckService) context.getService(cs_ref);

+		Properties props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here

+		assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);

+		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);

+		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);

+		

+		fooProvider2.start();

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);

+		

+		cs = (CheckService) context.getService(cs_ref);

+		props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+		assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);

+		assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);

+		assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);

+		

+		fooProvider1.stop();

+		

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);

+		

+		cs = (CheckService) context.getService(cs_ref);

+		props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+		assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);

+		assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);

+		assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);

+		

+		fooProvider2.stop();

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);

+		

+		id = null;

+		cs = null;

+		context.ungetService(arch_ref);

+		context.ungetService(cs_ref);

+	}

+	

+	public void testOptional() {

+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());

+        assertNotNull("Check architecture availability", arch_ref);

+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+        

+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        CheckService cs = (CheckService) context.getService(cs_ref);

+        Properties props = cs.getProps();

+        //Check properties

+        assertFalse("check CheckService invocation - 0", ((Boolean)props.get("result")).booleanValue()); // False : no provider

+        assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);

+        assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);

+        assertEquals("Check FS invocation (double) - 0", ((Double)props.get("double")).doubleValue(), 0.0);

+        

+        fooProvider1.start();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here

+        assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);

+        assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);

+        assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);

+        

+        fooProvider2.start();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+        assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);

+        assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);

+        assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);

+        

+        fooProvider1.stop();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, it still one provider.

+        assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);

+        assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);

+        assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);

+        

+        fooProvider2.stop();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertFalse("check CheckService invocation - 4", ((Boolean)props.get("result")).booleanValue()); // False, no more provider.

+        assertEquals("check void bind invocation - 4", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 4", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 4", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 4", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 4", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 4", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 4", ((Integer)props.get("int")).intValue(), 0);

+        assertEquals("Check FS invocation (long) - 4", ((Long)props.get("long")).longValue(), 0);

+        assertEquals("Check FS invocation (double) - 4", ((Double)props.get("double")).doubleValue(), 0.0);

+        

+        id = null;

+        cs = null;

+        context.ungetService(arch_ref);

+        context.ungetService(cs_ref);       

+    }

+	

+}

diff --git a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java
index ae38291..668530a 100644
--- a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java
+++ b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java
@@ -49,6 +49,8 @@
         ots.addTestSuite(DependencyArchitectureTest.class);

         ots.addTestSuite(ListMultipleDependencies.class);

         ots.addTestSuite(VectorMultipleDependencies.class);

+        ots.addTestSuite(SetMultipleDependencies.class);

+        ots.addTestSuite(CollectionMultipleDependencies.class);

 		return ots;

 	}

 

diff --git a/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/SetMultipleDependencies.java b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/SetMultipleDependencies.java
new file mode 100644
index 0000000..a32f477
--- /dev/null
+++ b/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/SetMultipleDependencies.java
@@ -0,0 +1,248 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.service.dependency;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class SetMultipleDependencies extends OSGiTestCase {

+

+	ComponentInstance instance1, instance2;

+	ComponentInstance fooProvider1, fooProvider2;

+	

+	public void setUp() {

+		try {

+			Properties prov = new Properties();

+			prov.put("name", "FooProvider1");

+			fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);

+			fooProvider1.stop();

+		

+			Properties prov2 = new Properties();

+			prov2.put("name", "FooProvider2");

+			fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);

+			fooProvider2.stop();

+		

+			Properties i1 = new Properties();

+			i1.put("name", "Simple");

+			instance1 = Utils.getFactoryByName(context, "SimpleSetCheckServiceProvider").createComponentInstance(i1);

+			

+			Properties i2 = new Properties();

+            i2.put("name", "Optional");

+            instance2 = Utils.getFactoryByName(context, "OptionalSetCheckServiceProvider").createComponentInstance(i2);

+		} catch(Exception e) { fail(e.getMessage()); }

+		

+	}

+	

+	public void tearDown() {

+		instance1.dispose();

+		instance2.dispose();

+		fooProvider1.dispose();

+		fooProvider2.dispose();

+		instance1 = null;

+		instance2 = null;

+		fooProvider1 = null;

+		fooProvider2 = null;

+	}

+	

+	public void testSimple() {

+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());

+		assertNotNull("Check architecture availability", arch_ref);

+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);

+		

+		fooProvider1.start();

+		

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);

+		

+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		CheckService cs = (CheckService) context.getService(cs_ref);

+		Properties props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here

+		assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);

+		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);

+		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);

+		

+		fooProvider2.start();

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);

+		

+		cs = (CheckService) context.getService(cs_ref);

+		props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+		assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);

+		assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);

+		assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);

+		

+		fooProvider1.stop();

+		

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);

+		

+		cs = (CheckService) context.getService(cs_ref);

+		props = cs.getProps();

+		//Check properties

+		assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+		assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);

+		assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);

+		assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);

+		assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);

+		assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);

+		assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);

+		assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);

+		assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);

+		assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);

+		

+		fooProvider2.stop();

+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);

+		

+		id = null;

+		cs = null;

+		context.ungetService(arch_ref);

+		context.ungetService(cs_ref);

+	}

+	

+	public void testOptional() {

+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());

+        assertNotNull("Check architecture availability", arch_ref);

+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+        

+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        CheckService cs = (CheckService) context.getService(cs_ref);

+        Properties props = cs.getProps();

+        //Check properties

+        assertFalse("check CheckService invocation - 0", ((Boolean)props.get("result")).booleanValue()); // False : no provider

+        assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);

+        assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);

+        assertEquals("Check FS invocation (double) - 0", ((Double)props.get("double")).doubleValue(), 0.0);

+        

+        fooProvider1.start();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here

+        assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);

+        assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);

+        assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);

+        

+        fooProvider2.start();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here

+        assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);

+        assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);

+        assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);

+        

+        fooProvider1.stop();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, it still one provider.

+        assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);

+        assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);

+        assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);

+        

+        fooProvider2.stop();

+        

+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);

+        

+        cs = (CheckService) context.getService(cs_ref);

+        props = cs.getProps();

+        //Check properties

+        assertFalse("check CheckService invocation - 4", ((Boolean)props.get("result")).booleanValue()); // False, no more provider.

+        assertEquals("check void bind invocation - 4", ((Integer)props.get("voidB")).intValue(), 0);

+        assertEquals("check void unbind callback invocation - 4", ((Integer)props.get("voidU")).intValue(), 0);

+        assertEquals("check object bind callback invocation - 4", ((Integer)props.get("objectB")).intValue(), 0);

+        assertEquals("check object unbind callback invocation - 4", ((Integer)props.get("objectU")).intValue(), 0);

+        assertEquals("check ref bind callback invocation - 4", ((Integer)props.get("refB")).intValue(), 0);

+        assertEquals("check ref unbind callback invocation - 4", ((Integer)props.get("refU")).intValue(), 0);

+        assertEquals("Check FS invocation (int) - 4", ((Integer)props.get("int")).intValue(), 0);

+        assertEquals("Check FS invocation (long) - 4", ((Long)props.get("long")).longValue(), 0);

+        assertEquals("Check FS invocation (double) - 4", ((Double)props.get("double")).doubleValue(), 0.0);

+        

+        id = null;

+        cs = null;

+        context.ungetService(arch_ref);

+        context.ungetService(cs_ref);       

+    }

+	

+}

diff --git a/ipojo/tests/core/service-dependency/src/main/resources/metadata.xml b/ipojo/tests/core/service-dependency/src/main/resources/metadata.xml
index b08fd6e..9433bb2 100644
--- a/ipojo/tests/core/service-dependency/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/service-dependency/src/main/resources/metadata.xml
@@ -457,4 +457,34 @@
 		<provides />

 	</component>

 	

+	<!-- Aggregate dependency as Set -->

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.SetCheckService"

+		name="SimpleSetCheckServiceProvider" architecture="true">

+		<requires field="fs" interface="org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService"/>

+		<provides />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.SetCheckService"

+		name="OptionalSetCheckServiceProvider"

+		architecture="true">

+		<requires interface="org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService" field="fs" optional="true" />

+		<provides />

+	</component>

+	

+	<!-- Aggregate dependency as Collection -->

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CollectionCheckService"

+		name="SimpleCollectionCheckServiceProvider" architecture="true">

+		<requires field="fs" interface="org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService"/>

+		<provides />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CollectionCheckService"

+		name="OptionalCollectionCheckServiceProvider"

+		architecture="true">

+		<requires interface="org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService" field="fs" optional="true" />

+		<provides />

+	</component>

+	

 </ipojo>