openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1436691 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: intercept/ proxy/ proxy/asm/ proxy/javassist/
Date Mon, 21 Jan 2013 23:43:17 GMT
Author: struberg
Date: Mon Jan 21 23:43:17 2013
New Revision: 1436691

URL: http://svn.apache.org/viewvc?rev=1436691&view=rev
Log:
OWB-344 improve proxying of protected methods

We can only  proxy protected methods if they are contained
in the same ClassLoader. 

Removed:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1436691&r1=1436690&r2=1436691&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Mon Jan 21 23:43:17 2013
@@ -126,7 +126,7 @@ public final class WebBeansInterceptorCo
                 // we only need to create a proxy class for intercepted or decorated Beans
                 InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
 
-                ClassLoader classLoader = this.getClass().getClassLoader();
+                ClassLoader classLoader = bean.getBeanClass().getClassLoader();
 
                 Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
                 Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new
Method[interceptorInfo.getNonInterceptedMethods().size()]);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1436691&r1=1436690&r2=1436691&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
Mon Jan 21 23:43:17 2013
@@ -94,13 +94,13 @@ public abstract class AbstractProxyFacto
     /**
      * generate the bytecode for invoking all intercepted methods
      */
-    protected abstract void delegateInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] interceptedMethods)
+    protected abstract void delegateInterceptedMethods(ClassLoader classLoader, ClassWriter
cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)
             throws ProxyGenerationException;
 
     /**
      * generate the bytecode for invoking all non-intercepted methods
      */
-    protected abstract void delegateNonInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] noninterceptedMethods)
+    protected abstract void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter
cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)
             throws ProxyGenerationException;
 
     /**
@@ -172,14 +172,14 @@ public abstract class AbstractProxyFacto
     {
         String proxyClassFileName = proxyClassName.replace('.', '/');
 
-        final byte[] proxyBytes = generateProxy(classToProxy, proxyClassName, proxyClassFileName,
interceptedMethods, nonInterceptedMethods);
+        final byte[] proxyBytes = generateProxy(classLoader, classToProxy, proxyClassName,
proxyClassFileName, interceptedMethods, nonInterceptedMethods);
 
         Class<T> clazz = defineAndLoadClass(classLoader, proxyClassName, proxyBytes);
 
         return clazz;
     }
 
-    private byte[] generateProxy(Class<?> classToProxy, String proxyClassName, String
proxyClassFileName,
+    private byte[] generateProxy(ClassLoader classLoader, Class<?> classToProxy, String
proxyClassName, String proxyClassFileName,
                                  Method[] interceptedMethods, Method[] nonInterceptedMethods)
             throws ProxyGenerationException
     {
@@ -212,12 +212,12 @@ public abstract class AbstractProxyFacto
 
         if (nonInterceptedMethods != null)
         {
-            delegateNonInterceptedMethods(cw, proxyClassFileName, classToProxy, nonInterceptedMethods);
+            delegateNonInterceptedMethods(classLoader, cw, proxyClassFileName, classToProxy,
nonInterceptedMethods);
         }
 
         if (interceptedMethods != null)
         {
-            delegateInterceptedMethods(cw, proxyClassFileName, classToProxy, interceptedMethods);
+            delegateInterceptedMethods(classLoader, cw, proxyClassFileName, classToProxy,
interceptedMethods);
         }
 
         return cw.toByteArray();
@@ -284,7 +284,7 @@ public abstract class AbstractProxyFacto
         int modifiers = delegatedMethod.getModifiers();
 
         //X TODO how to deal with native functions?
-        return (modifiers & (Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL | Modifier.PROTECTED
| Modifier.NATIVE)) > 0 ||
+        return (modifiers & (Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL | Modifier.NATIVE))
> 0 ||
                "finalize".equals(delegatedMethod.getName());
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java?rev=1436691&r1=1436690&r2=1436691&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
Mon Jan 21 23:43:17 2013
@@ -255,7 +255,7 @@ public class InterceptorDecoratorProxyFa
      *
      * @param noninterceptedMethods all methods which are neither intercepted nor decorated
      */
-    protected void delegateNonInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] noninterceptedMethods)
+    protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw,
String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)
     {
         for (Method delegatedMethod : noninterceptedMethods)
         {
@@ -304,7 +304,7 @@ public class InterceptorDecoratorProxyFa
         }
     }
 
-    protected void delegateInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] interceptedMethods)
+    protected void delegateInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String
proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)
             throws ProxyGenerationException
     {
         for (int i = 0; i < interceptedMethods.length; i++)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java?rev=1436691&r1=1436690&r2=1436691&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
Mon Jan 21 23:43:17 2013
@@ -276,13 +276,17 @@ public class NormalScopeProxyFactory ext
     }
 
     @Override
-    protected void delegateInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] interceptedMethods) throws ProxyGenerationException
+    protected void delegateInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String
proxyClassFileName,
+                                              Class<?> classToProxy, Method[] interceptedMethods)
+            throws ProxyGenerationException
     {
         // nothing to do ;)
     }
 
     @Override
-    protected void delegateNonInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException
+    protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw,
String proxyClassFileName,
+                                                 Class<?> classToProxy, Method[] noninterceptedMethods)
+            throws ProxyGenerationException
     {
         for (Method delegatedMethod : noninterceptedMethods)
         {
@@ -290,6 +294,14 @@ public class NormalScopeProxyFactory ext
             {
                 continue;
             }
+            if (classLoader != classToProxy.getClassLoader())
+            {
+                // we can only proxy protected methods that way if the subclass and proxied
class are in the same classloader
+                if (Modifier.isProtected(delegatedMethod.getModifiers()))
+                {
+                    continue;
+                }
+            }
 
             String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java?rev=1436691&r1=1436690&r2=1436691&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
Mon Jan 21 23:43:17 2013
@@ -156,7 +156,8 @@ public class SubclassProxyFactory extend
     }
 
     @Override
-    protected void delegateInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] interceptedMethods) throws ProxyGenerationException
+    protected void delegateInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String
proxyClassFileName, Class<?> classToProxy,
+                                              Method[] interceptedMethods) throws ProxyGenerationException
     {
     }
 
@@ -167,7 +168,8 @@ public class SubclassProxyFactory extend
     }
 
     @Override
-    protected void delegateNonInterceptedMethods(ClassWriter cw, String proxyClassFileName,
Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException
+    protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw,
String proxyClassFileName, Class<?> classToProxy,
+                                                 Method[] noninterceptedMethods) throws ProxyGenerationException
     {
         for (Method delegatedMethod : noninterceptedMethods)
         {



Mime
View raw message