You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jc...@apache.org on 2010/07/16 01:10:46 UTC
svn commit: r964636 [1/3] - in
/commons/proper/proxy/branches/version-2.0-work: ./ cglib/ cglib/src/
cglib/src/main/ cglib/src/main/java/ cglib/src/main/java/org/
cglib/src/main/java/org/apache/ cglib/src/main/java/org/apache/commons/
cglib/src/main/ja...
Author: jcarman
Date: Thu Jul 15 23:10:43 2010
New Revision: 964636
URL: http://svn.apache.org/viewvc?rev=964636&view=rev
Log:
work in progress.
Added:
commons/proper/proxy/branches/version-2.0-work/cglib/
commons/proper/proxy/branches/version-2.0-work/cglib/pom.xml
commons/proper/proxy/branches/version-2.0-work/cglib/src/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/
commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/CglibProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/
commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/TestCglibProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/core/
commons/proper/proxy/branches/version-2.0-work/core/pom.xml
commons/proper/proxy/branches/version-2.0-work/core/src/
commons/proper/proxy/branches/version-2.0-work/core/src/main/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Interceptor.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invocation.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invoker.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ObjectProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/BeanProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/CloningProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ConstantProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/NullProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ProviderDecorator.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/SingletonProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractProxyFactoryTestCase.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractSubclassingProxyFactoryTestCase.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractEcho.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/DuplicateEcho.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/Echo.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/EchoImpl.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/QuoteService.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/SuffixInterceptor.java
commons/proper/proxy/branches/version-2.0-work/javassist/
commons/proper/proxy/branches/version-2.0-work/javassist/pom.xml
commons/proper/proxy/branches/version-2.0-work/javassist/src/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy/javassist/
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy/javassist/JavassistInvocation.java
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy/javassist/JavassistProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/javassist/src/main/java/org/apache/commons/proxy/javassist/JavassistUtils.java
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/apache/commons/proxy/javassist/
commons/proper/proxy/branches/version-2.0-work/javassist/src/test/java/org/apache/commons/proxy/javassist/TestJavassistProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/jdk/
commons/proper/proxy/branches/version-2.0-work/jdk/pom.xml
commons/proper/proxy/branches/version-2.0-work/jdk/src/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy/jdk/
commons/proper/proxy/branches/version-2.0-work/jdk/src/main/java/org/apache/commons/proxy/jdk/JdkProxyFactory.java
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/apache/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/apache/commons/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/apache/commons/proxy/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/apache/commons/proxy/jdk/
commons/proper/proxy/branches/version-2.0-work/jdk/src/test/java/org/apache/commons/proxy/jdk/TestJdkProxyFactory.java
Modified:
commons/proper/proxy/branches/version-2.0-work/pom.xml
Added: commons/proper/proxy/branches/version-2.0-work/cglib/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/cglib/pom.xml?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/cglib/pom.xml (added)
+++ commons/proper/proxy/branches/version-2.0-work/cglib/pom.xml Thu Jul 15 23:10:43 2010
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>commons-proxy</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>commons-proxy-cglib</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-proxy-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-proxy-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/CglibProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/CglibProxyFactory.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/CglibProxyFactory.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/cglib/src/main/java/org/apache/commons/proxy/cglib/CglibProxyFactory.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,187 @@
+package org.apache.commons.proxy.cglib;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Dispatcher;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+import org.apache.commons.proxy.Interceptor;
+import org.apache.commons.proxy.Invocation;
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.impl.AbstractSubclassingProxyFactory;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+public class CglibProxyFactory extends AbstractSubclassingProxyFactory
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ private static CallbackFilter callbackFilter = new CglibProxyFactoryCallbackFilter();
+
+//**********************************************************************************************************************
+// ProxyFactory Implementation
+//**********************************************************************************************************************
+
+ public Object createDelegatorProxy(ClassLoader classLoader, ObjectProvider targetProvider,
+ Class... proxyClasses)
+ {
+ final Enhancer enhancer = new Enhancer();
+ enhancer.setClassLoader(classLoader);
+ enhancer.setInterfaces(toInterfaces(proxyClasses));
+ enhancer.setSuperclass(getSuperclass(proxyClasses));
+ enhancer.setCallbackFilter(callbackFilter);
+ enhancer.setCallbacks(new Callback[]{new ObjectProviderDispatcher(targetProvider), new EqualsHandler(), new HashCodeHandler()});
+ return enhancer.create();
+ }
+
+ public Object createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
+ Class... proxyClasses)
+ {
+ final Enhancer enhancer = new Enhancer();
+ enhancer.setClassLoader(classLoader);
+ enhancer.setInterfaces(toInterfaces(proxyClasses));
+ enhancer.setSuperclass(getSuperclass(proxyClasses));
+ enhancer.setCallbackFilter(callbackFilter);
+ enhancer.setCallbacks(new Callback[]{new InterceptorBridge(target, interceptor), new EqualsHandler(), new HashCodeHandler()});
+ return enhancer.create();
+ }
+
+ public Object createInvokerProxy(ClassLoader classLoader, Invoker invoker,
+ Class... proxyClasses)
+ {
+ final Enhancer enhancer = new Enhancer();
+ enhancer.setClassLoader(classLoader);
+ enhancer.setInterfaces(toInterfaces(proxyClasses));
+ enhancer.setSuperclass(getSuperclass(proxyClasses));
+ enhancer.setCallbackFilter(callbackFilter);
+ enhancer.setCallbacks(new Callback[]{new InvokerBridge(invoker), new EqualsHandler(), new HashCodeHandler()});
+ return enhancer.create();
+ }
+
+//**********************************************************************************************************************
+// Inner Classes
+//**********************************************************************************************************************
+
+ private static class CglibProxyFactoryCallbackFilter implements CallbackFilter
+ {
+ public int accept(Method method)
+ {
+ if (isEqualsMethod(method))
+ {
+ return 1;
+ }
+ else if (isHashCode(method))
+ {
+ return 2;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+
+ private static class EqualsHandler implements MethodInterceptor, Serializable
+ {
+ public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable
+ {
+ return o == objects[0];
+ }
+ }
+
+ private static class HashCodeHandler implements MethodInterceptor, Serializable
+ {
+ public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable
+ {
+ return System.identityHashCode(o);
+ }
+ }
+
+ private static class InterceptorBridge implements net.sf.cglib.proxy.MethodInterceptor, Serializable
+ {
+ private final Interceptor inner;
+ private final Object target;
+
+ public InterceptorBridge(Object target, Interceptor inner)
+ {
+ this.inner = inner;
+ this.target = target;
+ }
+
+ public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable
+ {
+ return inner.intercept(new MethodProxyInvocation(target, method, args, methodProxy));
+ }
+ }
+
+ private static class InvokerBridge implements net.sf.cglib.proxy.InvocationHandler, Serializable
+ {
+ private final Invoker original;
+
+ public InvokerBridge(Invoker original)
+ {
+ this.original = original;
+ }
+
+ public Object invoke(Object object, Method method, Object[] objects) throws Throwable
+ {
+ return original.invoke(object, method, objects);
+ }
+ }
+
+ private static class MethodProxyInvocation implements Invocation, Serializable
+ {
+ private final MethodProxy methodProxy;
+ private final Method method;
+ private final Object[] args;
+ private final Object target;
+
+ public MethodProxyInvocation(Object target, Method method, Object[] args, MethodProxy methodProxy)
+ {
+ this.target = target;
+ this.method = method;
+ this.methodProxy = methodProxy;
+ this.args = args;
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Object[] getArguments()
+ {
+ return args;
+ }
+
+ public Object proceed() throws Throwable
+ {
+ return methodProxy.invoke(target, args);
+ }
+
+ public Object getProxy()
+ {
+ return target;
+ }
+ }
+
+ private static class ObjectProviderDispatcher implements Dispatcher, Serializable
+ {
+ private final ObjectProvider delegateProvider;
+
+ public ObjectProviderDispatcher(ObjectProvider delegateProvider)
+ {
+ this.delegateProvider = delegateProvider;
+ }
+
+ public Object loadObject()
+ {
+ return delegateProvider.getObject();
+ }
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/TestCglibProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/TestCglibProxyFactory.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/TestCglibProxyFactory.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/cglib/src/test/java/org/apache/commons/proxy/cglib/TestCglibProxyFactory.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,15 @@
+package org.apache.commons.proxy.cglib;
+
+import org.apache.commons.proxy.AbstractSubclassingProxyFactoryTestCase;
+
+public class TestCglibProxyFactory extends AbstractSubclassingProxyFactoryTestCase
+{
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public TestCglibProxyFactory()
+ {
+ super(new CglibProxyFactory());
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/pom.xml?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/pom.xml (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/pom.xml Thu Jul 15 23:10:43 2010
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>commons-proxy</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>commons-proxy-core</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>axis</groupId>
+ <artifactId>axis-jaxrpc</artifactId>
+ <version>1.2.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>hessian</groupId>
+ <artifactId>hessian</artifactId>
+ <version>3.0.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>burlap</groupId>
+ <artifactId>burlap</artifactId>
+ <version>2.1.7</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>xmlrpc</groupId>
+ <artifactId>xmlrpc</artifactId>
+ <version>2.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>1.0.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Interceptor.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Interceptor.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Interceptor.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Interceptor.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import java.io.Serializable;
+
+/**
+ * "Intercepts" a method invocation.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public interface Interceptor extends Serializable
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ public Object intercept( Invocation invocation ) throws Throwable;
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invocation.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invocation.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invocation.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invocation.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import java.lang.reflect.Method;
+
+/**
+ * Represents a method invocation.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public interface Invocation
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ /**
+ * Returns the arguments being passed to this method invocation. Changes in the elements of this array will be
+ * propagated to the recipient of this invocation.
+ *
+ * @return the arguments being passed to this method invocation
+ */
+ public Object[] getArguments();
+
+ /**
+ * Returns the method being called.
+ *
+ * @return the method being called
+ */
+ public Method getMethod();
+
+ /**
+ * Returns the proxy object on which this invocation was invoked.
+ *
+ * @return the proxy object on which this invocation was invoked
+ */
+ public Object getProxy();
+
+ /**
+ * Called in order to let the invocation proceed.
+ *
+ * @return the return value of the invocation
+ * @throws Throwable any exception or error that was thrown as a result of this invocation
+ */
+ public Object proceed() throws Throwable;
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invoker.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invoker.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invoker.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/Invoker.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+/**
+ * An invoker is responsible for handling a method invocation.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public interface Invoker extends Serializable
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ /**
+ * "Invokes" the method. Implementation should throw a {@link org.apache.commons.proxy.exception.InvokerException}
+ * if problems arise while trying to invoke the method.
+ *
+ * @param proxy the proxy object
+ * @param method the method being invoked
+ * @param arguments the arguments
+ * @return the return value
+ * @throws Throwable thrown by the implementation
+ */
+ public Object invoke( Object proxy, Method method, Object[] arguments ) throws Throwable;
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ObjectProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ObjectProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ObjectProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ObjectProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+/**
+ * Provides an object to a delegating proxy.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public interface ObjectProvider<T>
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ /**
+ * Returns an object. Implementing classes should throw a
+ * {@link org.apache.commons.proxy.exception.ObjectProviderException} if any problems arise while
+ * constructing/finding the object.
+ *
+ * @return the object on which the method should be called
+ */
+ public T getObject();
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,161 @@
+package org.apache.commons.proxy;
+
+public interface ProxyFactory
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param delegateProvider the delegate provider
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target <code>delegateProvider>
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createDelegatorProxy( ClassLoader classLoader, ObjectProvider<T> delegateProvider,
+ Class<T> proxyClass );
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInterceptorProxy( Object target, Interceptor interceptor,
+ Class<T> proxyClass );
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClass the class/interface that the proxy should implement.
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInterceptorProxy( ClassLoader classLoader,
+ Object target,
+ Interceptor interceptor,
+ Class<T> proxyClass );
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param invoker the invoker
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInvokerProxy( Invoker invoker, Class<T> proxyClass );
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param invoker the invoker
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInvokerProxy( ClassLoader classLoader, Invoker invoker,
+ Class<T> proxyClass );
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param delegateProvider the delegate provider
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target object provider
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T createDelegatorProxy( ObjectProvider<T> delegateProvider, Class<T> proxyClass );
+ /**
+ * Returns true if all <code>proxyClasses</code> are interfaces.
+ *
+ * @param proxyClasses the proxy classes
+ * @return true if all <code>proxyClasses</code> are interfaces
+ */
+ public boolean canProxy( Class... proxyClasses );
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param delegateProvider the delegate provider
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target object provider
+ */
+ public Object createDelegatorProxy( ObjectProvider delegateProvider, Class... proxyClasses );
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param delegateProvider the delegate provider
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target <code>delegateProvider>
+ */
+ public Object createDelegatorProxy( ClassLoader classLoader, ObjectProvider delegateProvider,
+ Class... proxyClasses );
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ public Object createInterceptorProxy( Object target, Interceptor interceptor,
+ Class... proxyClasses );
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClasses the interfaces that the proxy should implement.
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ public Object createInterceptorProxy( ClassLoader classLoader, Object target, Interceptor interceptor,
+ Class... proxyClasses );
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param invoker the invoker
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ public Object createInvokerProxy( Invoker invoker, Class... proxyClasses );
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param invoker the invoker
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ public Object createInvokerProxy( ClassLoader classLoader, Invoker invoker,
+ Class... proxyClasses );
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import org.apache.commons.proxy.invoker.NullInvoker;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Provides some helpful proxy utility methods.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ProxyUtils
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ public static final Object[] EMPTY_ARGUMENTS = new Object[0];
+ public static final Class[] EMPTY_ARGUMENT_TYPES = new Class[0];
+ private static final Map<Class, Class> wrapperClassMap = new HashMap<Class, Class>();
+ private static Map<Class, Object> nullValueMap = new HashMap<Class, Object>();
+
+//**********************************************************************************************************************
+// Static Methods
+//**********************************************************************************************************************
+
+ static
+ {
+ wrapperClassMap.put(Integer.TYPE, Integer.class);
+ wrapperClassMap.put(Character.TYPE, Character.class);
+ wrapperClassMap.put(Boolean.TYPE, Boolean.class);
+ wrapperClassMap.put(Short.TYPE, Short.class);
+ wrapperClassMap.put(Long.TYPE, Long.class);
+ wrapperClassMap.put(Float.TYPE, Float.class);
+ wrapperClassMap.put(Double.TYPE, Double.class);
+ wrapperClassMap.put(Byte.TYPE, Byte.class);
+ }
+
+ static
+ {
+ nullValueMap.put(Integer.TYPE, 0);
+ nullValueMap.put(Long.TYPE, (long) 0);
+ nullValueMap.put(Short.TYPE, (short) 0);
+ nullValueMap.put(Byte.TYPE, (byte) 0);
+ nullValueMap.put(Float.TYPE, 0.0f);
+ nullValueMap.put(Double.TYPE, 0.0);
+ nullValueMap.put(Character.TYPE, (char) 0);
+ nullValueMap.put(Boolean.TYPE, Boolean.FALSE);
+ }
+
+ /**
+ * Creates a "null object" which implements the <code>proxyClasses</code>.
+ *
+ * @param proxyFactory the proxy factory to be used to create the proxy object
+ * @param proxyClasses the proxy interfaces
+ * @return a "null object" which implements the <code>proxyClasses</code>.
+ */
+ public static Object createNullObject(ProxyFactory proxyFactory, Class[] proxyClasses)
+ {
+ return proxyFactory.createInvokerProxy(new NullInvoker(), proxyClasses);
+ }
+
+ /**
+ * Creates a "null object" which implements the <code>proxyClasses</code>.
+ *
+ * @param proxyFactory the proxy factory to be used to create the proxy object
+ * @param classLoader the class loader to be used by the proxy factory to create the proxy object
+ * @param proxyClasses the proxy interfaces
+ * @return a "null object" which implements the <code>proxyClasses</code>.
+ */
+ public static Object createNullObject(ProxyFactory proxyFactory, ClassLoader classLoader, Class[] proxyClasses)
+ {
+ return proxyFactory.createInvokerProxy(classLoader, new NullInvoker(), proxyClasses);
+ }
+
+ /**
+ * <p>Gets an array of {@link Class} objects representing all interfaces implemented by the given class and its
+ * superclasses.</p>
+ * <p/>
+ * <p>The order is determined by looking through each interface in turn as declared in the source file and following
+ * its hierarchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order
+ * is maintained.</p>
+ * <p/>
+ * <b>Note</b>: Implementation of this method was "borrowed" from
+ * <a href="http://commons.apache.org/lang/">Apache Commons Lang</a> to avoid a dependency.</p>
+ *
+ * @param cls the class to look up, may be <code>null</code>
+ * @return an array of {@link Class} objects representing all interfaces implemented by the given class and its
+ * superclasses or <code>null</code> if input class is null.
+ */
+ public static Class[] getAllInterfaces(Class cls)
+ {
+ final List interfaces = getAllInterfacesImpl(cls, new LinkedList());
+ return interfaces == null ? null : (Class[]) interfaces.toArray(new Class[interfaces.size()]);
+ }
+
+ private static List getAllInterfacesImpl(Class cls, List list)
+ {
+ if (cls == null)
+ {
+ return null;
+ }
+ while (cls != null)
+ {
+ Class[] interfaces = cls.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ if (!list.contains(interfaces[i]))
+ {
+ list.add(interfaces[i]);
+ }
+ getAllInterfacesImpl(interfaces[i], list);
+ }
+ cls = cls.getSuperclass();
+ }
+ return list;
+ }
+
+ /**
+ * Returns the class name as you would expect to see it in Java code.
+ * <p/>
+ * <b>Examples:</b> <ul> <li>getJavaClassName( Object[].class ) == "Object[]"</li> <li>getJavaClassName(
+ * Object[][].class ) == "Object[][]"</li> <li>getJavaClassName( Integer.TYPE ) == "int"</li> </p>
+ *
+ * @param clazz the class
+ * @return the class' name as you would expect to see it in Java code
+ */
+ public static String getJavaClassName(Class clazz)
+ {
+ if (clazz.isArray())
+ {
+ return getJavaClassName(clazz.getComponentType()) + "[]";
+ }
+ return clazz.getName();
+ }
+
+ /**
+ * Returns the wrapper class for the given primitive type.
+ *
+ * @param primitiveType the primitive type
+ * @return the wrapper class
+ */
+ public static Class getWrapperClass(Class primitiveType)
+ {
+ return wrapperClassMap.get(primitiveType);
+ }
+
+ /**
+ * Returns the proper "null value" as specified by the Java language.
+ *
+ * @param type the type
+ * @return the null value
+ */
+ public static <T> T nullValue(Class<T> type)
+ {
+ return (T) nullValueMap.get(type);
+ }
+
+ public static boolean isEqualsMethod(Method method)
+ {
+ return "equals".equals(method.getName()) &&
+ Boolean.TYPE.equals(method.getReturnType()) &&
+ method.getParameterTypes().length == 1 &&
+ Object.class.equals(method.getParameterTypes()[0]);
+ }
+
+ public static boolean isHashCode(Method method)
+ {
+ return "hashCode".equals(method.getName()) &&
+ Integer.TYPE.equals(method.getReturnType()) &&
+ method.getParameterTypes().length == 0;
+ }
+
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.exception;
+
+/**
+ * To be used by an {@link org.apache.commons.proxy.Invoker} when they encounter an error.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class InvokerException extends RuntimeException
+{
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public InvokerException()
+ {
+ }
+
+ public InvokerException( String message )
+ {
+ super(message);
+ }
+
+ public InvokerException( Throwable cause )
+ {
+ super(cause);
+ }
+
+ public InvokerException( String message, Throwable cause )
+ {
+ super(message, cause);
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.exception;
+
+/**
+ * {@link org.apache.commons.proxy.ObjectProvider} implementations should throw this exception type to indicate that
+ * there was a problem creating/finding the object.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ObjectProviderException extends RuntimeException
+{
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public ObjectProviderException()
+ {
+ }
+
+ public ObjectProviderException( String message )
+ {
+ super(message);
+ }
+
+ public ObjectProviderException( Throwable cause )
+ {
+ super(cause);
+ }
+
+ public ObjectProviderException( String message, Throwable cause )
+ {
+ super(message, cause);
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.exception;
+
+/**
+ * A runtime exception type to be used by {@link org.apache.commons.proxy.ProxyFactory proxy factories} when a problem
+ * occurs.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ProxyFactoryException extends RuntimeException
+{
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public ProxyFactoryException()
+ {
+ }
+
+ public ProxyFactoryException( String message )
+ {
+ super(message);
+ }
+
+ public ProxyFactoryException( Throwable cause )
+ {
+ super(cause);
+ }
+
+ public ProxyFactoryException( String message, Throwable cause )
+ {
+ super(message, cause);
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A useful superclass for {@link ProxyClassGenerator} implementations.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public abstract class AbstractProxyClassGenerator implements ProxyClassGenerator
+{
+//**********************************************************************************************************************
+// Static Methods
+//**********************************************************************************************************************
+
+ /**
+ * Returns all methods that a proxy class must implement from the proxy interfaces. This method makes sure there
+ * are no method signature clashes. For methods with the same signature (name and parameter types), the one
+ * encountered first will be returned in the result. Final methods are also excluded from the result.
+ *
+ * @param proxyClasses the interfaces the proxy class must implement
+ * @return all methods that the proxy class must implement
+ */
+ public static Method[] getImplementationMethods( Class[] proxyClasses )
+ {
+ final Map signatureMethodMap = new HashMap();
+ final Set finalizedSignatures = new HashSet();
+ for( int i = 0; i < proxyClasses.length; i++ )
+ {
+ Class proxyInterface = proxyClasses[i];
+ final Method[] methods = proxyInterface.getMethods();
+ for( int j = 0; j < methods.length; j++ )
+ {
+ final MethodSignature signature = new MethodSignature(methods[j]);
+ if( Modifier.isFinal(methods[j].getModifiers()) )
+ {
+ finalizedSignatures.add(signature);
+ }
+ else if( !signatureMethodMap.containsKey(signature) )
+ {
+ signatureMethodMap.put(signature, methods[j]);
+ }
+ }
+ }
+ final Collection resultingMethods = signatureMethodMap.values();
+ for( Iterator i = finalizedSignatures.iterator(); i.hasNext(); )
+ {
+ MethodSignature signature = ( MethodSignature ) i.next();
+ resultingMethods.remove(signatureMethodMap.get(signature));
+ }
+ return ( Method[] ) resultingMethods.toArray(new Method[resultingMethods.size()]);
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,310 @@
+package org.apache.commons.proxy.impl;
+
+import org.apache.commons.proxy.Interceptor;
+import org.apache.commons.proxy.Invocation;
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.ProxyFactory;
+import org.apache.commons.proxy.ProxyUtils;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public abstract class AbstractProxyFactory implements ProxyFactory
+{
+ /**
+ * Returns true if all <code>proxyClasses</code> are interfaces.
+ *
+ * @param proxyClasses the proxy classes
+ * @return true if all <code>proxyClasses</code> are interfaces
+ */
+ public boolean canProxy( Class... proxyClasses )
+ {
+ for( Class proxyClass : proxyClasses )
+ {
+ if( !proxyClass.isInterface() )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param delegateProvider the delegate provider
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target object provider
+ */
+ public Object createDelegatorProxy( ObjectProvider delegateProvider, Class... proxyClasses )
+ {
+ return createDelegatorProxy(Thread.currentThread().getContextClassLoader(), delegateProvider, proxyClasses);
+ }
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param delegateProvider the delegate provider
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target object provider
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T createDelegatorProxy( ObjectProvider<T> delegateProvider, Class<T> proxyClass )
+ {
+ return (T)createDelegatorProxy(delegateProvider, new Class[] {proxyClass});
+ }
+
+ /**
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param delegateProvider the delegate provider
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which delegates to the object provided by the target <code>delegateProvider>
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createDelegatorProxy( ClassLoader classLoader, ObjectProvider<T> delegateProvider,
+ Class<T> proxyClass )
+ {
+ return ( T ) createDelegatorProxy(classLoader, delegateProvider, new Class[] {proxyClass});
+ }
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ public Object createInterceptorProxy( Object target, Interceptor interceptor,
+ Class... proxyClasses )
+ {
+ return createInterceptorProxy(Thread.currentThread().getContextClassLoader(), target, interceptor,
+ proxyClasses);
+ }
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInterceptorProxy( Object target, Interceptor interceptor,
+ Class<T> proxyClass )
+ {
+ return ( T ) createInterceptorProxy(target, interceptor, new Class[] {proxyClass});
+ }
+
+ /**
+ * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param target the target object
+ * @param interceptor the method interceptor
+ * @param proxyClass the class/interface that the proxy should implement.
+ * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
+ * <code>target</code> object.
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInterceptorProxy( ClassLoader classLoader,
+ Object target,
+ Interceptor interceptor,
+ Class<T> proxyClass )
+ {
+ return ( T ) createInterceptorProxy(classLoader, target, interceptor, new Class[] {proxyClass});
+ }
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param invoker the invoker
+ * @param proxyClasses the interfaces that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ public Object createInvokerProxy( Invoker invoker, Class... proxyClasses )
+ {
+ return createInvokerProxy(Thread.currentThread().getContextClassLoader(), invoker,
+ proxyClasses);
+ }
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * generated using the current thread's "context class loader."
+ *
+ * @param invoker the invoker
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInvokerProxy( Invoker invoker, Class<T> proxyClass )
+ {
+ return ( T ) createInvokerProxy(invoker, new Class[] {proxyClass});
+ }
+
+ /**
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations.
+ *
+ * @param classLoader the class loader to use when generating the proxy
+ * @param invoker the invoker
+ * @param proxyClass the class/interface that the proxy should implement
+ * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
+ */
+ @SuppressWarnings( "unchecked" )
+ public <T> T createInvokerProxy( ClassLoader classLoader, Invoker invoker,
+ Class<T> proxyClass )
+ {
+ return ( T ) createInvokerProxy(classLoader, invoker, new Class[] {proxyClass});
+ }
+
+//**********************************************************************************************************************
+// Inner Classes
+//**********************************************************************************************************************
+
+ private static class DelegatorInvocationHandler extends AbstractInvocationHandler
+ {
+ private final ObjectProvider delegateProvider;
+
+ protected DelegatorInvocationHandler( ObjectProvider delegateProvider )
+ {
+ this.delegateProvider = delegateProvider;
+ }
+
+ public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ {
+ try
+ {
+ return method.invoke(delegateProvider.getObject(), args);
+ }
+ catch( InvocationTargetException e )
+ {
+ throw e.getTargetException();
+ }
+ }
+ }
+
+ private static class InterceptorInvocationHandler extends AbstractInvocationHandler
+ {
+ private final Object target;
+ private final Interceptor methodInterceptor;
+
+ public InterceptorInvocationHandler( Object target, Interceptor methodInterceptor )
+ {
+ this.target = target;
+ this.methodInterceptor = methodInterceptor;
+ }
+
+ public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ {
+ final ReflectionInvocation invocation = new ReflectionInvocation(target, method, args);
+ return methodInterceptor.intercept(invocation);
+ }
+ }
+
+ private abstract static class AbstractInvocationHandler implements InvocationHandler, Serializable
+ {
+ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+ {
+ if( isHashCode(method) )
+ {
+ return System.identityHashCode(proxy);
+ }
+ else if( isEqualsMethod(method) )
+ {
+ return proxy == args[0];
+ }
+ else
+ {
+ return invokeImpl(proxy, method, args);
+ }
+ }
+
+ protected abstract Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable;
+ }
+
+ private static class InvokerInvocationHandler extends AbstractInvocationHandler
+ {
+ private final Invoker invoker;
+
+ public InvokerInvocationHandler( Invoker invoker )
+ {
+ this.invoker = invoker;
+ }
+
+ public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ {
+ return invoker.invoke(proxy, method, args);
+ }
+ }
+
+ protected static boolean isHashCode( Method method )
+ {
+ return "hashCode".equals(method.getName()) &&
+ Integer.TYPE.equals(method.getReturnType()) &&
+ method.getParameterTypes().length == 0;
+ }
+
+ protected static boolean isEqualsMethod( Method method )
+ {
+ return "equals".equals(method.getName()) &&
+ Boolean.TYPE.equals(method.getReturnType()) &&
+ method.getParameterTypes().length == 1 &&
+ Object.class.equals(method.getParameterTypes()[0]);
+ }
+
+ private static class ReflectionInvocation implements Invocation, Serializable
+ {
+ private final Method method;
+ private final Object[] arguments;
+ private final Object target;
+
+ public ReflectionInvocation( Object target, Method method, Object[] arguments )
+ {
+ this.method = method;
+ this.arguments = ( arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments );
+ this.target = target;
+ }
+
+ public Object[] getArguments()
+ {
+ return arguments;
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Object getProxy()
+ {
+ return target;
+ }
+
+ public Object proceed() throws Throwable
+ {
+ try
+ {
+ return method.invoke(target, arguments);
+ }
+ catch( InvocationTargetException e )
+ {
+ throw e.getTargetException();
+ }
+ }
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,144 @@
+package org.apache.commons.proxy.impl;
+
+import org.apache.commons.proxy.exception.ProxyFactoryException;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+public abstract class AbstractSubclassingProxyFactory extends AbstractProxyFactory
+{
+//**********************************************************************************************************************
+// ProxyFactory Implementation
+//**********************************************************************************************************************
+
+ /**
+ * Returns true if a suitable superclass can be found, given the desired <code>proxyClasses</code>.
+ *
+ * @param proxyClasses the proxy classes
+ * @return true if a suitable superclass can be found, given the desired <code>proxyClasses</code>
+ */
+ public boolean canProxy( Class... proxyClasses )
+ {
+ try
+ {
+ getSuperclass(proxyClasses);
+ return true;
+ }
+ catch( ProxyFactoryException e )
+ {
+ return false;
+ }
+ }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ private static boolean hasSuitableDefaultConstructor( Class superclass )
+ {
+ final Constructor[] declaredConstructors = superclass.getDeclaredConstructors();
+ for( int i = 0; i < declaredConstructors.length; i++ )
+ {
+ Constructor constructor = declaredConstructors[i];
+ if( constructor.getParameterTypes().length == 0 && ( Modifier.isPublic(constructor.getModifiers()) ||
+ Modifier.isProtected(constructor.getModifiers()) ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static Class[] toNonInterfaces( Class[] proxyClasses )
+ {
+ final List superclasses = new LinkedList();
+ for( int i = 0; i < proxyClasses.length; i++ )
+ {
+ Class proxyClass = proxyClasses[i];
+ if( !proxyClass.isInterface() )
+ {
+ superclasses.add(proxyClass);
+ }
+ }
+ return ( Class[] ) superclasses.toArray(new Class[superclasses.size()]);
+ }
+
+ /**
+ * 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
+ * not found!
+ *
+ * @param proxyClasses the proxy classes
+ * @return the <code>proxyClasses</code> transformed into an array of only the interface classes
+ */
+ protected static Class[] toInterfaces( Class[] proxyClasses )
+ {
+ final Collection interfaces = new LinkedList();
+ boolean serializableFound = false;
+ for( int i = 0; i < proxyClasses.length; i++ )
+ {
+ Class proxyInterface = proxyClasses[i];
+ if( proxyInterface.isInterface() )
+ {
+ interfaces.add(proxyInterface);
+ }
+ serializableFound |= ( Serializable.class.equals(proxyInterface) );
+ }
+ if( !serializableFound )
+ {
+ interfaces.add(Serializable.class);
+ }
+ return ( Class[] ) interfaces.toArray(new Class[interfaces.size()]);
+ }
+
+ /**
+ * Returns either {@link Object} if all of the <code>proxyClasses</code> are interfaces or the single non-interface
+ * class from <code>proxyClasses</code>.
+ *
+ * @param proxyClasses the proxy classes
+ * @return either {@link Object} if all of the <code>proxyClasses</code> are interfaces or the single non-interface
+ * class from <code>proxyClasses</code>
+ * @throws ProxyFactoryException if multiple non-interface classes are contained in <code>proxyClasses</code> or any
+ * of the non-interface classes are final
+ */
+ public static Class getSuperclass( Class[] proxyClasses )
+ {
+ final Class[] superclasses = toNonInterfaces(proxyClasses);
+ switch( superclasses.length )
+ {
+ case 0:
+ return Object.class;
+ case 1:
+ final Class superclass = superclasses[0];
+ if( Modifier.isFinal(superclass.getModifiers()) )
+ {
+ throw new ProxyFactoryException(
+ "Proxy class cannot extend " + superclass.getName() + " as it is final.");
+ }
+ if( !hasSuitableDefaultConstructor(superclass) )
+ {
+ throw new ProxyFactoryException("Proxy class cannot extend " + superclass.getName() +
+ ", because it has no visible \"default\" constructor.");
+ }
+ return superclass;
+ default:
+ final StringBuffer errorMessage = new StringBuffer("Proxy class cannot extend ");
+ for( int i = 0; i < superclasses.length; i++ )
+ {
+ Class c = superclasses[i];
+ errorMessage.append(c.getName());
+ if( i != superclasses.length - 1 )
+ {
+ errorMessage.append(", ");
+ }
+ }
+ errorMessage.append("; multiple inheritance not allowed.");
+ throw new ProxyFactoryException(errorMessage.toString());
+ }
+ }
+}
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.impl;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A class for capturing the signature of a method (its name and parameter types).
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class MethodSignature
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ private final String name;
+ private final List parameterTypes;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public MethodSignature( Method method )
+ {
+ this.name = method.getName();
+ this.parameterTypes = Arrays.asList(method.getParameterTypes());
+ }
+
+//**********************************************************************************************************************
+// Canonical Methods
+//**********************************************************************************************************************
+
+ public boolean equals( Object o )
+ {
+ if( this == o )
+ {
+ return true;
+ }
+ if( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+ final MethodSignature that = ( MethodSignature ) o;
+ if( !name.equals(that.name) )
+ {
+ return false;
+ }
+ if( !parameterTypes.equals(that.parameterTypes) )
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = name.hashCode();
+ result = 29 * result + parameterTypes.hashCode();
+ return result;
+ }
+}