commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1388097 - in /commons/proper/proxy/branches/version-2.0-work: cglib/src/main/java/org/apache/commons/proxy2/cglib/ core/src/test/java/org/apache/commons/proxy2/ javassist/src/main/java/org/apache/commons/proxy2/javassist/ jdk/src/main/java...
Date Thu, 20 Sep 2012 16:19:37 GMT
Author: mbenson
Date: Thu Sep 20 16:19:37 2012
New Revision: 1388097

URL: http://svn.apache.org/viewvc?rev=1388097&view=rev
Log:
[PROXY-18] Invocation should return the proxy object, rather than the target, from #getProxy()

Modified:
    commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
    commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
    commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
    commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
    commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
    commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java

Modified: commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
Thu Sep 20 16:19:37 2012
@@ -148,8 +148,8 @@ public class CglibProxyFactory extends A
         /** Serialization version */
         private static final long serialVersionUID = 1L;
 
-        private final Interceptor inner;
         private final Object target;
+        private final Interceptor inner;
 
         public InterceptorBridge(Object target, Interceptor inner)
         {
@@ -159,7 +159,7 @@ public class CglibProxyFactory extends A
 
         public Object intercept(Object object, Method method, Object[] args, MethodProxy
methodProxy) throws Throwable
         {
-            return inner.intercept(new MethodProxyInvocation(target, method, args, methodProxy));
+            return inner.intercept(new MethodProxyInvocation(object, target, method, args,
methodProxy));
         }
     }
 
@@ -186,13 +186,15 @@ public class CglibProxyFactory extends A
         /** Serialization version */
         private static final long serialVersionUID = 1L;
 
-        private final MethodProxy methodProxy;
+        private final Object proxy;
+        private final Object target;
         private final Method method;
         private final Object[] args;
-        private final Object target;
+        private final MethodProxy methodProxy;
 
-        public MethodProxyInvocation(Object target, Method method, Object[] args, MethodProxy
methodProxy)
+        public MethodProxyInvocation(Object proxy, Object target, Method method, Object[]
args, MethodProxy methodProxy)
         {
+            this.proxy = proxy;
             this.target = target;
             this.method = method;
             this.methodProxy = methodProxy;
@@ -216,7 +218,7 @@ public class CglibProxyFactory extends A
 
         public Object getProxy()
         {
-            return target;
+            return proxy;
         }
     }
 

Modified: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
Thu Sep 20 16:19:37 2012
@@ -294,7 +294,7 @@ public abstract class AbstractProxyFacto
         assertNotNull(tester.arguments);
         assertEquals(0, tester.arguments.length);
         assertEquals(Echo.class.getMethod("echo"), tester.method);
-        assertEquals(target, tester.proxy);
+        assertSame(proxy, tester.proxy);
         proxy.echoBack("Hello");
         assertNotNull(tester.arguments);
         assertEquals(1, tester.arguments.length);

Modified: commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
Thu Sep 20 16:19:37 2012
@@ -47,12 +47,15 @@ public abstract class JavassistInvocatio
 
     private static WeakHashMap<ClassLoader, Map<String, WeakReference<Class<?>>>>
loaderToClassCache = new WeakHashMap<ClassLoader, Map<String,WeakReference<Class<?>>>>();
 
-    /** The invoked method */
-    private final Method method;
+    /** The proxy object */
+    private final Object proxy;
 
     /** The target object */
     private final Object target;
 
+    /** The invoked method */
+    private final Method method;
+
     /** The method arguments */
     private final Object[] arguments;
 
@@ -82,14 +85,14 @@ public abstract class JavassistInvocatio
                         "_invocation",
                 JavassistInvocation.class);
         final CtConstructor constructor = new CtConstructor(
-                JavassistUtils.resolve(new Class[] {Method.class, Object.class, Object[].class}),
+                JavassistUtils.resolve(new Class[] { Object.class, Object.class, Method.class,
Object[].class }),
                 ctClass);
         constructor.setBody("{\n\tsuper($$);\n}");
         ctClass.addConstructor(constructor);
         final CtMethod proceedMethod = new CtMethod(JavassistUtils.resolve(Object.class),
"proceed",
                 JavassistUtils.resolve(new Class[0]), ctClass);
         final Class<?>[] argumentTypes = interfaceMethod.getParameterTypes();
-        final StringBuffer proceedBody = new StringBuffer("{\n");
+        final StringBuilder proceedBody = new StringBuilder("{\n");
         if( !Void.TYPE.equals(interfaceMethod.getReturnType()) )
         {
             proceedBody.append("\treturn ");
@@ -201,10 +204,11 @@ public abstract class JavassistInvocatio
 // Constructors
 //**********************************************************************************************************************
 
-    public JavassistInvocation( Method method, Object target, Object[] arguments )
+    public JavassistInvocation( Object proxy, Object target, Method method, Object[] arguments
)
     {
-        this.method = method;
+        this.proxy = proxy;
         this.target = target;
+        this.method = method;
         this.arguments = ArrayUtils.clone(arguments);
     }
 
@@ -228,6 +232,6 @@ public abstract class JavassistInvocatio
 
     public Object getProxy()
     {
-        return target;
+        return proxy;
     }
 }

Modified: commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
Thu Sep 20 16:19:37 2012
@@ -202,8 +202,8 @@ public class JavassistProxyFactory exten
                                 .getMethodInvocationClass(classLoader, methods[i]);
 
                         final String body = "{\n\t return ( $r ) interceptor.intercept( new
" + invocationClass.getName() +
-                                "( " + GET_METHOD_METHOD_NAME + "(\"" + methods[i].getDeclaringClass().getName()
+
-                                "\", \"" + methods[i].getName() + "\", $sig), target, $args
) );\n }";
+                                "( this, target, " + GET_METHOD_METHOD_NAME + "(\"" + methods[i].getDeclaringClass().getName()
+
+                                "\", \"" + methods[i].getName() + "\", $sig), $args ) );\n
}";
                         method.setBody(body);
                         proxyClass.addMethod(method);
                     }

Modified: commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
Thu Sep 20 16:19:37 2012
@@ -159,7 +159,7 @@ public class JdkProxyFactory extends Abs
 
         public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
         {
-            final ReflectionInvocation invocation = new ReflectionInvocation(target, method,
args);
+            final ReflectionInvocation invocation = new ReflectionInvocation(proxy, target,
method, args);
             return methodInterceptor.intercept(invocation);
         }
     }
@@ -187,15 +187,17 @@ public class JdkProxyFactory extends Abs
         /** Serialization version */
         private static final long serialVersionUID = 1L;
 
+        private final Object proxy;
+        private final Object target;
         private final Method method;
         private final Object[] arguments;
-        private final Object target;
 
-        public ReflectionInvocation( Object target, Method method, Object[] arguments )
+        public ReflectionInvocation( Object proxy, Object target, Method method, Object[]
arguments )
         {
+            this.proxy = proxy;
+            this.target = target;
             this.method = method;
             this.arguments = ( arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments
);
-            this.target = target;
         }
 
         public Object[] getArguments()
@@ -210,7 +212,7 @@ public class JdkProxyFactory extends Abs
 
         public Object getProxy()
         {
-            return target;
+            return proxy;
         }
 
         public Object proceed() throws Throwable

Modified: commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java?rev=1388097&r1=1388096&r2=1388097&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java
Thu Sep 20 16:19:37 2012
@@ -110,7 +110,7 @@ public class AnnotationFactory {
             if ("toString".equals(method.getName()) && method.getParameterTypes().length
== 0) {
                 return AnnotationUtils.toString((Annotation) proxy);
             }
-            final ReflectionInvocation invocation = new ReflectionInvocation(target, method,
args);
+            final ReflectionInvocation invocation = new ReflectionInvocation(proxy, target,
method, args);
             return methodInterceptor.intercept(invocation);
         }
 
@@ -120,14 +120,16 @@ public class AnnotationFactory {
         /** Serialization version */
         private static final long serialVersionUID = 1L;
 
+        private final Object proxy;
+        private final Object target;
         private final Method method;
         private final Object[] arguments;
-        private final Object target;
 
-        public ReflectionInvocation(Object target, Method method, Object[] arguments) {
+        public ReflectionInvocation(Object proxy, Object target, Method method, Object[]
arguments) {
+            this.proxy = proxy;
+            this.target = target;
             this.method = method;
             this.arguments = (arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments);
-            this.target = target;
         }
 
         public Object[] getArguments() {
@@ -139,7 +141,7 @@ public class AnnotationFactory {
         }
 
         public Object getProxy() {
-            return target;
+            return proxy;
         }
 
         public Object proceed() throws Throwable {



Mime
View raw message