generics/serialization warnings, javadoc, and the occasional minor code change
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/proxy/branches/version-2.0-work@964972 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java b/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java
index e79a6fe..61181be 100644
--- a/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy/ProxyFactory.java
@@ -97,11 +97,12 @@
* @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 );
diff --git a/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java b/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java
index 4b17c23..ef57475 100644
--- a/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java
+++ b/core/src/main/java/org/apache/commons/proxy/ProxyUtils.java
@@ -38,9 +38,9 @@
//**********************************************************************************************************************
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 @@
* @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 @@
* @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 @@
* @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 @@
}
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 @@
* @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 @@
* @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 @@
* @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 @@
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()) &&
diff --git a/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java b/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java
index b9d7f6e..17fbcba 100644
--- a/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java
+++ b/core/src/main/java/org/apache/commons/proxy/exception/InvokerException.java
@@ -25,24 +25,43 @@
*/
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);
diff --git a/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java b/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java
index a7b6979..ce5af2a 100644
--- a/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java
+++ b/core/src/main/java/org/apache/commons/proxy/exception/ObjectProviderException.java
@@ -26,24 +26,43 @@
*/
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);
diff --git a/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java b/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java
index 136d6ae..e1c356b 100644
--- a/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java
+++ b/core/src/main/java/org/apache/commons/proxy/exception/ProxyFactoryException.java
@@ -26,24 +26,43 @@
*/
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);
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java b/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java
index 1269090..b9dc8af 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyClassGenerator.java
@@ -22,7 +22,6 @@
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 @@
* @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 @@
}
}
}
- 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()]);
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java b/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java
index 71c1b40..613f03e 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/AbstractProxyFactory.java
@@ -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 @@
* @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 @@
* @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 @@
* <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 @@
* @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 @@
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();
- }
- }
- }
}
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java b/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java
index cb4f98f..bffa869 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/AbstractSubclassingProxyFactory.java
@@ -5,10 +5,13 @@
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 @@
* @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 @@
// 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 @@
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 @@
* @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 @@
* @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 @@
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 )
{
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java b/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java
index 5779586..78a5714 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/MethodSignature.java
@@ -34,22 +34,29 @@
//**********************************************************************************************************************
private final String name;
- private final List parameterTypes;
+ private final List<Class<?>> parameterTypes;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // 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 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public int hashCode()
{
int result;
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java b/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java
index 1aa1434..2339746 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java
@@ -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 @@
*/
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 @@
// 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 @@
* @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));
}
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java b/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java
index 01aa883..78ab2bc 100644
--- a/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java
+++ b/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java
@@ -36,5 +36,5 @@
* @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 );
}
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java b/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java
index a3f1a37..f36a0c2 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java
@@ -52,29 +52,39 @@
*/
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());
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java b/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java
index 8dc3acb..a6722e4 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java
@@ -31,26 +31,35 @@
*/
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);
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java b/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java
index 522d4f3..51bf64c 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java
@@ -32,13 +32,19 @@
*/
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);
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java b/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java
index 065e494..4a7087c 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java
@@ -23,6 +23,7 @@
import org.apache.xmlrpc.XmlRpcHandler;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Vector;
/**
@@ -40,6 +41,9 @@
*/
public class XmlRpcInvoker implements Invoker
{
+ /** Serialization version */
+ private static final long serialVersionUID = 1L;
+
//**********************************************************************************************************************
// Fields
//**********************************************************************************************************************
@@ -47,24 +51,31 @@
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 @@
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;
- }
}
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java b/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java
index 3a30702..88baede 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java
@@ -29,7 +29,7 @@
import java.util.List;
/**
- * @auothor James Carman
+ * @author James Carman
*/
public class InvocationRecorder
{
diff --git a/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java b/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java
index 9eafbba..61edf6f 100644
--- a/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java
+++ b/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java
@@ -22,7 +22,7 @@
import java.lang.reflect.Method;
/**
- * @auothor James Carman
+ * @author James Carman
*/
public class RecordedInvocation
{
diff --git a/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java b/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java
index ebb3ae1..dbb1e40 100644
--- a/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java
@@ -6,7 +6,7 @@
import java.io.Serializable;
/**
- * @auothor James Carman
+ * @author James Carman
* @since 1.1
*/
public abstract class AbstractTestCase extends TestCase
diff --git a/pom.xml b/pom.xml
index b52ab4d..886a58c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,13 @@
</roles>
<url></url>
</developer>
+ <developer>
+ <name>Matt Benson</name>
+ <email>mbenson@apache.org</email>
+ <roles>
+ <role>Claim-jumper</role>
+ </roles>
+ </developer>
</developers>
<contributors>