You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2012/12/31 13:47:12 UTC
svn commit: r1427111 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java
Author: struberg
Date: Mon Dec 31 12:47:11 2012
New Revision: 1427111
URL: http://svn.apache.org/viewvc?rev=1427111&view=rev
Log:
OWB-344 add InvocationHandler field to the proxy
This will contain the InvocationHandler which will hold all the
Interceptor and Decorator instances and manage them
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java
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=1427111&r1=1427110&r2=1427111&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 Dec 31 12:47:11 2012
@@ -21,6 +21,7 @@ package org.apache.webbeans.proxy;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -47,14 +48,18 @@ import org.objectweb.asm.Type;
*
* This factory will create and cache the proxy classes for a given type.
*
- * TODO: clarify how serialisation works! The proxy classes might need to get created on deserialisation!
+ *
*/
+//X TODO: clarify how serialisation works! The proxy classes might need to get created on deserialisation!
public class InterceptorDecoratorProxyFactory
{
/** the name of the field which stores the proxied instance */
public static final String FIELD_PROXIED_INSTANCE = "owbIntDecProxiedInstance";
+ /** the name of the field which stores the Interceptor + Decorator stack InvocationHandler */
+ public static final String FIELD_INVOCATION_HANDLER = "owbIntDecInvocationHandler";
+
//X TODO add caching of created proxy classes. This is needed to prevent class loading clashes.
//X a generated proxy cannot easily get redefined later!
@@ -65,7 +70,7 @@ public class InterceptorDecoratorProxyFa
this.webBeansContext = webBeansContext;
}
- public <T> T createProxyInstance(Class<T> proxyClass, T instance)
+ public <T> T createProxyInstance(Class<T> proxyClass, T instance, InvocationHandler interceptorDecoratorStack)
throws ProxyGenerationException
{
try
@@ -76,6 +81,10 @@ public class InterceptorDecoratorProxyFa
delegateField.setAccessible(true);
delegateField.set(proxy, instance);
+ Field invocationHandlerField = proxy.getClass().getDeclaredField(FIELD_INVOCATION_HANDLER);
+ invocationHandlerField.setAccessible(true);
+ invocationHandlerField.set(proxy, interceptorDecoratorStack);
+
return proxy;
}
catch (InstantiationException e)
@@ -151,8 +160,11 @@ public class InterceptorDecoratorProxyFa
private void createInstanceVariables(ClassWriter cw, Class<?> classToProxy, String classFileName)
{
- // variable #1
- createDelegationPoint(cw, classToProxy, classFileName);
+ // variable #1, the delegation point
+ cw.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy), null, null).visitEnd();
+
+ // variable #2, the invocation handler
+ cw.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, FIELD_INVOCATION_HANDLER, Type.getDescriptor(InvocationHandler.class), null, null).visitEnd();
}
/**
@@ -183,6 +195,10 @@ public class InterceptorDecoratorProxyFa
mv.visitInsn(Opcodes.ACONST_NULL);
mv.visitFieldInsn(Opcodes.PUTFIELD, proxyClassFileName, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy));
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitInsn(Opcodes.ACONST_NULL);
+ mv.visitFieldInsn(Opcodes.PUTFIELD, proxyClassFileName, FIELD_INVOCATION_HANDLER, Type.getDescriptor(InvocationHandler.class));
+
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
mv.visitEnd();
@@ -193,17 +209,6 @@ public class InterceptorDecoratorProxyFa
}
}
- /**
- * Create the private field to point to the internal contextual instance.
- * @param cw
- * @param classToProxy
- * @param classFileName
- */
- private void createDelegationPoint(ClassWriter cw, Class<?> classToProxy, String classFileName)
- {
- cw.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy), null, null).visitEnd();
- }
-
private Map<String, List<Method>> getNonPrivateMethods(Class<?> clazz)
{
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java?rev=1427111&r1=1427110&r2=1427111&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/InterceptorDecoratorProxyFactoryTest.java Mon Dec 31 12:47:11 2012
@@ -49,7 +49,7 @@ public class InterceptorDecoratorProxyFa
Class<ClassInterceptedClass> proxyClass = pf.createInterceptorDecoratorProxyClass(classLoader, ClassInterceptedClass.class);
Assert.assertNotNull(proxyClass);
- ClassInterceptedClass proxy = pf.createProxyInstance(proxyClass, new ClassInterceptedClass());
+ ClassInterceptedClass proxy = pf.createProxyInstance(proxyClass, new ClassInterceptedClass(), null);
Assert.assertNotNull(proxy);
// we need to get the field from the proxy via reflection