summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java34
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java4
2 files changed, 27 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
index 2906897e96..a0af933c71 100644
--- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
+++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
@@ -19,7 +19,12 @@
package org.apache.tuscany.sca.implementation.java.injection;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
@@ -30,21 +35,32 @@ import org.apache.tuscany.sca.core.factory.ObjectFactory;
*
* @version $Rev$ $Date$
*/
-public class ListMultiplicityObjectFactory implements ObjectFactory<List<?>> {
+public class ListMultiplicityObjectFactory implements ObjectFactory<Collection<?>> {
- private ObjectFactory[] factories;
+ private Collection<ObjectFactory<?>> factories;
+ private Class<?> collectionType;
- public ListMultiplicityObjectFactory(List<ObjectFactory<?>> factories) {
+ public ListMultiplicityObjectFactory(List<ObjectFactory<?>> factories, Class<?> collectionType) {
assert factories != null : "Object factories were null";
- this.factories = factories.toArray(new ObjectFactory[factories.size()]);
+ this.factories = factories;
+ this.collectionType = collectionType;
}
- public List<?> getInstance() throws ObjectCreationException {
- List<Object> list = new ArrayList<Object>();
- for (ObjectFactory factory : factories) {
- list.add(factory.getInstance());
+ public Collection<?> getInstance() throws ObjectCreationException {
+ Collection<Object> collection = null;
+ if (SortedSet.class.isAssignableFrom(collectionType)) {
+ collection = new TreeSet<Object>();
+ } else if (Set.class.isAssignableFrom(collectionType)) {
+ collection = new HashSet<Object>();
+ } else if (List.class.isAssignableFrom(collectionType)) {
+ collection = new ArrayList<Object>();
+ } else {
+ collection = new ArrayList<Object>();
}
- return list;
+ for (ObjectFactory<?> factory : factories) {
+ collection.add(factory.getInstance());
+ }
+ return collection;
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java
index 1f1f1eefdc..e89b618cfe 100644
--- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java
+++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java
@@ -151,14 +151,14 @@ public class JavaInstanceFactoryProvider<T> implements InstanceFactoryProvider<T
if (field.getType().isArray()) {
return new FieldInjector<T>(field, new ArrayMultiplicityObjectFactory(interfaceType, factories));
} else {
- return new FieldInjector<T>(field, new ListMultiplicityObjectFactory(factories));
+ return new FieldInjector<T>(field, new ListMultiplicityObjectFactory(factories, field.getType()));
}
} else if (element.getAnchor() instanceof Method) {
Method method = (Method)element.getAnchor();
if (method.getParameterTypes()[0].isArray()) {
return new MethodInjector<T>(method, new ArrayMultiplicityObjectFactory(interfaceType, factories));
} else {
- return new MethodInjector<T>(method, new ListMultiplicityObjectFactory(factories));
+ return new MethodInjector<T>(method, new ListMultiplicityObjectFactory(factories, method.getParameterTypes()[0]));
}
} else {
throw new InvalidAccessorException("Member must be a field or method: " + element.getName());