Author: struberg
Date: Thu Jan 3 22:17:16 2013
New Revision: 1428640
URL: http://svn.apache.org/viewvc?rev=1428640&view=rev
Log:
OWB-344 remove instance from InterceptorHandler
We don't need it as we store it in the InterceptorHandler already
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorHandler.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=1428640&r1=1428639&r2=1428640&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
Thu Jan 3 22:17:16 2013
@@ -349,41 +349,20 @@ public class InterceptorDecoratorProxyFa
}
}
-/*X TODO remove. we dont resolve the methods dynamically
- // invoke getMethod() with the method name and the array of types
- mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class",
"getDeclaredMethod",
-
"(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
-
- // store the returned method for later
- mv.visitVarInsn(Opcodes.ASTORE, length);
-*/
-
// the following code generates bytecode equivalent to:
- // return ((<returntype>) invocationHandler.invoke(this, method, new
Object[] { <function arguments }))[.<primitive>Value()];
+ // return ((<returntype>) invocationHandler.invoke(this,
{methodIndex}, new Object[] { <function arguments }))[.<primitive>Value()];
final Label l4 = new Label();
mv.visitLabel(l4);
mv.visitVarInsn(Opcodes.ALOAD, 0);
// get the invocationHandler field from this class
-//X mv.visitFieldInsn(Opcodes.GETFIELD, proxyName,
FIELD_INVOCATION_HANDLER, "Ljava/lang/reflect/InvocationHandler;");
mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName,
FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class));
- // we want to pass "this" in as the first parameter
- //X mv.visitVarInsn(Opcodes.ALOAD, 0);
-
- // load the delegate variable as first parameter
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName,
FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy));
-
// add the methodIndex as context as second parameter
mv.visitIntInsn(Opcodes.BIPUSH, methodIndex);
- // and the method we fetched earlier
- //X mv.visitVarInsn(Opcodes.ALOAD, length);
-
// need to construct the array of objects passed in
-
// create the Object[]
createArrayDefinition(mv, parameterTypes.length, Object.class);
@@ -427,7 +406,7 @@ public class InterceptorDecoratorProxyFa
// invoke the invocationHandler
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
Type.getInternalName(InterceptorHandler.class), "invoke",
- "(Ljava/lang/Object;I[Ljava/lang/Object;)Ljava/lang/Object;");
+ "(I[Ljava/lang/Object;)Ljava/lang/Object;");
// cast the result
mv.visitTypeInsn(Opcodes.CHECKCAST, getCastType(returnType));
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorHandler.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorHandler.java?rev=1428640&r1=1428639&r2=1428640&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorHandler.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorHandler.java
Thu Jan 3 22:17:16 2013
@@ -25,11 +25,10 @@ public interface InterceptorHandler
/**
*
- * @param instance
* @param methodIndex index to find the Method
* @param args
* @return
* @throws Throwable
*/
- public Object invoke(Object instance, int methodIndex, Object[] args)
throws Throwable;
+ public Object invoke(int methodIndex, Object[] args);
}
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=1428640&r1=1428639&r2=1428640&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
Thu Jan 3 22:17:16 2013
@@ -19,12 +19,14 @@
package org.apache.webbeans.newtests.interceptors.factory;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
+import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.newtests.AbstractUnitTest;
import
org.apache.webbeans.newtests.interceptors.factory.beans.ClassInterceptedClass;
import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
@@ -62,7 +64,7 @@ public class InterceptorDecoratorProxyFa
ClassInterceptedClass internalInstance = new ClassInterceptedClass();
internalInstance.init();
- TestInvocationHandler testInvocationHandler = new
TestInvocationHandler(interceptedMethods);
+ TestInvocationHandler testInvocationHandler = new
TestInvocationHandler(internalInstance, interceptedMethods);
ClassInterceptedClass proxy = pf.createProxyInstance(proxyClass,
internalInstance, testInvocationHandler);
Assert.assertNotNull(proxy);
@@ -91,21 +93,34 @@ public class InterceptorDecoratorProxyFa
{
public List<String> invokedMethodNames = new ArrayList<String>();
+ private Object instance;
private List<Method> interceptedMethods;
- public TestInvocationHandler(List<Method> interceptedMethods)
+ public TestInvocationHandler(Object instance, List<Method>
interceptedMethods)
{
+ this.instance = instance;
this.interceptedMethods = interceptedMethods;
}
@Override
- public Object invoke(Object instance, int methodIndex, Object[] args)
throws Throwable
+ public Object invoke(int methodIndex, Object[] args)
{
invokedMethodNames.add(interceptedMethods.get(methodIndex).getName());
System.out.println("TestInvocationHandler got properly invoked for
method " + interceptedMethods.get(methodIndex).getName());
- return interceptedMethods.get(methodIndex).invoke(instance, args);
+ try
+ {
+ return interceptedMethods.get(methodIndex).invoke(instance,
args);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new WebBeansException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new WebBeansException(e);
+ }
}
}
}