[jboss-cvs] JBossAS SVN: r102382 - in projects/ejb3/components/proxy/trunk: build and 37 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 14 13:41:21 EDT 2010


Author: jaikiran
Date: 2010-03-14 13:41:20 -0400 (Sun, 14 Mar 2010)
New Revision: 102382

Added:
   projects/ejb3/components/proxy/trunk/javassist/
   projects/ejb3/components/proxy/trunk/javassist/pom.xml
   projects/ejb3/components/proxy/trunk/javassist/src/
   projects/ejb3/components/proxy/trunk/javassist/src/main/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistInvocationHandlerAdapter.java
   projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistProxyFactory.java
   projects/ejb3/components/proxy/trunk/javassist/src/test/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/DelegatingInvocationHandler.java
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/Dummy.java
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/SimpleClass.java
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/unit/
   projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/unit/JavassistProxyFactoryTestCase.java
   projects/ejb3/components/proxy/trunk/reflect/
   projects/ejb3/components/proxy/trunk/reflect/pom.xml
   projects/ejb3/components/proxy/trunk/reflect/src/
   projects/ejb3/components/proxy/trunk/reflect/src/main/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/reflect/
   projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/reflect/ReflectProxyFactory.java
   projects/ejb3/components/proxy/trunk/reflect/src/test/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/DelegatingInvocationHandler.java
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Echo.java
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Greeter.java
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/SimpleClass.java
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/unit/
   projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/unit/ReflectProxyFactoryTestCase.java
Modified:
   projects/ejb3/components/proxy/trunk/build/pom.xml
   projects/ejb3/components/proxy/trunk/pom.xml
   projects/ejb3/components/proxy/trunk/spi/src/main/java/org/jboss/ejb3/proxy/spi/factory/ProxyFactory.java
Log:
EJBTHREE-2012 Added javassist and java.lang.reflect based proxy factory implementations

Modified: projects/ejb3/components/proxy/trunk/build/pom.xml
===================================================================
--- projects/ejb3/components/proxy/trunk/build/pom.xml	2010-03-14 16:26:12 UTC (rev 102381)
+++ projects/ejb3/components/proxy/trunk/build/pom.xml	2010-03-14 17:41:20 UTC (rev 102382)
@@ -72,13 +72,11 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <redirectTestOutputToFile>true</redirectTestOutputToFile>
-          <trimStackTrace>false</trimStackTrace>
-          <printSummary>true</printSummary>
-          <includes>
-            <include>**/*UnitTest.java</include>
-          </includes>
-          <forkMode>always</forkMode>
-          <useFile>true</useFile>
+            <printSummary>true</printSummary>
+            <forkMode>always</forkMode>
+            <includes>
+                <include>**/*TestCase.java</include>
+            </includes>
         </configuration>
       </plugin>
 

Added: projects/ejb3/components/proxy/trunk/javassist/pom.xml
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/pom.xml	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/pom.xml	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,58 @@
+<!--
+  vi:ts=2:sw=2:expandtab
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Define Parent -->
+  <parent>
+    <groupId>org.jboss.ejb3.proxy</groupId>
+    <artifactId>proxy-build</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- Maven POM Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <artifactId>proxy-javassist</artifactId>
+  <packaging>jar</packaging>
+  <name>Javassist based implementation of proxy SPI</name>
+  <description>Javassist based implementation of proxy SPI</description>
+
+  
+  
+  <properties>
+  
+    <version.javassist>3.7.1.GA</version.javassist>
+  
+  </properties>
+
+  <dependencies>
+    <dependency>
+		<groupId>org.jboss.ejb3.proxy</groupId>
+		<artifactId>proxy-spi</artifactId>
+		<version>${project.version}</version>
+	</dependency>
+	
+	<dependency>
+		<groupId>javassist</groupId>
+		<artifactId>javassist</artifactId>
+		<version>${version.javassist}</version>
+	</dependency>
+	
+	
+	<!-- ********************** -->
+	<!-- Test dependencies -->
+	<!-- ********************** -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+	  <scope>test</scope>
+    </dependency>
+    
+    
+  </dependencies>
+</project>

Added: projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistInvocationHandlerAdapter.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistInvocationHandlerAdapter.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistInvocationHandlerAdapter.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import javassist.util.proxy.MethodHandler;
+
+/**
+ * {@link JavassistInvocationHandlerAdapter} is an implementation of Javassist {@link MethodHandler}
+ * and is responsible for forwarding the method invocations to a instance of {@link java.lang.reflect.InvocationHandler}
+ *
+ * @see MethodHandler
+ * @see InvocationHandler
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JavassistInvocationHandlerAdapter implements MethodHandler
+{
+
+   /**
+    * The invocation handler to which the method invocations will be forwarded to
+    */
+   private InvocationHandler invocationHandler;
+
+   /**
+    * Creates a {@link JavassistInvocationHandlerAdapter} for an {@link InvocationHandler}
+    * @param invocationHandler The invocation handler
+    * @throws IllegalArgumentException If the passed <code>invocationHandler</code> is null
+    */
+   public JavassistInvocationHandlerAdapter(InvocationHandler invocationHandler)
+   {
+      if (invocationHandler == null)
+      {
+         throw new IllegalArgumentException(this.getClass().getName() + " cannot be created out of a null "
+               + InvocationHandler.class.getName());
+      }
+      this.invocationHandler = invocationHandler;
+   }
+
+   /**
+    * Lets the {@link InvocationHandler} instance, which was passed to {@link #JavassistInvocationHandlerAdapter(InvocationHandler)} 
+    * handle the method invocation.
+    * 
+    * @see javassist.util.proxy.MethodHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.reflect.Method, java.lang.Object[])
+    */
+   @Override
+   public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
+   {
+      // let the invocation handler take care of the call
+      return this.invocationHandler.invoke(self, thisMethod, args);
+   }
+}
\ No newline at end of file

Added: projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistProxyFactory.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistProxyFactory.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/main/java/org/jboss/ejb3/proxy/javassist/JavassistProxyFactory.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist;
+
+import java.lang.reflect.InvocationHandler;
+
+import org.jboss.ejb3.proxy.spi.factory.ProxyFactory;
+
+/**
+ * Implementation of {@link ProxyFactory} which uses Javassist to create proxies
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JavassistProxyFactory implements ProxyFactory
+{
+
+   /**
+    * @see org.jboss.ejb3.proxy.spi.factory.ProxyFactory#createProxy(java.lang.ClassLoader, java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
+    */
+   public Object createProxy(ClassLoader cl, Class<?>[] types, InvocationHandler invocationHandler)
+         throws IllegalArgumentException
+   {
+      // we can only handle one type
+      if (types.length == 0)
+      {
+         throw new IllegalArgumentException("Class type not specified for creating proxy");
+      }
+      if (types.length > 1)
+      {
+         throw new IllegalArgumentException("More than one class type specified for creating proxy");
+      }
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("Null classloader passed to proxy creation");
+      }
+      String className = types[0].getName();
+      try
+      {
+         // we load the type using the passed classloader so
+         // that javassist will then use this classloader for
+         // creating the proxy on the passed type
+         Class<?> type = cl.loadClass(className);
+         // create a proxy for this type
+         return this.createProxy(new Class<?>[] {type}, invocationHandler);
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         throw new RuntimeException("Could not load class: " + className + " during proxy creation", cnfe);
+      }
+      
+   }
+
+   /**
+    * Creates a proxy using javassist
+    * <p>
+    *   This implementation expects the passed <code>types</code> to contain only one 
+    *   {@link Class} type. If it contains more than one {@link Class} type then a 
+    *   {@link IllegalArgumentException} is thrown
+    * </p>
+    * <p>
+    *  The implementation uses the classloader of <code>types</code>[0] for creating the
+    *  proxy
+    * </p>
+    * @throws IllegalArgumentException If more than one {@link Class} type is passed in the <code>types</code>
+    *  
+    * @see org.jboss.ejb3.proxy.spi.factory.ProxyFactory#createProxy(java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
+    */
+   public Object createProxy(Class<?>[] types, InvocationHandler invocationHandler) throws IllegalArgumentException
+   {
+      // we can only handle one type
+      if (types.length == 0)
+      {
+         throw new IllegalArgumentException("Class type not specified for creating proxy");
+      }
+      if (types.length > 1)
+      {
+         throw new IllegalArgumentException("More than one class type specified for creating proxy");
+      }
+
+      javassist.util.proxy.ProxyFactory javassistProxyFactory = new javassist.util.proxy.ProxyFactory();
+      // set the bean class for which we need a proxy 
+      // Javassist internally uses the classloader of this "superclass" for
+      // proxy creation
+      javassistProxyFactory.setSuperclass(types[0]);
+      // Set our method handler which is responsible for handling the method invocations
+      // on the proxy
+      javassistProxyFactory.setHandler(new JavassistInvocationHandlerAdapter(invocationHandler));
+
+      // create the proxy
+      Object proxy;
+      try
+      {
+         proxy = javassistProxyFactory.create(new Class[0], new Object[0]);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Could not create a proxy of type " + types[0], e);
+      }
+      // cast to the bean type and return
+      return types[0].cast(proxy);
+   }
+
+}

Added: projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/DelegatingInvocationHandler.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/DelegatingInvocationHandler.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/DelegatingInvocationHandler.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist.test;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * DelegatingInvocationHandler
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class DelegatingInvocationHandler <T> implements InvocationHandler
+{
+
+   private T delegateInstance;
+   
+   public DelegatingInvocationHandler(T delegate)
+   {
+      this.delegateInstance = delegate;
+   }
+   
+   /** (non-Javadoc)
+    * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+    */
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      return method.invoke(this.delegateInstance, args);
+   }
+
+}

Added: projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/Dummy.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/Dummy.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/Dummy.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist.test;
+
+/**
+ * Dummy
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class Dummy
+{
+   public void doNothing()
+   {
+      
+   }
+}

Added: projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/SimpleClass.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/SimpleClass.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/SimpleClass.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist.test;
+
+/**
+ * SimpleClass
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SimpleClass
+{
+
+   public String echo(String msg)
+   {
+      return msg;
+   }
+}

Added: projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/unit/JavassistProxyFactoryTestCase.java
===================================================================
--- projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/unit/JavassistProxyFactoryTestCase.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/javassist/src/test/java/org/jboss/ejb3/proxy/javassist/test/unit/JavassistProxyFactoryTestCase.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.javassist.test.unit;
+
+import java.lang.reflect.InvocationHandler;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.proxy.javassist.JavassistProxyFactory;
+import org.jboss.ejb3.proxy.javassist.test.DelegatingInvocationHandler;
+import org.jboss.ejb3.proxy.javassist.test.Dummy;
+import org.jboss.ejb3.proxy.javassist.test.SimpleClass;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test {@link JavassistProxyFactory}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JavassistProxyFactoryTestCase
+{
+
+   private JavassistProxyFactory javassistProxyFactory;
+
+   @Before
+   public void beforeTest()
+   {
+      this.javassistProxyFactory = new JavassistProxyFactory();
+   }
+
+   /**
+    * Tests that the proxy creation through {@link JavassistProxyFactory} works as expected
+    * @throws Exception
+    */
+   @Test
+   public void testProxyCreation() throws Exception
+   {
+      SimpleClass instance = new SimpleClass();
+      InvocationHandler invocationHandler = new DelegatingInvocationHandler<SimpleClass>(instance);
+      Object obj = this.javassistProxyFactory.createProxy(new Class<?>[]
+      {SimpleClass.class}, invocationHandler);
+
+      Assert.assertNotNull("Proxy factory created a null proxy", obj);
+      Assert.assertTrue("Proxy factory created a proxy which is *not* of type " + SimpleClass.class,
+            (obj instanceof SimpleClass));
+
+      SimpleClass proxy = (SimpleClass) obj;
+      String msg = "Hello";
+      String result = proxy.echo(msg);
+      Assert.assertEquals("Unexpected return value from proxy invocation", msg, result);
+   }
+
+   /**
+    * Test that proxy creation through {@link JavassistProxyFactory} leads to {@link IllegalArgumentException}
+    * if the number of {@link Class} types passed, is more than one
+    * @throws Exception
+    */
+   @Test
+   public void testProxyCreationForMoreThanOneType() throws Exception
+   {
+      SimpleClass instance = new SimpleClass();
+      InvocationHandler invocationHandler = new DelegatingInvocationHandler<SimpleClass>(instance);
+      try
+      {
+         Object obj = this.javassistProxyFactory.createProxy(new Class<?>[]
+         {SimpleClass.class, Dummy.class}, invocationHandler);
+         Assert.fail("Javassist proxy factory unexpectedly created a proxy for more than one type");
+      }
+      catch (IllegalArgumentException iae)
+      {
+         //expected
+      }
+
+   }
+}

Modified: projects/ejb3/components/proxy/trunk/pom.xml
===================================================================
--- projects/ejb3/components/proxy/trunk/pom.xml	2010-03-14 16:26:12 UTC (rev 102381)
+++ projects/ejb3/components/proxy/trunk/pom.xml	2010-03-14 17:41:20 UTC (rev 102382)
@@ -45,6 +45,8 @@
   <modules>
     <module>spi</module>
     <module>build</module>
+	<module>reflect</module>
+    <module>javassist</module>
   </modules>
 
 </project>

Added: projects/ejb3/components/proxy/trunk/reflect/pom.xml
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/pom.xml	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/pom.xml	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,52 @@
+<!--
+  vi:ts=2:sw=2:expandtab
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Define Parent -->
+  <parent>
+    <groupId>org.jboss.ejb3.proxy</groupId>
+    <artifactId>proxy-build</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- Maven POM Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <artifactId>proxy-reflect</artifactId>
+  <packaging>jar</packaging>
+  <name>java.lang.reflect based implementation of proxy SPI</name>
+  <description>java.lang.reflect based implementation of proxy SPI</description>
+
+  
+  
+  <properties>
+  
+    
+  
+  </properties>
+
+  <dependencies>
+    <dependency>
+		<groupId>org.jboss.ejb3.proxy</groupId>
+		<artifactId>proxy-spi</artifactId>
+		<version>${project.version}</version>
+	</dependency>
+	
+	
+	<!-- ********************** -->
+	<!-- Test dependencies -->
+	<!-- ********************** -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+	  <scope>test</scope>
+    </dependency>
+    
+    
+  </dependencies>
+</project>

Added: projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/reflect/ReflectProxyFactory.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/reflect/ReflectProxyFactory.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/main/java/org/jboss/ejb3/proxy/reflect/ReflectProxyFactory.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+import org.jboss.ejb3.proxy.spi.factory.ProxyFactory;
+
+/**
+ * Implementation of {@link ProxyFactory} which creates {@link java.lang.reflect.Proxy}
+ * based proxies
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ReflectProxyFactory implements ProxyFactory
+{
+
+   /**
+    * Creates a {@link Proxy}
+    * <p>
+    *   This method uses the classloader of <code>types</code>[0] {@link Class} for creating the proxy 
+    * </p>
+    * @see org.jboss.ejb3.proxy.spi.factory.ProxyFactory#createProxy(java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
+    */
+   public Object createProxy(Class<?>[] types, InvocationHandler invocationHandler) throws IllegalArgumentException
+   {
+      ClassLoader cl = types[0].getClassLoader();
+      return this.createProxy(cl, types, invocationHandler);
+   }
+
+   /**
+    * @see org.jboss.ejb3.proxy.spi.factory.ProxyFactory#createProxy(java.lang.ClassLoader, java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
+    */
+   public Object createProxy(ClassLoader cl, Class<?>[] types, InvocationHandler invocationHandler)
+         throws IllegalArgumentException
+   {
+      return Proxy.newProxyInstance(cl, types, invocationHandler);
+   }
+
+}

Added: projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/DelegatingInvocationHandler.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/DelegatingInvocationHandler.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/DelegatingInvocationHandler.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect.test;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * DelegatingInvocationHandler
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class DelegatingInvocationHandler<T> implements InvocationHandler
+{
+
+   private T delegateInstance;
+
+   public DelegatingInvocationHandler(T delegate)
+   {
+      this.delegateInstance = delegate;
+   }
+
+   /** (non-Javadoc)
+    * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+    */
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      return method.invoke(this.delegateInstance, args);
+   }
+
+}

Added: projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Echo.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Echo.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Echo.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect.test;
+
+/**
+ * Echo
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Echo
+{
+
+   public String echo(String msg);
+}

Added: projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Greeter.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Greeter.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/Greeter.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect.test;
+
+/**
+ * Greeter
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Greeter
+{
+   public String greet(String user);
+}

Added: projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/SimpleClass.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/SimpleClass.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/SimpleClass.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect.test;
+
+/**
+ * SimpleClass
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SimpleClass implements Echo, Greeter
+{
+
+   public String echo(String msg)
+   {
+      return msg;
+   }
+
+   /**
+    * @see org.jboss.ejb3.proxy.reflect.test.Greeter#greet(java.lang.String)
+    */
+   public String greet(String user)
+   {
+      return "Hello " + user;
+   }
+}

Added: projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/unit/ReflectProxyFactoryTestCase.java
===================================================================
--- projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/unit/ReflectProxyFactoryTestCase.java	                        (rev 0)
+++ projects/ejb3/components/proxy/trunk/reflect/src/test/java/org/jboss/ejb3/proxy/reflect/test/unit/ReflectProxyFactoryTestCase.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -0,0 +1,101 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.proxy.reflect.test.unit;
+
+import java.lang.reflect.InvocationHandler;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.proxy.reflect.ReflectProxyFactory;
+import org.jboss.ejb3.proxy.reflect.test.DelegatingInvocationHandler;
+import org.jboss.ejb3.proxy.reflect.test.Echo;
+import org.jboss.ejb3.proxy.reflect.test.Greeter;
+import org.jboss.ejb3.proxy.reflect.test.SimpleClass;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ReflectProxyFactory}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ReflectProxyFactoryTestCase
+{
+
+   private ReflectProxyFactory reflectProxyFactory;
+
+   @Before
+   public void beforeTest()
+   {
+      this.reflectProxyFactory = new ReflectProxyFactory();
+   }
+
+   /**
+    * Tests that the proxy creation through {@link ReflectProxyFactory} works as expected
+    * @throws Exception
+    */
+   @Test
+   public void testProxyCreation() throws Exception
+   {
+      SimpleClass instance = new SimpleClass();
+      InvocationHandler invocationHandler = new DelegatingInvocationHandler<SimpleClass>(instance);
+      Object obj = this.reflectProxyFactory.createProxy(new Class<?>[]{Echo.class}, invocationHandler);
+      
+      Assert.assertNotNull("Proxy factory created a null proxy", obj);
+      Assert.assertTrue("Proxy factory created a proxy which is *not* of type " + Echo.class, (obj instanceof Echo));
+      
+      Echo proxy = (Echo) obj;
+      String msg = "Hello";
+      String result = proxy.echo(msg);
+      Assert.assertEquals("Unexpected return value from proxy invocation", msg, result);
+   }
+   
+   /**
+    * Test that proxy creation through {@link ReflectProxyFactory} for multiple class types
+    * does not lead to any exception
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testProxyCreationForMultipleTypes() throws Exception
+   {
+      SimpleClass instance = new SimpleClass();
+      InvocationHandler invocationHandler = new DelegatingInvocationHandler<SimpleClass>(instance);
+      Object obj = this.reflectProxyFactory.createProxy(new Class<?>[]{Echo.class, Greeter.class}, invocationHandler);
+      
+      Assert.assertNotNull("Proxy factory created a null proxy", obj);
+      Assert.assertTrue("Proxy factory created a proxy which is *not* of type " + Echo.class, (obj instanceof Echo));
+      Assert.assertTrue("Proxy factory created a proxy which is *not* of type " + Greeter.class, (obj instanceof Greeter));
+      
+      Echo proxy = (Echo) obj;
+      String msg = "Hello";
+      String result = proxy.echo(msg);
+      Assert.assertEquals("Unexpected return value from proxy invocation", msg, result);
+      
+      Greeter greeter = (Greeter) obj;
+      String user = "me";
+      String greeting = greeter.greet(user);
+      String expected = "Hello " + user;
+      Assert.assertEquals("Unexpected return value from proxy invocation", expected, greeting);
+   }
+}

Modified: projects/ejb3/components/proxy/trunk/spi/src/main/java/org/jboss/ejb3/proxy/spi/factory/ProxyFactory.java
===================================================================
--- projects/ejb3/components/proxy/trunk/spi/src/main/java/org/jboss/ejb3/proxy/spi/factory/ProxyFactory.java	2010-03-14 16:26:12 UTC (rev 102381)
+++ projects/ejb3/components/proxy/trunk/spi/src/main/java/org/jboss/ejb3/proxy/spi/factory/ProxyFactory.java	2010-03-14 17:41:20 UTC (rev 102382)
@@ -36,11 +36,12 @@
    //-------------------------------------------------------------------------------------||
    // Contracts --------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
-
+   
    /**
     * Creates a proxy which is castable to the specified type(s) passed;
     * the specified {@link InvocationHandler} will service requests
     * 
+    * @param cl The classloader to use for creating the proxy
     * @param types Target types supported by the returned proxy.  In some implementations,
     *   this may require an array of interfaces; in others a concrete base class must be supplied.
     *   It is the responsibility of implementors to throw {@link IllegalArgumentException} on 
@@ -49,6 +50,24 @@
     * not be null else {@link IllegalArgumentException} will be raised
     * @throws IllegalArgumentException
     */
+   Object createProxy(ClassLoader cl, Class<?>[] types, InvocationHandler invocationHandler) throws IllegalArgumentException;
+
+   /**
+    * Creates a proxy which is castable to the specified type(s) passed;
+    * the specified {@link InvocationHandler} will service requests
+    * <p>
+    *  It's upto the implementation to use a classloader of their choice to create the proxy. If the calling
+    *  code expects a specific classloader to be used for proxy creation, then use the other {@link #createProxy(ClassLoader, Class[], InvocationHandler)}
+    *  method.
+    * </p>
+    * @param types Target types supported by the returned proxy.  In some implementations,
+    *   this may require an array of interfaces; in others a concrete base class must be supplied.
+    *   It is the responsibility of implementors to throw {@link IllegalArgumentException} on 
+    *   unsupported input
+    * @param invocationHandler Underlying handler used to service invocations upon the returned proxy; must
+    * not be null else {@link IllegalArgumentException} will be raised
+    * @throws IllegalArgumentException
+    */
    Object createProxy(Class<?>[] types, InvocationHandler invocationHandler) throws IllegalArgumentException;
 
 }




More information about the jboss-cvs-commits mailing list