commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r631675 - in /commons/proper/proxy/trunk/src: main/java/org/apache/commons/proxy/ main/java/org/apache/commons/proxy/factory/util/ main/java/org/apache/commons/proxy/interceptor/ test/java/org/apache/commons/proxy/interceptor/ test/java/org...
Date Wed, 27 Feb 2008 18:54:04 GMT
Author: jcarman
Date: Wed Feb 27 10:54:01 2008
New Revision: 631675

URL: http://svn.apache.org/viewvc?rev=631675&view=rev
Log:
PROXY-8: Improve Proxy Serialization

Modified:
    commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/Interceptor.java
    commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
    commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/interceptor/MethodFilter.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestExecutorInterceptor.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestFilteredInterceptor.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestInterceptorChain.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestDuckTypingInvoker.java
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java

Modified: commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/Interceptor.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/Interceptor.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/Interceptor.java (original)
+++ commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/Interceptor.java Wed
Feb 27 10:54:01 2008
@@ -17,13 +17,15 @@
 
 package org.apache.commons.proxy;
 
+import java.io.Serializable;
+
 /**
  * "Intercepts" a method invocation.
  *
  * @author James Carman
  * @since 1.0
  */
-public interface Interceptor
+public interface Interceptor extends Serializable
 {
 //**********************************************************************************************************************
 // Other Methods

Modified: commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
(original)
+++ commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
Wed Feb 27 10:54:01 2008
@@ -101,28 +101,6 @@
     }
 
     /**
-     * Helper method for instantiating a proxy object from its proxy class.  Uses the default
constructor.
-     *
-     * @param proxyClass the proxy class
-     * @return a proxy object
-     */
-    protected static Object instantiate( Class proxyClass )
-    {
-        try
-        {
-            return proxyClass.newInstance();
-        }
-        catch( InstantiationException e )
-        {
-            throw new ProxyFactoryException("Unable to instantiate proxy object from proxy
class.", e);
-        }
-        catch( IllegalAccessException e )
-        {
-            throw new ProxyFactoryException("Unable to instantiate proxy object from proxy
class.", e);
-        }
-    }
-
-    /**
      * Returns the <code>proxyClasses</code> transformed into an array of only
the interface classes.
      * <p/>
      * <b>Note</b>: This class will append {@link Serializable} to the end of
the list if it's

Modified: commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/interceptor/MethodFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/interceptor/MethodFilter.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/interceptor/MethodFilter.java
(original)
+++ commons/proper/proxy/trunk/src/main/java/org/apache/commons/proxy/interceptor/MethodFilter.java
Wed Feb 27 10:54:01 2008
@@ -18,6 +18,7 @@
 package org.apache.commons.proxy.interceptor;
 
 import java.lang.reflect.Method;
+import java.io.Serializable;
 
 /**
  * A <code>MethodFilter</code> determines whether or not a method is accepted.
@@ -25,7 +26,7 @@
  * @author James Carman
  * @since 1.0
  */
-public interface MethodFilter
+public interface MethodFilter extends Serializable
 {
 //**********************************************************************************************************************
 // Other Methods

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestExecutorInterceptor.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestExecutorInterceptor.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestExecutorInterceptor.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestExecutorInterceptor.java
Wed Feb 27 10:54:01 2008
@@ -30,6 +30,15 @@
 // Other Methods
 //**********************************************************************************************************************
 
+    public void testMethodThrowsException()
+    {
+        final ExceptionEcho impl = new ExceptionEcho();
+        final OneShotExecutor executor = new OneShotExecutor();
+        final Echo proxy = ( Echo ) new CglibProxyFactory()
+                .createInterceptorProxy(impl, new ExecutorInterceptor(executor), new Class[]
{Echo.class});
+        proxy.echo();
+    }
+
     public void testNonVoidMethod() throws Exception
     {
         final ExecutedEcho impl = new ExecutedEcho();
@@ -60,6 +69,17 @@
 //**********************************************************************************************************************
 // Inner Classes
 //**********************************************************************************************************************
+
+//
+// Inner Classes
+//
+    public static class ExceptionEcho extends EchoImpl
+    {
+        public void echo()
+        {
+            throw new RuntimeException("Oops!");
+        }
+    }
 
     public static class ExecutedEcho extends EchoImpl
     {

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestFilteredInterceptor.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestFilteredInterceptor.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestFilteredInterceptor.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestFilteredInterceptor.java
Wed Feb 27 10:54:01 2008
@@ -17,10 +17,10 @@
 
 package org.apache.commons.proxy.interceptor;
 
-import junit.framework.TestCase;
 import org.apache.commons.proxy.Interceptor;
 import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
 import org.apache.commons.proxy.interceptor.filter.SimpleFilter;
+import org.apache.commons.proxy.util.AbstractTestCase;
 import org.apache.commons.proxy.util.Echo;
 import org.apache.commons.proxy.util.EchoImpl;
 import org.apache.commons.proxy.util.SuffixInterceptor;
@@ -29,12 +29,17 @@
  * @author James Carman
  * @since 1.0
  */
-public class TestFilteredInterceptor extends TestCase
+public class TestFilteredInterceptor extends AbstractTestCase
 {
 //**********************************************************************************************************************
 // Other Methods
 //**********************************************************************************************************************
 
+    public void testSerialization()
+    {
+        assertSerializable(new FilteredInterceptor(new SuffixInterceptor("a"), new SimpleFilter(new
String[] {"echoBack"})));
+    }
+    
     public void testFilterAccepts()
     {
         Echo echo = ( Echo ) new InterceptorChain(new Interceptor[] {new FilteredInterceptor(new
SuffixInterceptor("a"), new SimpleFilter(new String[] {"echoBack"}))}).createProxyProvider(new
CglibProxyFactory(), new EchoImpl()).getObject();

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestInterceptorChain.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestInterceptorChain.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestInterceptorChain.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestInterceptorChain.java
Wed Feb 27 10:54:01 2008
@@ -17,23 +17,29 @@
 
 package org.apache.commons.proxy.interceptor;
 
-import junit.framework.TestCase;
 import org.apache.commons.proxy.Interceptor;
 import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
 import org.apache.commons.proxy.util.Echo;
 import org.apache.commons.proxy.util.EchoImpl;
 import org.apache.commons.proxy.util.SuffixInterceptor;
+import org.apache.commons.proxy.util.AbstractTestCase;
 
 /**
  * @author James Carman
  * @since 1.0
  */
-public class TestInterceptorChain extends TestCase
+public class TestInterceptorChain extends AbstractTestCase
 {
 //**********************************************************************************************************************
 // Other Methods
 //**********************************************************************************************************************
 
+    public void testSerializable()
+    {
+        Echo echo = ( Echo ) new InterceptorChain(new Interceptor[] {new SuffixInterceptor("a"),
new SuffixInterceptor("b")}).createProxyProvider(new CglibProxyFactory(), new EchoImpl(),
new Class[] {Echo.class}).getObject();
+        assertSerializable(echo);
+    }
+    
     public void testWithMultipleInterceptors()
     {
         Echo echo = ( Echo ) new InterceptorChain(new Interceptor[] {new SuffixInterceptor("a"),
new SuffixInterceptor("b")}).createProxyProvider(new CglibProxyFactory(), new EchoImpl(),
new Class[] {Echo.class}).getObject();

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java
Wed Feb 27 10:54:01 2008
@@ -17,19 +17,30 @@
 
 package org.apache.commons.proxy.interceptor;
 
-import junit.framework.TestCase;
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
 import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory;
+import org.apache.commons.proxy.util.AbstractTestCase;
 import org.apache.commons.proxy.util.Echo;
 import org.apache.commons.proxy.util.EchoImpl;
 
-public class TestMethodInterceptorAdapter extends TestCase
+import java.io.Serializable;
+
+public class TestMethodInterceptorAdapter extends AbstractTestCase
 {
 //**********************************************************************************************************************
 // Other Methods
 //**********************************************************************************************************************
 
+    public void testSerialization()
+    {
+        final Echo proxy = ( Echo ) new JavassistProxyFactory().createInterceptorProxy(new
EchoImpl(),
+                new MethodInterceptorAdapter(new SuffixMethodInterceptor(
+                        " suffix")),
+                new Class[] {Echo.class});
+        assertSerializable(proxy);
+    }
+    
     public void testMethodInterception()
     {
         final Echo proxy = ( Echo ) new JavassistProxyFactory().createInterceptorProxy(new
EchoImpl(),
@@ -80,7 +91,7 @@
         }
     }
 
-    private class SuffixMethodInterceptor implements MethodInterceptor
+    private static class SuffixMethodInterceptor implements MethodInterceptor, Serializable
     {
         private final String suffix;
 

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestDuckTypingInvoker.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestDuckTypingInvoker.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestDuckTypingInvoker.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestDuckTypingInvoker.java
Wed Feb 27 10:54:01 2008
@@ -17,17 +17,17 @@
 
 package org.apache.commons.proxy.invoker;
 
-import junit.framework.TestCase;
 import org.apache.commons.proxy.ObjectProvider;
 import org.apache.commons.proxy.ProxyFactory;
 import org.apache.commons.proxy.provider.ConstantProvider;
+import org.apache.commons.proxy.util.AbstractTestCase;
 
 import java.io.Serializable;
 
 /**
  *
  */
-public class TestDuckTypingInvoker extends TestCase
+public class TestDuckTypingInvoker extends AbstractTestCase
 {
 //**********************************************************************************************************************
 // Other Methods
@@ -91,6 +91,13 @@
         }
     }
 
+    public void testSerialization()
+    {
+        final ObjectProvider targetProvider = new ConstantProvider(new LegacyDuck());
+        final DuckTypingInvoker invoker = new DuckTypingInvoker(targetProvider);
+        assertSerializable(invoker);
+    }
+
     public void testTargetHasCompatibleReturnType()
     {
         final ObjectProvider targetProvider = new ConstantProvider(new LegacyDuck());
@@ -114,7 +121,7 @@
         public void sayHonk();
     }
 
-    public static class LegacyDuck
+    public static class LegacyDuck implements Serializable
     {
         public String sayQuack()
         {

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java?rev=631675&r1=631674&r2=631675&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java
Wed Feb 27 10:54:01 2008
@@ -17,19 +17,25 @@
 
 package org.apache.commons.proxy.invoker;
 
-import junit.framework.TestCase;
 import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory;
+import org.apache.commons.proxy.util.AbstractTestCase;
 import org.apache.commons.proxy.util.Echo;
 
+import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 
-public class TestInvocationHandlerAdapter extends TestCase
+public class TestInvocationHandlerAdapter extends AbstractTestCase
 {
 //**********************************************************************************************************************
 // Other Methods
 //**********************************************************************************************************************
 
+    public void testSerialization()
+    {
+        assertSerializable( new InvocationHandlerAdapter( new InvocationHandlerTester() )
);
+    }
+    
     public void testMethodInvocation() throws Exception
     {
         InvocationHandlerTester tester = new InvocationHandlerTester();
@@ -46,7 +52,7 @@
 // Inner Classes
 //**********************************************************************************************************************
 
-    private class InvocationHandlerTester implements InvocationHandler
+    private static class InvocationHandlerTester implements InvocationHandler, Serializable
     {
         private Object proxy;
         private Method method;



Mime
View raw message