Author: mbenson Date: Fri Jul 16 23:04:32 2010 New Revision: 964972 URL: http://svn.apache.org/viewvc?rev=964972&view=rev Log: generics/serialization warnings, javadoc, and the occasional minor code change
Modified: 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/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/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/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/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/test/java/org/apache/commons/proxy/util/AbstractTestCase.java commons/proper/proxy/branches/version-2.0-work/pom.xml Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java Fri Jul 16 23:04:32 2010 @@ -97,11 +97,12 @@ public interface ProxyFactory * @return a proxy which delegates to the object provided by the target object provider */ public <T> T createDelegatorProxy( ObjectProvider<T> delegateProvider, Class<T> proxyClass ); + /** - * Returns true if all <code>proxyClasses</code> are interfaces. + * Learn whether this {...@link ProxyFactory} is capable of creating a proxy for the specified set of classes. * * @param proxyClasses the proxy classes - * @return true if all <code>proxyClasses</code> are interfaces + * @return boolean */ public boolean canProxy( Class<?>... proxyClasses ); Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java Fri Jul 16 23:04:32 2010 @@ -38,9 +38,9 @@ public class ProxyUtils //********************************************************************************************************************** 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>(); + 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 @@ -77,7 +77,7 @@ public class ProxyUtils * @param proxyClasses the proxy interfaces * @return a "null object" which implements the <code>proxyClasses</code>. */ - public static Object createNullObject(ProxyFactory proxyFactory, Class[] proxyClasses) + public static Object createNullObject(ProxyFactory proxyFactory, Class<?>[] proxyClasses) { return proxyFactory.createInvokerProxy(new NullInvoker(), proxyClasses); } @@ -90,7 +90,7 @@ public class ProxyUtils * @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) + public static Object createNullObject(ProxyFactory proxyFactory, ClassLoader classLoader, Class<?>[] proxyClasses) { return proxyFactory.createInvokerProxy(classLoader, new NullInvoker(), proxyClasses); } @@ -110,13 +110,13 @@ public class ProxyUtils * @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) + public static Class<?>[] getAllInterfaces(Class<?> cls) { - final List interfaces = getAllInterfacesImpl(cls, new LinkedList()); + final List<Class<?>> interfaces = getAllInterfacesImpl(cls, new LinkedList<Class<?>>()); return interfaces == null ? null : (Class[]) interfaces.toArray(new Class[interfaces.size()]); } - private static List getAllInterfacesImpl(Class cls, List list) + private static List<Class<?>> getAllInterfacesImpl(Class<?> cls, List<Class<?>> list) { if (cls == null) { @@ -124,7 +124,7 @@ public class ProxyUtils } while (cls != null) { - Class[] interfaces = cls.getInterfaces(); + Class<?>[] interfaces = cls.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (!list.contains(interfaces[i])) @@ -147,7 +147,7 @@ public class ProxyUtils * @param clazz the class * @return the class' name as you would expect to see it in Java code */ - public static String getJavaClassName(Class clazz) + public static String getJavaClassName(Class<?> clazz) { if (clazz.isArray()) { @@ -162,7 +162,7 @@ public class ProxyUtils * @param primitiveType the primitive type * @return the wrapper class */ - public static Class getWrapperClass(Class primitiveType) + public static Class<?> getWrapperClass(Class<?> primitiveType) { return wrapperClassMap.get(primitiveType); } @@ -173,11 +173,17 @@ public class ProxyUtils * @param type the type * @return the null value */ + @SuppressWarnings("unchecked") public static <T> T nullValue(Class<T> type) { return (T) nullValueMap.get(type); } + /** + * Learn whether the specified method is/overrides {...@link Object#equals(Object)}. + * @param method to compare + * @return <code>true</code> for a method with signature <code>boolean equals(Object)</code> + */ public static boolean isEqualsMethod(Method method) { return "equals".equals(method.getName()) && @@ -186,6 +192,11 @@ public class ProxyUtils Object.class.equals(method.getParameterTypes()[0]); } + /** + * Learn whether the specified method is/overrides {...@link Object#hashCode()}. + * @param method to compare + * @return true for a method with signature <code>int hashCode()</code> + */ public static boolean isHashCode(Method method) { return "hashCode".equals(method.getName()) && Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java Fri Jul 16 23:04:32 2010 @@ -25,24 +25,43 @@ package org.apache.commons.proxy.excepti */ public class InvokerException extends RuntimeException { -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + /** Serialization version */ + private static final long serialVersionUID = -1L; + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new InvokerException instance. + */ public InvokerException() { } + /** + * Create a new InvokerException instance. + * @param message + */ public InvokerException( String message ) { super(message); } + /** + * Create a new InvokerException instance. + * @param cause + */ public InvokerException( Throwable cause ) { super(cause); } + /** + * Create a new InvokerException instance. + * @param message + * @param cause + */ public InvokerException( String message, Throwable cause ) { super(message, cause); Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java Fri Jul 16 23:04:32 2010 @@ -26,24 +26,43 @@ package org.apache.commons.proxy.excepti */ public class ObjectProviderException extends RuntimeException { -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + /** Serialization version */ + private static final long serialVersionUID = -1L; + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new ObjectProviderException instance. + */ public ObjectProviderException() { } + /** + * Create a new ObjectProviderException instance. + * @param message + */ public ObjectProviderException( String message ) { super(message); } + /** + * Create a new ObjectProviderException instance. + * @param cause + */ public ObjectProviderException( Throwable cause ) { super(cause); } + /** + * Create a new ObjectProviderException instance. + * @param message + * @param cause + */ public ObjectProviderException( String message, Throwable cause ) { super(message, cause); Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java Fri Jul 16 23:04:32 2010 @@ -26,24 +26,43 @@ package org.apache.commons.proxy.excepti */ public class ProxyFactoryException extends RuntimeException { -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + /** Serialization version */ + private static final long serialVersionUID = -1L; + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new ProxyFactoryException instance. + */ public ProxyFactoryException() { } + /** + * Create a new ProxyFactoryException instance. + * @param message + */ public ProxyFactoryException( String message ) { super(message); } + /** + * Create a new ProxyFactoryException instance. + * @param cause + */ public ProxyFactoryException( Throwable cause ) { super(cause); } + /** + * Create a new ProxyFactoryException instance. + * @param message + * @param cause + */ public ProxyFactoryException( String message, Throwable cause ) { super(message, cause); Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java Fri Jul 16 23:04:32 2010 @@ -22,7 +22,6 @@ 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; @@ -46,13 +45,13 @@ public abstract class AbstractProxyClass * @param proxyClasses the interfaces the proxy class must implement * @return all methods that the proxy class must implement */ - public static Method[] getImplementationMethods( Class[] proxyClasses ) + public static Method[] getImplementationMethods( Class<?>[] proxyClasses ) { - final Map signatureMethodMap = new HashMap(); - final Set finalizedSignatures = new HashSet(); + final Map<MethodSignature, Method> signatureMethodMap = new HashMap<MethodSignature, Method>(); + final Set<MethodSignature> finalizedSignatures = new HashSet<MethodSignature>(); for( int i = 0; i < proxyClasses.length; i++ ) { - Class proxyInterface = proxyClasses[i]; + Class<?> proxyInterface = proxyClasses[i]; final Method[] methods = proxyInterface.getMethods(); for( int j = 0; j < methods.length; j++ ) { @@ -67,12 +66,10 @@ public abstract class AbstractProxyClass } } } - final Collection resultingMethods = signatureMethodMap.values(); - for( Iterator i = finalizedSignatures.iterator(); i.hasNext(); ) - { - MethodSignature signature = ( MethodSignature ) i.next(); + final Collection<Method> resultingMethods = signatureMethodMap.values(); + for (MethodSignature signature : finalizedSignatures) { resultingMethods.remove(signatureMethodMap.get(signature)); } - return ( Method[] ) resultingMethods.toArray(new Method[resultingMethods.size()]); + return resultingMethods.toArray(new Method[resultingMethods.size()]); } } Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java Fri Jul 16 23:04:32 2010 @@ -18,18 +18,15 @@ 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; +/** + * Base abstract {...@link ProxyFactory} implementation, primarily providing + * implementations of the interface methods that are typically convenience + * constructs over the other methods. + */ public abstract class AbstractProxyFactory implements ProxyFactory { /** @@ -38,9 +35,9 @@ public abstract class AbstractProxyFacto * @param proxyClasses the proxy classes * @return true if all <code>proxyClasses</code> are interfaces */ - public boolean canProxy( Class... proxyClasses ) + public boolean canProxy( Class<?>... proxyClasses ) { - for( Class proxyClass : proxyClasses ) + for( Class<?> proxyClass : proxyClasses ) { if( !proxyClass.isInterface() ) { @@ -58,7 +55,7 @@ public abstract class AbstractProxyFacto * @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 ) + public Object createDelegatorProxy( ObjectProvider<?> delegateProvider, Class<?>... proxyClasses ) { return createDelegatorProxy(Thread.currentThread().getContextClassLoader(), delegateProvider, proxyClasses); } @@ -103,7 +100,7 @@ public abstract class AbstractProxyFacto * <code>target</code> object. */ public Object createInterceptorProxy( Object target, Interceptor interceptor, - Class... proxyClasses ) + Class<?>... proxyClasses ) { return createInterceptorProxy(Thread.currentThread().getContextClassLoader(), target, interceptor, proxyClasses); @@ -154,7 +151,7 @@ public abstract class AbstractProxyFacto * @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 ) + public Object createInvokerProxy( Invoker invoker, Class<?>... proxyClasses ) { return createInvokerProxy(Thread.currentThread().getContextClassLoader(), invoker, proxyClasses); @@ -189,139 +186,4 @@ public abstract class AbstractProxyFacto 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(); - } - } - } } Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java Fri Jul 16 23:04:32 2010 @@ -5,10 +5,13 @@ import org.apache.commons.proxy.exceptio 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; +import java.util.LinkedHashSet; +import java.util.Set; +/** + * Parent {...@link AbstractProxyFactory} for implementations that permit the generation of + * proxies with a specific inheritance hierarchy. + */ public abstract class AbstractSubclassingProxyFactory extends AbstractProxyFactory { //********************************************************************************************************************** @@ -21,7 +24,7 @@ public abstract class AbstractSubclassin * @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 ) + public boolean canProxy( Class<?>... proxyClasses ) { try { @@ -38,12 +41,12 @@ public abstract class AbstractSubclassin // Other Methods //********************************************************************************************************************** - private static boolean hasSuitableDefaultConstructor( Class superclass ) + private static boolean hasSuitableDefaultConstructor( Class<?> superclass ) { - final Constructor[] declaredConstructors = superclass.getDeclaredConstructors(); + final Constructor<?>[] declaredConstructors = superclass.getDeclaredConstructors(); for( int i = 0; i < declaredConstructors.length; i++ ) { - Constructor constructor = declaredConstructors[i]; + Constructor<?> constructor = declaredConstructors[i]; if( constructor.getParameterTypes().length == 0 && ( Modifier.isPublic(constructor.getModifiers()) || Modifier.isProtected(constructor.getModifiers()) ) ) { @@ -53,18 +56,17 @@ public abstract class AbstractSubclassin return false; } - private static Class[] toNonInterfaces( Class[] proxyClasses ) + private static Class<?>[] toNonInterfaces( Class<?>[] proxyClasses ) { - final List superclasses = new LinkedList(); - for( int i = 0; i < proxyClasses.length; i++ ) + final Set<Class<?>> superclasses = new LinkedHashSet<Class<?>>(); + for (Class<?> proxyClass : proxyClasses) { - Class proxyClass = proxyClasses[i]; - if( !proxyClass.isInterface() ) + if( !proxyClass.isInterface()) { superclasses.add(proxyClass); } } - return ( Class[] ) superclasses.toArray(new Class[superclasses.size()]); + return superclasses.toArray(new Class[superclasses.size()]); } /** @@ -76,18 +78,17 @@ public abstract class AbstractSubclassin * @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 ) + protected static Class<?>[] toInterfaces( Class<?>[] proxyClasses ) { - final Collection interfaces = new LinkedList(); + final Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); boolean serializableFound = false; - for( int i = 0; i < proxyClasses.length; i++ ) + for (Class<?> proxyClass : proxyClasses) { - Class proxyInterface = proxyClasses[i]; - if( proxyInterface.isInterface() ) + if( proxyClass.isInterface() ) { - interfaces.add(proxyInterface); + interfaces.add(proxyClass); } - serializableFound |= ( Serializable.class.equals(proxyInterface) ); + serializableFound |= ( Serializable.class.equals(proxyClass) ); } if( !serializableFound ) { @@ -106,15 +107,15 @@ public abstract class AbstractSubclassin * @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 ) + public static Class<?> getSuperclass( Class<?>[] proxyClasses ) { - final Class[] superclasses = toNonInterfaces(proxyClasses); + final Class<?>[] superclasses = toNonInterfaces(proxyClasses); switch( superclasses.length ) { case 0: return Object.class; case 1: - final Class superclass = superclasses[0]; + final Class<?> superclass = superclasses[0]; if( Modifier.isFinal(superclass.getModifiers()) ) { throw new ProxyFactoryException( @@ -130,7 +131,7 @@ public abstract class AbstractSubclassin final StringBuffer errorMessage = new StringBuffer("Proxy class cannot extend "); for( int i = 0; i < superclasses.length; i++ ) { - Class c = superclasses[i]; + Class<?> c = superclasses[i]; errorMessage.append(c.getName()); if( i != superclasses.length - 1 ) { Modified: 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=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java Fri Jul 16 23:04:32 2010 @@ -34,22 +34,29 @@ public class MethodSignature //********************************************************************************************************************** private final String name; - private final List parameterTypes; - -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + private final List<Class<?>> parameterTypes; + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new MethodSignature instance. + * @param method + */ public MethodSignature( Method method ) { this.name = method.getName(); this.parameterTypes = Arrays.asList(method.getParameterTypes()); } -//********************************************************************************************************************** -// Canonical Methods -//********************************************************************************************************************** - + //********************************************************************************************************************** + // Canonical Methods + //********************************************************************************************************************** + + /** + * {...@inheritdoc} + */ public boolean equals( Object o ) { if( this == o ) @@ -72,6 +79,9 @@ public class MethodSignature return true; } + /** + * {...@inheritdoc} + */ public int hashCode() { int result; Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java Fri Jul 16 23:04:32 2010 @@ -17,9 +17,13 @@ package org.apache.commons.proxy.impl; +import java.lang.ref.Reference; import java.lang.ref.WeakReference; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; /** @@ -32,17 +36,23 @@ import java.util.WeakHashMap; */ public class ProxyClassCache { + //********************************************************************************************************************** // Fields //********************************************************************************************************************** - private final Map loaderToClassCache = new WeakHashMap(); + private final Map<ClassLoader, Map<Set<Class<?>>, WeakReference<Class<?>>>> loaderToClassCache + = new WeakHashMap<ClassLoader, Map<Set<Class<?>>, WeakReference<Class<?>>>>(); private final ProxyClassGenerator proxyClassGenerator; -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + /** + * Create a new ProxyClassCache instance. + * @param proxyClassGenerator + */ public ProxyClassCache( ProxyClassGenerator proxyClassGenerator ) { this.proxyClassGenerator = proxyClassGenerator; @@ -52,30 +62,20 @@ public class ProxyClassCache // Other Methods //********************************************************************************************************************** - private Map getClassCache( ClassLoader classLoader ) + private Map<Set<Class<?>>, WeakReference<Class<?>>> getClassCache( ClassLoader classLoader ) { - Map cache = ( Map ) loaderToClassCache.get(classLoader); + Map<Set<Class<?>>, WeakReference<Class<?>>> cache = loaderToClassCache.get(classLoader); if( cache == null ) { - cache = new HashMap(); + cache = new HashMap<Set<Class<?>>, WeakReference<Class<?>>>(); loaderToClassCache.put(classLoader, cache); } return cache; } - private String toClassCacheKey( Class[] proxyClasses ) + private Set<Class<?>> toClassCacheKey( Class<?>[] proxyClasses ) { - final StringBuffer sb = new StringBuffer(); - for( int i = 0; i < proxyClasses.length; i++ ) - { - Class proxyInterface = proxyClasses[i]; - sb.append(proxyInterface.getName()); - if( i != proxyClasses.length - 1 ) - { - sb.append(","); - } - } - return sb.toString(); + return new HashSet<Class<?>>(Arrays.asList(proxyClasses)); } /** @@ -87,26 +87,26 @@ public class ProxyClassCache * @return the proxy class generated by the {...@link ProxyClassGenerator} using the specified {...@link ClassLoader} and * array of proxy classes */ - public synchronized Class getProxyClass( ClassLoader classLoader, Class[] proxyClasses ) + public synchronized Class<?> getProxyClass( ClassLoader classLoader, Class<?>[] proxyClasses ) { - final Map classCache = getClassCache(classLoader); - final String key = toClassCacheKey(proxyClasses); - Class proxyClass; - WeakReference proxyClassReference = ( WeakReference ) classCache.get(key); + final Map<Set<Class<?>>, WeakReference<Class<?>>> classCache = getClassCache(classLoader); + final Set<Class<?>> key = toClassCacheKey(proxyClasses); + Class<?> proxyClass; + Reference<Class<?>> proxyClassReference = classCache.get(key); if( proxyClassReference == null ) { proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses); - classCache.put(key, new WeakReference(proxyClass)); + classCache.put(key, new WeakReference<Class<?>>(proxyClass)); } else { synchronized( proxyClassReference ) { - proxyClass = ( Class ) proxyClassReference.get(); + proxyClass = proxyClassReference.get(); if( proxyClass == null ) { proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses); - classCache.put(key, new WeakReference(proxyClass)); + classCache.put(key, new WeakReference<Class<?>>(proxyClass)); } } } Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java Fri Jul 16 23:04:32 2010 @@ -36,5 +36,5 @@ public interface ProxyClassGenerator * @param proxyClasses the proxy classes * @return the dynamically generated proxy class */ - public Class generateProxyClass( ClassLoader classLoader, Class[] proxyClasses ); + public Class<?> generateProxyClass( ClassLoader classLoader, Class<?>[] proxyClasses ); } Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java Fri Jul 16 23:04:32 2010 @@ -52,29 +52,39 @@ import java.lang.reflect.Method; */ public class DuckTypingInvoker implements Invoker { + /** Serialization version */ + private static final long serialVersionUID = 1L; + //********************************************************************************************************************** // Fields //********************************************************************************************************************** - private final ObjectProvider targetProvider; + private final ObjectProvider<?> targetProvider; -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** - public DuckTypingInvoker( final ObjectProvider targetProvider ) + /** + * Create a new DuckTypingInvoker instance. + * @param targetProvider + */ + public DuckTypingInvoker( final ObjectProvider<?> targetProvider ) { this.targetProvider = targetProvider; } -//********************************************************************************************************************** -// Invoker Implementation -//********************************************************************************************************************** + //********************************************************************************************************************** + // Invoker Implementation + //********************************************************************************************************************** + /** + * {...@inheritdoc} + */ public Object invoke( final Object proxy, final Method method, final Object[] arguments ) throws Throwable { final Object target = targetProvider.getObject(); - final Class targetClass = target.getClass(); + final Class<?> targetClass = target.getClass(); try { final Method targetMethod = targetClass.getMethod(method.getName(), method.getParameterTypes()); Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java Fri Jul 16 23:04:32 2010 @@ -31,26 +31,35 @@ import java.lang.reflect.Method; */ public class InvocationHandlerAdapter implements Invoker { + /** Serialization version */ + private static final long serialVersionUID = 1L; + //********************************************************************************************************************** // Fields //********************************************************************************************************************** private final InvocationHandler invocationHandler; -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** - + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new InvocationHandlerAdapter instance. + * @param invocationHandler + */ public InvocationHandlerAdapter( InvocationHandler invocationHandler ) { this.invocationHandler = invocationHandler; } -//********************************************************************************************************************** -// Invoker Implementation -//********************************************************************************************************************** - - + //********************************************************************************************************************** + // Invoker Implementation + //********************************************************************************************************************** + + /** + * {...@inheritdoc} + */ public Object invoke( Object proxy, Method method, Object[] arguments ) throws Throwable { return invocationHandler.invoke(proxy, method, arguments); Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java Fri Jul 16 23:04:32 2010 @@ -32,13 +32,19 @@ import java.lang.reflect.Method; */ public class NullInvoker implements Invoker, Serializable { -//********************************************************************************************************************** -// Invoker Implementation -//********************************************************************************************************************** + /** Serialization version */ + private static final long serialVersionUID = 1L; + //********************************************************************************************************************** + // Invoker Implementation + //********************************************************************************************************************** + + /** + * {...@inheritdoc} + */ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { - final Class returnType = method.getReturnType(); + final Class<?> returnType = method.getReturnType(); return ProxyUtils.nullValue(returnType); } } Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java Fri Jul 16 23:04:32 2010 @@ -23,6 +23,7 @@ import org.apache.xmlrpc.XmlRpcException import org.apache.xmlrpc.XmlRpcHandler; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Vector; /** @@ -40,6 +41,9 @@ import java.util.Vector; */ public class XmlRpcInvoker implements Invoker { + /** Serialization version */ + private static final long serialVersionUID = 1L; + //********************************************************************************************************************** // Fields //********************************************************************************************************************** @@ -47,24 +51,31 @@ public class XmlRpcInvoker implements In private final XmlRpcHandler handler; private final String handlerName; -//********************************************************************************************************************** -// Constructors -//********************************************************************************************************************** - + //********************************************************************************************************************** + // Constructors + //********************************************************************************************************************** + + /** + * Create a new XmlRpcInvoker instance. + * @param handler + * @param handlerName + */ public XmlRpcInvoker( XmlRpcHandler handler, String handlerName ) { this.handler = handler; this.handlerName = handlerName; } -//********************************************************************************************************************** -// Invoker Implementation -//********************************************************************************************************************** - - + //********************************************************************************************************************** + // Invoker Implementation + //********************************************************************************************************************** + + /** + * {...@inheritdoc} + */ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { - final Object returnValue = handler.execute(handlerName + "." + method.getName(), toArgumentVector(args)); + final Object returnValue = handler.execute(handlerName + "." + method.getName(), new Vector<Object>(Arrays.asList(args))); if( returnValue instanceof XmlRpcException ) { throw new InvokerException("Unable to execute XML-RPC call.", ( XmlRpcException ) returnValue); @@ -72,18 +83,4 @@ public class XmlRpcInvoker implements In return returnValue; } -//********************************************************************************************************************** -// Other Methods -//********************************************************************************************************************** - - private Vector toArgumentVector( Object[] args ) - { - final Vector v = new Vector(); - for( int i = 0; i < args.length; i++ ) - { - Object arg = args[i]; - v.addElement(arg); - } - return v; - } } Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java Fri Jul 16 23:04:32 2010 @@ -29,7 +29,7 @@ import java.util.LinkedList; import java.util.List; /** - * @auothor James Carman + * @author James Carman */ public class InvocationRecorder { Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java Fri Jul 16 23:04:32 2010 @@ -22,7 +22,7 @@ import org.apache.commons.proxy.ProxyUti import java.lang.reflect.Method; /** - * @auothor James Carman + * @author James Carman */ public class RecordedInvocation { Modified: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java (original) +++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java Fri Jul 16 23:04:32 2010 @@ -6,7 +6,7 @@ import org.apache.commons.lang.Serializa import java.io.Serializable; /** - * @auothor James Carman + * @author James Carman * @since 1.1 */ public abstract class AbstractTestCase extends TestCase Modified: commons/proper/proxy/branches/version-2.0-work/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/pom.xml?rev=964972&r1=964971&r2=964972&view=diff ============================================================================== --- commons/proper/proxy/branches/version-2.0-work/pom.xml (original) +++ commons/proper/proxy/branches/version-2.0-work/pom.xml Fri Jul 16 23:04:32 2010 @@ -76,6 +76,13 @@ </roles> <url></url> </developer> + <developer> + <name>Matt Benson</name> + <email>mben...@apache.org</email> + <roles> + <role>Claim-jumper</role> + </roles> + </developer> </developers> <contributors>