aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1133129 - /aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
Date Tue, 07 Jun 2011 18:51:16 GMT
Author: timothyjward
Date: Tue Jun  7 18:51:16 2011
New Revision: 1133129

URL: http://svn.apache.org/viewvc?rev=1133129&view=rev
Log:
ARIES-671 : Cope with non-imported dependencies for proxy by interface

Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java?rev=1133129&r1=1133128&r2=1133129&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
Tue Jun  7 18:51:16 2011
@@ -1,18 +1,21 @@
 package org.apache.aries.proxy.impl.interfaces;
 
 import java.security.ProtectionDomain;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
 
 import org.apache.aries.proxy.InvocationListener;
 import org.apache.aries.proxy.UnableToProxyException;
 import org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter;
 import org.apache.aries.proxy.weaving.WovenProxy;
 import org.apache.aries.util.AriesFrameworkUtil;
-import org.apache.aries.util.BundleToClassLoaderAdapter;
 import org.osgi.framework.Bundle;
 
 /** An implementation of ClassLoader that will be used to define our proxy class */
@@ -22,6 +25,13 @@ final class ProxyClassLoader extends Cla
   private final ConcurrentMap<HashSet<Class<?>>, String> classes = 
                 new ConcurrentHashMap<HashSet<Class<?>>, String>();
   
+  private final ConcurrentMap<String, Class<?>> locatedClasses = 
+                new ConcurrentHashMap<String, Class<?>>();
+  
+  private final Set<Class<?>> ifaces = new HashSet<Class<?>>();
+  
+  private final ReadWriteLock ifacesLock = new ReentrantReadWriteLock();
+  
   public ProxyClassLoader(Bundle bundle) {
     super(AriesFrameworkUtil.getClassLoader(bundle));
   }
@@ -33,8 +43,30 @@ final class ProxyClassLoader extends Cla
       return WovenProxy.class;
     else if (InvocationListener.class.getName().equals(className))
       return InvocationListener.class;
-    else 
-      return null;
+    else {
+      Class<?> c = locatedClasses.get(className);
+      if(c != null)
+        return c;
+      Lock rLock = ifacesLock.readLock();
+      rLock.lock();
+      try {
+        Set<ClassLoader> cls = new HashSet<ClassLoader>();
+        for(Class<?> iface : ifaces) {
+          if(cls.add(iface.getClassLoader())) {
+            try {
+              c = Class.forName(className, false, iface.getClassLoader());
+              locatedClasses.put(className, c);
+              return c;
+            } catch (ClassNotFoundException e) {
+              // This is a no-op
+            }
+          }
+        }
+      } finally {
+        rLock.unlock();
+      }
+    }
+    return null;
   }
 
   public Class<?> createProxyClass(HashSet<Class<?>> createSet) throws
UnableToProxyException {
@@ -50,16 +82,24 @@ final class ProxyClassLoader extends Cla
       }
     }
     
+    Lock wLock = ifacesLock.writeLock();
+    wLock.lock();
+    try {
+      ifaces.addAll(createSet);
+    } finally {
+      wLock.unlock();
+    }
+    
     className = "Proxy" + AbstractWovenProxyAdapter.getSanitizedUUIDString();
     
     InterfaceCombiningClassAdapter icca = new InterfaceCombiningClassAdapter(
         className, this, createSet);
     
-    //Use the protection domain of the first interface in the set
+    //Do not use a protection domain the real code will inherit permissions from
+    //the real class, not the proxy class
     try {
       byte[] bytes = icca.generateBytes();
-      ProtectionDomain pd = createSet.iterator().next().getProtectionDomain();
-      Class<?> c = defineClass(className, bytes, 0, bytes.length, pd);
+      Class<?> c = defineClass(className, bytes, 0, bytes.length);
       String old = classes.putIfAbsent(createSet, className);
       if(old != null) {
         c = Class.forName(className, false, this);



Mime
View raw message