Author: mbenson
Date: Tue Jul 27 15:40:21 2010
New Revision: 979754
URL: http://svn.apache.org/viewvc?rev=979754&view=rev
Log:
use lang3 TypeUtils in commons-proxy core
Modified:
commons/proper/proxy/branches/version-2.0-work/core/pom.xml
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
Modified: commons/proper/proxy/branches/version-2.0-work/core/pom.xml
URL:
http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/pom.xml?rev=979754&r1=979753&r2=979754&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/pom.xml (original)
+++ commons/proper/proxy/branches/version-2.0-work/core/pom.xml Tue Jul 27
15:40:21 2010
@@ -73,10 +73,10 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- <scope>test</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>jmock</groupId>
Modified:
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/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/proxy2/invoker/recorder/InvocationRecorder.java?rev=979754&r1=979753&r2=979754&view=diff
==============================================================================
---
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
(original)
+++
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
Tue Jul 27 15:40:21 2010
@@ -17,15 +17,14 @@
package org.apache.commons.proxy2.invoker.recorder;
+import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.proxy2.Invoker;
import org.apache.commons.proxy2.ProxyFactory;
import org.apache.commons.proxy2.ProxyUtils;
import org.apache.commons.proxy2.invoker.RecordedInvocation;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.util.LinkedList;
import java.util.List;
@@ -103,7 +102,8 @@ public class InvocationRecorder
public Object invoke( Object o, Method method, Object[] args ) throws
Throwable
{
recordedInvocations.add(new RecordedInvocation(method, args));
- final Class<?> returnType = getReturnType(targetType, method);
+ final Class<?> returnType =
TypeUtils.getRawType(method.getGenericReturnType(), targetType);
+ //what to do if returnType is null?
return proxy(method.getGenericReturnType(), returnType);
}
}
@@ -116,58 +116,4 @@ public class InvocationRecorder
recordedInvocations.clear();
}
- /**
- * Get the raw return type of a method qualified with regard to a
particular target type.
- * @param enclosingType
- * @param method
- * @return {...@link Class} instance
- * @throws Exception
- */
- public static Class<?> getReturnType( Type enclosingType, Method method )
throws Exception
- {
- Type returnType = method.getGenericReturnType();
- if( returnType instanceof Class<?> )
- {
- return ( Class<?> ) returnType;
- }
- else if( returnType instanceof TypeVariable<?> )
- {
- return resolveVariable(enclosingType, ( TypeVariable<?> )
returnType);
- }
- else if( returnType instanceof ParameterizedType )
- {
- return ( Class<?> ) ( ( ParameterizedType ) returnType
).getRawType();
- }
- return null;
- }
-
- /**
- * Resolve the raw type of a type variable against a particular
owning/inheriting type.
- * @param enclosingType
- * @param typeVar
- * @return {...@link Class} instance
- * @throws Exception
- */
- public static Class<?> resolveVariable( Type enclosingType,
TypeVariable<?> typeVar ) throws Exception
- {
- if( enclosingType instanceof ParameterizedType )
- {
- ParameterizedType pt = ( ParameterizedType ) enclosingType;
- final Class<?> rawType = ( Class<?> ) pt.getRawType();
- TypeVariable<?>[] typeParameters = rawType.getTypeParameters();
- for( int i = 0; i < typeParameters.length; i++ )
- {
- TypeVariable<?> typeParameter = typeParameters[i];
- if( typeParameter == typeVar )
- {
- return ( Class<?> ) pt.getActualTypeArguments()[i];
- }
- }
- }
- else if( enclosingType instanceof Class<?> )
- {
- return resolveVariable(( ( Class<?> ) enclosingType
).getGenericSuperclass(), typeVar);
- }
- return null;
- }
}
Modified:
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java?rev=979754&r1=979753&r2=979754&view=diff
==============================================================================
---
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
(original)
+++
commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
Tue Jul 27 15:40:21 2010
@@ -1,10 +1,11 @@
package org.apache.commons.proxy2.util;
import junit.framework.TestCase;
-import org.apache.commons.lang.SerializationUtils;
import java.io.Serializable;
+import org.apache.commons.lang3.SerializationUtils;
+
/**
* @author James Carman
* @since 1.1