Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 96452 invoked from network); 27 Feb 2008 18:54:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Feb 2008 18:54:30 -0000 Received: (qmail 68302 invoked by uid 500); 27 Feb 2008 18:54:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 68233 invoked by uid 500); 27 Feb 2008 18:54:24 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 68224 invoked by uid 99); 27 Feb 2008 18:54:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Feb 2008 10:54:24 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Feb 2008 18:53:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 015AE1A9832; Wed, 27 Feb 2008 10:54:07 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: jcarman@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080227185408.015AE1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 proxyClasses transformed into an array of only the interface classes. *

* Note: 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 MethodFilter 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;