incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r1021940 - in /incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container: AbstractServiceReferenceRecipe.java ReferenceListRecipe.java ReferenceRecipe.java
Date Tue, 12 Oct 2010 22:03:02 GMT
Author: jbohn
Date: Tue Oct 12 22:03:01 2010
New Revision: 1021940

URL: http://svn.apache.org/viewvc?rev=1021940&view=rev
Log:
clean up runtime class processing for consistency in ReferenceRecipes

Modified:
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java?rev=1021940&r1=1021939&r2=1021940&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
Tue Oct 12 22:03:01 2010
@@ -39,7 +39,6 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.aries.blueprint.BlueprintConstants;
 import org.apache.aries.blueprint.ExtendedBlueprintContainer;
-import org.apache.aries.blueprint.ExtendedReferenceListMetadata;
 import org.apache.aries.blueprint.ExtendedServiceReferenceMetadata;
 import org.apache.aries.blueprint.di.AbstractRecipe;
 import org.apache.aries.blueprint.di.CollectionRecipe;
@@ -48,7 +47,6 @@ import org.apache.aries.blueprint.proxy.
 import org.apache.aries.blueprint.proxy.UnableToProxyException;
 import org.apache.aries.blueprint.utils.BundleDelegatingClassLoader;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
@@ -122,10 +120,8 @@ public abstract class AbstractServiceRef
         final ExtendedBlueprintContainer blueprintContainer,
         ServiceReferenceMetadata metadata) {
       
-      String typeName = metadata.getInterface();
-      Class typeClass = metadata instanceof ExtendedServiceReferenceMetadata
-                                ? ((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface()
: null;
-      if (typeName == null && typeClass == null) {
+      Class typeClass = getInterfaceClass();
+      if (typeClass == null) {
         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
           public ClassLoader run() {
             return new BundleDelegatingClassLoader(blueprintContainer.getBundleContext().getBundle(),
@@ -134,17 +130,7 @@ public abstract class AbstractServiceRef
         });
       }
       
-      final ClassLoader interfaceClassLoader;
-      if (typeClass != null) {
-          interfaceClassLoader = typeClass.getClassLoader();
-      } else {
-        try {
-          Bundle clientBundle = blueprintContainer.getBundleContext().getBundle();
-          interfaceClassLoader = clientBundle.loadClass(typeName).getClassLoader();
-        } catch (ClassNotFoundException cnfe) {
-          throw new ComponentDefinitionException("Unable to load class " + typeName + " from
recipe " + this, cnfe);
-        }
-      }
+      final ClassLoader interfaceClassLoader = typeClass.getClassLoader();
       
       return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
         public ClassLoader run() {
@@ -248,30 +234,25 @@ public abstract class AbstractServiceRef
     }
 
     protected void createListeners() {
-        try {
             if (listenersRecipe != null) {
                 List<Listener> listeners = (List<Listener>) listenersRecipe.create();
                 for (Listener listener : listeners) {
-                    List<Class> cl = new ArrayList<Class>();
-                    if (metadata instanceof ExtendedServiceReferenceMetadata && ((ExtendedServiceReferenceMetadata)
metadata).getRuntimeInterface() != null) {
-                        cl.add(((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface());
-                    } else if (metadata.getInterface() != null) {
-                        cl.addAll(loadAllClasses(Collections.singletonList(metadata.getInterface())));
+                    List<Class> classList = new ArrayList<Class>();
+                    Class clz = getInterfaceClass();
+                    if (clz != null) { 
+                        classList.add(clz);
                     } else {
-                        cl.add(Object.class);
+                        classList.add(Object.class);
                     }
-                    listener.init(cl);
+                    listener.init(classList);
                 }
                 this.listeners = listeners;
             } else {
                 this.listeners = Collections.emptyList();
             }
-        } catch (ClassNotFoundException e) {
-            throw new ComponentDefinitionException(e);
-        }
     }
 
-    protected List<Class> loadAllClasses(Iterable<String> interfaceNames) throws
ClassNotFoundException {
+    protected List<Class> loadAllClasses(Iterable<String> interfaceNames) {
         List<Class> classes = new ArrayList<Class>();
         for (String name : interfaceNames) {
             Class clazz = loadClass(name);
@@ -312,13 +293,9 @@ public abstract class AbstractServiceRef
             }
             if (!proxyClass) {
                 Set<Class> interfaces = new HashSet<Class>();
-                if (metadata.getInterface() != null) {
-                    interfaces.add(loadClass(metadata.getInterface()));
-                }
-                if (metadata instanceof ExtendedReferenceListMetadata
-                            && ((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface()
!= null) {
-                        interfaces.add(((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface());
-                    }
+                Class clz = getInterfaceClass();
+                if (clz != null) interfaces.add(clz);
+                
                 for (Class cl : interfaces) {
                     if (!cl.isInterface()) {
                         throw new ComponentDefinitionException("A class " + cl.getName()
+ " was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='classes'
attribute needs to be added to this service reference.");
@@ -383,6 +360,22 @@ public abstract class AbstractServiceRef
         }
         setSatisfied(satisfied);
     }
+    
+    protected Class getInterfaceClass() {
+        Class clz = getRuntimeClass(metadata);
+        if (clz != null)
+            return clz;
+        else if (metadata.getInterface() != null)
+            return loadClass(metadata.getInterface());
+        return null;
+    }
+    
+    protected static Class getRuntimeClass(ServiceReferenceMetadata metadata) {
+        if (metadata instanceof ExtendedServiceReferenceMetadata && ((ExtendedServiceReferenceMetadata)
metadata).getRuntimeInterface() != null) {
+           return ((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface();
+        } 
+        return null;
+    }
 
     protected void setSatisfied(boolean s) {
         // This check will ensure an atomic comparision and set
@@ -576,8 +569,9 @@ public abstract class AbstractServiceRef
         }
         // Handle interfaces
         String interfaceName = metadata.getInterface();
-        if (metadata instanceof ExtendedServiceReferenceMetadata && ((ExtendedServiceReferenceMetadata)
metadata).getRuntimeInterface() != null) {
-            interfaceName = ((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface().getName();
+        Class runtimeClass = getRuntimeClass(metadata);
+        if (runtimeClass != null) {
+            interfaceName = runtimeClass.getName();
         }
         if (interfaceName != null && interfaceName.length() > 0) {
             members.add("(" + Constants.OBJECTCLASS + "=" + interfaceName + ")");

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java?rev=1021940&r1=1021939&r2=1021940&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
Tue Oct 12 22:03:01 2010
@@ -23,7 +23,6 @@ import java.util.concurrent.Callable;
 
 import org.apache.aries.blueprint.ExtendedBlueprintContainer;
 import org.apache.aries.blueprint.ExtendedReferenceListMetadata;
-import org.apache.aries.blueprint.ExtendedServiceReferenceMetadata;
 import org.apache.aries.blueprint.di.Recipe;
 import org.apache.aries.blueprint.di.CollectionRecipe;
 import org.apache.aries.blueprint.utils.DynamicCollection;
@@ -112,13 +111,9 @@ public class ReferenceListRecipe extends
                 } else {
                     dispatcher = new ServiceDispatcher(reference);
                     Set<Class> interfaces = new HashSet<Class>();
-                    if (metadata.getInterface() != null) {
-                        interfaces.add(loadClass(metadata.getInterface()));
-                    }
+                    Class clz = getInterfaceClass();
+                    if (clz != null) interfaces.add(clz);
                     if (metadata instanceof ExtendedReferenceListMetadata) {
-                        if (((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface()
!= null) {
-                            interfaces.add(((ExtendedServiceReferenceMetadata) metadata).getRuntimeInterface());
-                        }
                         boolean greedy = (((ExtendedReferenceListMetadata) metadata).getProxyMethod()
& ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY) != 0;
                         if (greedy) {
                             List<String> ifs = Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS));

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java?rev=1021940&r1=1021939&r2=1021940&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
Tue Oct 12 22:03:01 2010
@@ -20,12 +20,10 @@ package org.apache.aries.blueprint.conta
 
 import java.util.HashSet;
 import java.util.List;
-import java.util.ArrayList;
 import java.util.Set;
 import java.util.concurrent.Callable;
 
 import org.apache.aries.blueprint.ExtendedBlueprintContainer;
-import org.apache.aries.blueprint.ExtendedServiceReferenceMetadata;
 import org.apache.aries.blueprint.di.Recipe;
 import org.apache.aries.blueprint.di.CollectionRecipe;
 import org.osgi.framework.ServiceReference;
@@ -78,12 +76,8 @@ public class ReferenceRecipe extends Abs
             }
             // Create the proxy
             Set<Class> interfaces = new HashSet<Class>();
-            if (this.metadata.getInterface() != null) {
-                interfaces.add(loadClass(this.metadata.getInterface()));
-            }
-            if (this.metadata instanceof ExtendedServiceReferenceMetadata && ((ExtendedServiceReferenceMetadata)
this.metadata).getRuntimeInterface() != null) {
-                interfaces.add(((ExtendedServiceReferenceMetadata) this.metadata).getRuntimeInterface());
-            }
+            Class clz = getInterfaceClass();
+            if (clz != null) interfaces.add(clz);
 
             proxy = createProxy(new ServiceDispatcher(), interfaces);
 



Mime
View raw message