geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r773454 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
Date Mon, 11 May 2009 03:01:39 GMT
Author: gawor
Date: Mon May 11 03:01:39 2009
New Revision: 773454

URL: http://svn.apache.org/viewvc?rev=773454&view=rev
Log:
handle Collection<ServiceReference> injection

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java?rev=773454&r1=773453&r2=773454&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
Mon May 11 03:01:39 2009
@@ -43,6 +43,7 @@
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.ExecutionContext;
 import org.apache.xbean.recipe.Recipe;
+import org.apache.xbean.recipe.RecipeHelper;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.blueprint.context.BlueprintContext;
@@ -84,7 +85,7 @@
                 comparator = new NaturalOrderComparator();
             }
             boolean orderReferences = metadata.getOrderingBasis() == RefCollectionMetadata.ORDERING_BASIS_SERVICE_REFERENCE;
-            boolean memberReferences = metadata.getMemberType() == RefCollectionMetadata.MEMBER_TYPE_SERVICE_REFERENCE;
+            boolean memberReferences = isReferenceCollection(expectedType) || metadata.getMemberType()
== RefCollectionMetadata.MEMBER_TYPE_SERVICE_REFERENCE;
             if (metadata.getCollectionType() == List.class) {
                 if (comparator != null) {
                     collection = new ManagedSortedList(memberReferences, orderReferences,
comparator);
@@ -119,6 +120,20 @@
         }
     }
     
+    private boolean isReferenceCollection(Type expectedType) {
+        Class componentType = getComponentType(expectedType);
+        return ServiceReference.class.equals(componentType);
+    }
+    
+    private Class getComponentType(Type expectedType) {
+        Type[] typeParameters = RecipeHelper.getTypeParameters(Collection.class, expectedType);
+        Class componentType = Object.class;
+        if (typeParameters != null && typeParameters.length == 1 && typeParameters[0]
instanceof Class) {
+            componentType = (Class) typeParameters[0];
+        }
+        return componentType;
+    }
+    
     public void stop() {
         super.stop();
         List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(collection.getDispatchers());



Mime
View raw message