tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject svn commit: r982836 - in /openejb/branches/openejb-3.1.x/container/openejb-core/src: main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java
Date Fri, 06 Aug 2010 00:00:18 GMT
Author: jgallimore
Date: Fri Aug  6 00:00:17 2010
New Revision: 982836

URL: http://svn.apache.org/viewvc?rev=982836&view=rev
Log:
Copied LocalBean proxy changes from trunk. OPENEJB-1321, OPENEJB-1323

Modified:
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java?rev=982836&r1=982835&r2=982836&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImpl.java
Fri Aug  6 00:00:17 2010
@@ -16,14 +16,17 @@
  */
 package org.apache.openejb.util.proxy;
 
-import org.apache.xbean.asm.*;
-
-import java.lang.reflect.Method;
 import java.lang.reflect.Field;
-import java.net.URLClassLoader;
+import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
+import org.apache.xbean.asm.ClassWriter;
+import org.apache.xbean.asm.FieldVisitor;
+import org.apache.xbean.asm.Label;
+import org.apache.xbean.asm.MethodVisitor;
+import org.apache.xbean.asm.Opcodes;
+import org.apache.xbean.asm.Type;
 
 public class LocalBeanProxyGeneratorImpl implements LocalBeanProxyGenerator, Opcodes {
 
@@ -62,7 +65,7 @@ public class LocalBeanProxyGeneratorImpl
 
         try {
             byte[] proxyBytes = generateProxy(clsToProxy, clsName);
-            return (Class<?>) unsafe.defineClass(proxyName, proxyBytes, 0, proxyBytes.length,
cl, this.getClass().getProtectionDomain());
+            return (Class<?>) unsafe.defineClass(proxyName, proxyBytes, 0, proxyBytes.length,
clsToProxy.getClassLoader(), clsToProxy.getProtectionDomain());
         } catch (ProxyGenerationException e) {
             throw new InternalError(e.toString());
         }
@@ -523,10 +526,16 @@ public class LocalBeanProxyGeneratorImpl
 			}
 		} else {
 			if (! parameterType.isPrimitive()) {
-				if (wrap) {
-					return "L" + parameterType.getCanonicalName().replaceAll("\\.", "/") + ";";
+                String clsName = parameterType.getCanonicalName();
+
+                if (parameterType.isMemberClass()) {
+                    int lastDot = clsName.lastIndexOf(".");
+                    clsName = clsName.substring(0, lastDot) + "$" + clsName.substring(lastDot
+ 1);
+                }
+                if (wrap) {
+					return "L" + clsName.replaceAll("\\.", "/") + ";";
 				} else {
-					return parameterType.getCanonicalName().replaceAll("\\.", "/");
+					return clsName.replaceAll("\\.", "/");
 				}
 			} else {
 				return getPrimitiveLetter(parameterType);

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java?rev=982836&r1=982835&r2=982836&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest.java
Fri Aug  6 00:00:17 2010
@@ -23,7 +23,6 @@ import org.junit.Test;
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -33,8 +32,8 @@ public class LocalBeanProxyGeneratorImpl
 	public class Call {
 		private String methodName;
 		private Class<?>[] parameterTypes;
-		
-		public String getMethodName() {
+
+        public String getMethodName() {
 			return methodName;
 		}
 		
@@ -51,14 +50,33 @@ public class LocalBeanProxyGeneratorImpl
 		}
 
 		public Call() {
-			super();
 		}
 
-		public Call(String methodName, Class<?>[] parameterTypes) {
+		public Call(String methodName, Class<?>... parameterTypes) {
 			this.parameterTypes = parameterTypes;
 			this.methodName = methodName;
 		}
-	}
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            Call call = (Call) o;
+
+            if (!methodName.equals(call.methodName)) return false;
+            if (!Arrays.equals(parameterTypes, call.parameterTypes)) return false;
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int result = methodName.hashCode();
+            result = 31 * result + Arrays.hashCode(parameterTypes);
+            return result;
+        }
+    }
 
 	private class TestInvocationHandler implements InvocationHandler {
 		
@@ -835,4 +853,61 @@ public class LocalBeanProxyGeneratorImpl
 		assertEquals("java/lang/Integer", proxyGenerator.getCastType(Integer.class));
 		assertEquals("org/apache/openejb/util/proxy/ProxyTestObject", proxyGenerator.getCastType(ProxyTestObject.class));
 	}
+
+
+    @Test
+    public void testEnumParam() throws Exception {
+        TestInvocationHandler invocationHandler = new TestInvocationHandler(new EnumParams());
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        Class cls = new LocalBeanProxyGeneratorImpl().createProxy(EnumParams.class, cl);
+        EnumParams proxy = (EnumParams) cls.getConstructor(new Class[] { InvocationHandler.class
}).newInstance(invocationHandler);
+
+        proxy.someStringMethod(Color.GREEN.name());
+        proxy.someEnumMethod(Color.RED);
+        proxy.someInnerClassMethod(new Name(Color.BLUE.name()));
+
+        Call[] calls = invocationHandler.getCalls();
+
+        assertEquals(3, calls.length);
+
+        assertEquals(new Call("someStringMethod", String.class), calls[0]);
+        assertEquals(new Call("someEnumMethod", Color.class), calls[1]);
+        assertEquals(new Call("someInnerClassMethod", Name.class), calls[2]);
+    }
+
+    public void testGetEnumType() throws Exception {
+        System.out.println(Color.class.getCanonicalName());
+        LocalBeanProxyGeneratorImpl localBeanProxyGenerator = new LocalBeanProxyGeneratorImpl();
+        assertEquals("Lorg/apache/openejb/util/proxy/LocalBeanProxyGeneratorImplTest$Color;",
localBeanProxyGenerator.getAsmTypeAsString(Color.class, true));
+    }
+
+
+    public static class EnumParams {
+
+        public void someEnumMethod(Color s){
+        }
+
+        public void someStringMethod(String s){
+        }
+
+        public void someInnerClassMethod(Name s){
+        }
+    }
+
+    public static enum Color {
+        RED, GREEN, BLUE;
+    }
+
+    public static class Name {
+        private final String name;
+
+        public Name(String name) {
+            this.name = name;
+        }
+
+        public String get() {
+            return name;
+        }
+    }
 }



Mime
View raw message