[jboss-cvs] JBossAS SVN: r75568 - in projects/ejb3/dev/proxy-int/proxy/src: main/java/org/jboss/ejb3/proxy/handler/session and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 9 18:44:02 EDT 2008


Author: ALRubinger
Date: 2008-07-09 18:44:02 -0400 (Wed, 09 Jul 2008)
New Revision: 75568

Modified:
   projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/ProxyInvocationHandlerBase.java
   projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionProxyInvocationHandlerBase.java
   projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionSpecProxyInvocationHandlerBase.java
   projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/lang/SerializableMethod.java
   projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java
   projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
   projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/lang/unit/SerializableMethodTestCase.java
Log:
[EJBTHREE-1345][EJBTHREE-1060] Add support for the actual class for a method in addition to the declaring class; required for proper implementation of getInvokedBusinessInterface with common ancestry

Modified: projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/ProxyInvocationHandlerBase.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/ProxyInvocationHandlerBase.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/ProxyInvocationHandlerBase.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.proxy.handler;
 
+import java.lang.reflect.Method;
+
 import org.jboss.ejb3.proxy.lang.SerializableMethod;
 
 /**
@@ -61,11 +63,11 @@
       try
       {
          METHOD_TO_STRING = new SerializableMethod(Object.class
-               .getDeclaredMethod(ProxyInvocationHandlerBase.METHOD_NAME_TO_STRING));
+               .getDeclaredMethod(ProxyInvocationHandlerBase.METHOD_NAME_TO_STRING), Object.class);
          METHOD_EQUALS = new SerializableMethod(Object.class.getDeclaredMethod(
-               ProxyInvocationHandlerBase.METHOD_NAME_EQUALS, Object.class));
+               ProxyInvocationHandlerBase.METHOD_NAME_EQUALS, Object.class), Object.class);
          METHOD_HASH_CODE = new SerializableMethod(Object.class
-               .getDeclaredMethod(ProxyInvocationHandlerBase.METHOD_NAME_HASH_CODE));
+               .getDeclaredMethod(ProxyInvocationHandlerBase.METHOD_NAME_HASH_CODE), Object.class);
       }
       catch (NoSuchMethodException nsme)
       {
@@ -121,8 +123,11 @@
       SerializableMethod invokedMethod = this.getInvokedMethod();
       assert invokedMethod != null : "Invoked Method was not set upon invocation of " + this.getClass().getName();
 
+      // Obtain Declared Method
+      Method declaredMethod = invokedMethod.toMethod();
+
       // equals
-      if (invokedMethod.equals(ProxyInvocationHandlerBase.METHOD_EQUALS))
+      if (declaredMethod.equals(ProxyInvocationHandlerBase.METHOD_EQUALS.toMethod()))
       {
          assert args.length == 1 : "Invocation for 'equals' should have exactly one argument, instead was: "
                + invokedMethod;
@@ -130,12 +135,12 @@
          return this.invokeEquals(proxy, argument);
       }
       // toString
-      if (invokedMethod.equals(ProxyInvocationHandlerBase.METHOD_TO_STRING))
+      if (declaredMethod.equals(ProxyInvocationHandlerBase.METHOD_TO_STRING.toMethod()))
       {
          return this.toString();
       }
       // hashCode
-      if (invokedMethod.equals(ProxyInvocationHandlerBase.METHOD_HASH_CODE))
+      if (declaredMethod.equals(ProxyInvocationHandlerBase.METHOD_HASH_CODE.toMethod()))
       {
          return this.invokeHashCode(proxy);
       }

Modified: projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionProxyInvocationHandlerBase.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionProxyInvocationHandlerBase.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionProxyInvocationHandlerBase.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -21,24 +21,17 @@
  */
 package org.jboss.ejb3.proxy.handler.session;
 
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.List;
 
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
 import org.jboss.aspects.remoting.PojiProxy;
 import org.jboss.ejb3.common.registrar.spi.Ejb3Registrar;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
-import org.jboss.ejb3.common.string.StringUtils;
 import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
 import org.jboss.ejb3.proxy.container.InvokableContext;
-import org.jboss.ejb3.proxy.handler.NotEligibleForDirectInvocationException;
 import org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase;
-import org.jboss.ejb3.proxy.lang.SerializableMethod;
 import org.jboss.ejb3.proxy.remoting.IsLocalProxyFactoryInterceptor;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.InvokerLocator;
@@ -60,6 +53,8 @@
    // Class Members ----------------------------------------------------------------||
    // ------------------------------------------------------------------------------||
 
+   private static final long serialVersionUID = 1L;
+   
    private static final Logger log = Logger.getLogger(SessionProxyInvocationHandlerBase.class);
 
    // ------------------------------------------------------------------------------||
@@ -74,46 +69,6 @@
       super();
    }
 
-   // ------------------------------------------------------------------------------||
-   // Required Implementations -----------------------------------------------------||
-   // ------------------------------------------------------------------------------||
-
-   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
-   {
-      // Set the invoked method
-      SerializableMethod invokedMethod = new SerializableMethod(method);
-      this.setInvokedMethod(invokedMethod);
-      
-      // Attempt to handle directly
-      try
-      {
-         return this.handleInvocationDirectly(proxy, args);
-      }
-      // Ignore this, we just couldn't handle here
-      catch (NotEligibleForDirectInvocationException nefdie)
-      {
-         log.debug("Couldn't handle invocation directly within " + this + ": "
-               + nefdie.getMessage());
-      }
-      
-      /*
-       * Obtain the Container
-       */
-      InvokableContext<?> container = this.getContainer();
-
-      /*
-       * Invoke
-       */
-
-      // Invoke
-      log.debug("Invoking: " + invokedMethod + " with arguments " + args + "...");
-      Object result = container.invoke(proxy, invokedMethod, args);
-
-      // Return
-      return result;
-
-   }
-
    /**
     * Returns the container housed locally
     * 

Modified: projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionSpecProxyInvocationHandlerBase.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionSpecProxyInvocationHandlerBase.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/handler/session/SessionSpecProxyInvocationHandlerBase.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -21,6 +21,13 @@
  */
 package org.jboss.ejb3.proxy.handler.session;
 
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.proxy.container.InvokableContext;
+import org.jboss.ejb3.proxy.handler.NotEligibleForDirectInvocationException;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
+import org.jboss.logging.Logger;
+
 /**
  * SessionSpecProxyInvocationHandlerBase
  * 
@@ -35,6 +42,12 @@
          SessionSpecProxyInvocationHandler
 {
    // ------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(SessionSpecProxyInvocationHandlerBase.class);
+   
+   // ------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------||
    // ------------------------------------------------------------------------------||
 
@@ -62,7 +75,57 @@
       super();
       this.setBusinessInterfaceType(businessInterfaceType);
    }
+   
+   // ------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------||
+   // ------------------------------------------------------------------------------||
 
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      // Initialize an explicitly-specified actual class
+      Class<?> callingClass = method.getDeclaringClass();
+      
+      // Obtain an explicitly-specified actual class
+      String actualClass = this.getBusinessInterfaceType();
+      if (actualClass != null && actualClass.trim().length() > 0)
+      {
+         callingClass = Class.forName(this.getBusinessInterfaceType());
+      }
+      
+      // Set the invoked method
+      SerializableMethod invokedMethod = new SerializableMethod(method, callingClass);
+      this.setInvokedMethod(invokedMethod);
+      
+      // Attempt to handle directly
+      try
+      {
+         return this.handleInvocationDirectly(proxy, args);
+      }
+      // Ignore this, we just couldn't handle here
+      catch (NotEligibleForDirectInvocationException nefdie)
+      {
+         log.debug("Couldn't handle invocation directly within " + this + ": "
+               + nefdie.getMessage());
+      }
+      
+      /*
+       * Obtain the Container
+       */
+      InvokableContext<?> container = this.getContainer();
+
+      /*
+       * Invoke
+       */
+
+      // Invoke
+      log.debug("Invoking: " + invokedMethod + " with arguments " + args + "...");
+      Object result = container.invoke(proxy, invokedMethod, args);
+
+      // Return
+      return result;
+
+   }
+
    // ------------------------------------------------------------------------------||
    // Accessors / Mutators ---------------------------------------------------------||
    // ------------------------------------------------------------------------------||

Modified: projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/lang/SerializableMethod.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/lang/SerializableMethod.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/lang/SerializableMethod.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -56,11 +56,16 @@
    private String name;
 
    /**
-    * Fully-qualified class name of the method
+    * Fully-qualified declaring class name of the method
     */
-   private String className;
+   private String declaringClassName;
 
    /**
+    * Fully-qualified final (child) class name of the method, may have inherited the method
+    */
+   private String actualClassName;
+
+   /**
     * Fully-qualfied class name of the return type of the method
     */
    private String returnType;
@@ -77,13 +82,16 @@
    /**
     * Constructor
     * 
-    * @param Method The method this view represents
+    * @param method The method this view represents
+    * @param actualClass The class to which this method is associated, 
+    *   may be a child of the class declaring the method
     */
-   public SerializableMethod(Method method)
+   public SerializableMethod(Method method, Class<?> actualClass)
    {
       // Set properties
       this.setName(method.getName());
-      this.setClassName(method.getDeclaringClass().getName());
+      this.setDeclaringClassName(method.getDeclaringClass().getName());
+      this.setActualClassName(actualClass.getName());
       this.setReturnType(method.getReturnType().getName());
       Class<?>[] paramTypes = method.getParameterTypes();
       List<String> paramTypesString = new ArrayList<String>();
@@ -116,8 +124,10 @@
       SerializableMethod other = SerializableMethod.class.cast(obj);
 
       // We're equal if all properties are equal
-      return this.getClassName().equals(other.getClassName()) && this.getName().equals(other.getName())
-            && Arrays.equals(this.getArgumentTypes(), other.getArgumentTypes());
+      return this.getDeclaringClassName().equals(other.getDeclaringClassName())
+            && this.getName().equals(other.getName())
+            && Arrays.equals(this.getArgumentTypes(), other.getArgumentTypes())
+            && this.getActualClassName().equals(other.getActualClassName());
    }
 
    @Override
@@ -134,7 +144,9 @@
       StringBuffer sb = new StringBuffer();
 
       // Construct
-      sb.append(this.getClassName());
+      sb.append(this.getActualClassName());
+      sb.append(": ");
+      sb.append(this.getDeclaringClassName());
       sb.append('.');
       sb.append(this.getName());
       sb.append('(');
@@ -228,7 +240,7 @@
    public Class<?> getClassType(ClassLoader cl)
    {
       // Obtain
-      Class<?> clazz = this.getClassFromName(this.getClassName(), cl);
+      Class<?> clazz = this.getClassFromName(this.getDeclaringClassName(), cl);
 
       // Return 
       return clazz;
@@ -306,14 +318,14 @@
    // Accessors / Mutators ---------------------------------------------------------||
    // ------------------------------------------------------------------------------||
 
-   public String getClassName()
+   public String getDeclaringClassName()
    {
-      return className;
+      return declaringClassName;
    }
 
-   public void setClassName(String className)
+   public void setDeclaringClassName(String className)
    {
-      this.className = className;
+      this.declaringClassName = className;
    }
 
    public String getReturnType()
@@ -346,4 +358,14 @@
       this.name = name;
    }
 
+   public String getActualClassName()
+   {
+      return actualClassName;
+   }
+
+   public void setActualClassName(String actualClassName)
+   {
+      this.actualClassName = actualClassName;
+   }
+
 }

Modified: projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -130,7 +130,8 @@
             // Obtain a proxy specific to this business interface
             String businessInterface = businessInterfaces.get(0);
             proxy = sFactory.createProxyBusiness(businessInterface);
-            log.debug("Created Proxy " + proxy + " for EJB3 Business Interface: " + businessInterface);
+            log.debug("Created Proxy of type" + proxy.getClass().getSimpleName() + " for EJB3 Business Interface: "
+                  + businessInterface);
          }
          else
          {

Modified: projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -157,7 +157,7 @@
       }
 
       // Obtain the method for invocation
-      Method m = this.getClassLoader().loadClass(method.getClassName()).getDeclaredMethod(method.getName(), argTypes);
+      Method m = this.getClassLoader().loadClass(method.getDeclaringClassName()).getDeclaredMethod(method.getName(), argTypes);
 
       // Invoke on the bean
       return invokeBean(proxy, m, args);

Modified: projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/lang/unit/SerializableMethodTestCase.java
===================================================================
--- projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/lang/unit/SerializableMethodTestCase.java	2008-07-09 22:41:46 UTC (rev 75567)
+++ projects/ejb3/dev/proxy-int/proxy/src/test/java/org/jboss/ejb3/test/proxy/lang/unit/SerializableMethodTestCase.java	2008-07-09 22:44:02 UTC (rev 75568)
@@ -73,8 +73,10 @@
 
       Method methodWithNoParamAndReturningVoid = myClass.getClass().getMethod("methodWithNoParamAndReturningVoid",
             (Class<?>[]) null);
-      SerializableMethod serializableMethod = new SerializableMethod(methodWithNoParamAndReturningVoid);
-      SerializableMethod anotherSerializableMethod = new SerializableMethod(methodWithNoParamAndReturningVoid);
+      SerializableMethod serializableMethod = new SerializableMethod(methodWithNoParamAndReturningVoid, myClass
+            .getClass());
+      SerializableMethod anotherSerializableMethod = new SerializableMethod(methodWithNoParamAndReturningVoid, myClass
+            .getClass());
 
       // These 2 SerializableMethod instances should be equal, as they were created for the same Method
       assertTrue("Failure - Two SerializableMethod instances created out of the same Method are not equal",
@@ -103,9 +105,10 @@
       Method methodAcceptingArrayOfPrimitives = myClass.getClass().getMethod("methodAcceptingArrayOfPrimitives",
             new Class[]
             {int[].class});
-      SerializableMethod serializableMethod_arrayOfPrimitives = new SerializableMethod(methodAcceptingArrayOfPrimitives);
+      SerializableMethod serializableMethod_arrayOfPrimitives = new SerializableMethod(
+            methodAcceptingArrayOfPrimitives, myClass.getClass());
       SerializableMethod anotherSerializableMethod_arrayOfPrimitives = new SerializableMethod(
-            methodAcceptingArrayOfPrimitives);
+            methodAcceptingArrayOfPrimitives, myClass.getClass());
 
       // test equals
       assertTrue(
@@ -122,9 +125,10 @@
 
       Method methodAcceptingArrayOfObjects = myClass.getClass().getMethod("methodAcceptingArrayOfObjects", new Class[]
       {Object[].class});
-      SerializableMethod serializableMethod_arrayOfObjects = new SerializableMethod(methodAcceptingArrayOfObjects);
+      SerializableMethod serializableMethod_arrayOfObjects = new SerializableMethod(methodAcceptingArrayOfObjects,
+            myClass.getClass());
       SerializableMethod anotherSerializableMethod_arrayOfObjects = new SerializableMethod(
-            methodAcceptingArrayOfObjects);
+            methodAcceptingArrayOfObjects, myClass.getClass());
 
       // test equals
       assertTrue(
@@ -158,8 +162,10 @@
             "methodWithParamAndReturningVoid", new Class[]
             {Integer.class});
 
-      SerializableMethod serializableMethod = new SerializableMethod(methodAcceptingStringParamAndReturingVoid);
-      SerializableMethod anotherSerializableMethod = new SerializableMethod(methodAcceptingIntegerParamAndReturingVoid);
+      SerializableMethod serializableMethod = new SerializableMethod(methodAcceptingStringParamAndReturingVoid, myClass
+            .getClass());
+      SerializableMethod anotherSerializableMethod = new SerializableMethod(methodAcceptingIntegerParamAndReturingVoid,
+            myClass.getClass());
 
       // test the equals
       assertFalse("Failure - Two Serializable method instances created for 2 different overloaded methods are equal",
@@ -174,9 +180,9 @@
             {int.class});
 
       SerializableMethod serializableMethod_PrimitiveIntParam = new SerializableMethod(
-            methodAcceptingPrimitiveIntAndReturningVoid);
+            methodAcceptingPrimitiveIntAndReturningVoid, myClass.getClass());
       SerializableMethod serializableMethod_IntegerParam = new SerializableMethod(
-            methodAcceptingIntegerParamAndReturingVoid);
+            methodAcceptingIntegerParamAndReturingVoid, myClass.getClass());
 
       // test the equals
       assertFalse(
@@ -189,7 +195,8 @@
 
       Method methodAcceptingObject = myClass.getClass().getMethod("methodWithParamAndReturningVoid", new Class[]
       {Object.class});
-      SerializableMethod serializableMethod_ObjectParam = new SerializableMethod(methodAcceptingObject);
+      SerializableMethod serializableMethod_ObjectParam = new SerializableMethod(methodAcceptingObject, myClass
+            .getClass());
 
       // test the equals
       assertFalse(
@@ -214,8 +221,10 @@
       Method toStringMethodOfMyClass = myClass.getClass().getDeclaredMethod("toString", (Class<?>[]) null);
       Method toStringMethodOfObject = Object.class.getDeclaredMethod("toString", (Class<?>[]) null);
 
-      SerializableMethod serializableMethod_toStringForMyClass = new SerializableMethod(toStringMethodOfMyClass);
-      SerializableMethod serializableMethod_toStringForThisTestCase = new SerializableMethod(toStringMethodOfObject);
+      SerializableMethod serializableMethod_toStringForMyClass = new SerializableMethod(toStringMethodOfMyClass,
+            myClass.getClass());
+      SerializableMethod serializableMethod_toStringForThisTestCase = new SerializableMethod(toStringMethodOfObject,
+            Object.class);
 
       // test the equals 
       assertFalse("Failure - Two SerializableMethod instances for same methods from two different classes are equal",
@@ -240,7 +249,7 @@
       Method methodWithParam = myClass.getClass().getMethod("methodAcceptingArrayOfObjects", new Class[]
       {Object[].class});
 
-      SerializableMethod serializableMethod = new SerializableMethod(methodWithParam);
+      SerializableMethod serializableMethod = new SerializableMethod(methodWithParam, myClass.getClass());
 
       SerializableMethod copyOfSerializableMethod = (SerializableMethod) SerializationUtil.getCopy(serializableMethod);
 
@@ -256,7 +265,7 @@
 
       Method method = myClass.getClass().getMethod("methodAcceptingMyClass", new Class[]
       {MyClass.class});
-      SerializableMethod serializableMethod_nonSerializableParam = new SerializableMethod(method);
+      SerializableMethod serializableMethod_nonSerializableParam = new SerializableMethod(method, myClass.getClass());
 
       SerializableMethod copyOfSerializableMethod_nonSerilizableParam = (SerializableMethod) SerializationUtil
             .getCopy(serializableMethod_nonSerializableParam);
@@ -292,17 +301,20 @@
       Method toStringMethodOfThisClass = this.getClass().getMethod("toString", (Class<?>[]) null);
       Method toStringMethodOfObject = Object.class.getMethod("toString", (Class<?>[]) null);
 
-      SerializableMethod serializableMethod_toStringOfThisClass = new SerializableMethod(toStringMethodOfThisClass);
-      SerializableMethod serializableMethod_toStringOfObjectClass = new SerializableMethod(toStringMethodOfObject);
+      SerializableMethod serializableMethod_toStringOfThisClass = new SerializableMethod(toStringMethodOfThisClass,
+            myClass.getClass());
+      SerializableMethod serializableMethod_toStringOfObjectClass = new SerializableMethod(toStringMethodOfObject,
+            Object.class);
 
       // test equals
-      assertTrue("Failure - Two SerializableMethod instances of method belonging to the same base class are not equal",
-            serializableMethod_toStringOfObjectClass.equals(serializableMethod_toStringOfThisClass));
+      assertTrue(
+            "Failure - Two SerializableMethod instances of method belonging to the same base class must not be equal",
+            !serializableMethod_toStringOfObjectClass.equals(serializableMethod_toStringOfThisClass));
 
       // test hashCode
-      assertEquals(
-            "Failure - Two SerializableMethod instances of method belonging to the same base class have different hashCode",
-            serializableMethod_toStringOfObjectClass.hashCode(), serializableMethod_toStringOfThisClass.hashCode());
+      assertTrue(
+            "Failure - Two SerializableMethod instances of method belonging to the same base class must have different hashCode",
+            serializableMethod_toStringOfObjectClass.hashCode() != serializableMethod_toStringOfThisClass.hashCode());
 
       // Test that the SerializableMethod instances created
       // for overridden methods are NOT equal
@@ -312,8 +324,8 @@
       Method methodFromParentClass = MyClass.class.getDeclaredMethod("methodWithParamAndReturningVoid", new Class[]
       {Integer.class});
 
-      SerializableMethod serializableMethodForChild = new SerializableMethod(methodFromChildClass);
-      SerializableMethod serializableMethodForParent = new SerializableMethod(methodFromParentClass);
+      SerializableMethod serializableMethodForChild = new SerializableMethod(methodFromChildClass, MyChildClass.class);
+      SerializableMethod serializableMethodForParent = new SerializableMethod(methodFromParentClass, MyClass.class);
 
       // test equals
       assertFalse("Failure - The SerializableMethod instances of method from base class and child class are equal",
@@ -339,8 +351,8 @@
       Method anotherGenericMethod = myClass.getClass().getMethod("methodWithGenerics", new Class[]
       {List.class, int.class});
 
-      SerializableMethod serializableMethod = new SerializableMethod(genericsMethod);
-      SerializableMethod anotherSerializableMethod = new SerializableMethod(anotherGenericMethod);
+      SerializableMethod serializableMethod = new SerializableMethod(genericsMethod, myClass.getClass());
+      SerializableMethod anotherSerializableMethod = new SerializableMethod(anotherGenericMethod, myClass.getClass());
 
       // test equals
       assertTrue("Failure - Two SerializableMethod instances for a method involving generics are not equal",
@@ -370,7 +382,7 @@
       Method methodWithoutPrimitivesParams = myClass.getClass().getMethod("methodWithParamAndReturningVoid",
             new Class[]
             {Integer.class});
-      SerializableMethod serializableMethod = new SerializableMethod(methodWithoutPrimitivesParams);
+      SerializableMethod serializableMethod = new SerializableMethod(methodWithoutPrimitivesParams, myClass.getClass());
       // invoke the toMethod()
       Method copyOfMethodWithoutPrimitiveParams = serializableMethod.toMethod();
 
@@ -404,7 +416,7 @@
 
       Method methodWithGenerics = myClass.getClass().getMethod("methodWithGenerics", new Class[]
       {List.class, int.class});
-      SerializableMethod serializableMethod = new SerializableMethod(methodWithGenerics);
+      SerializableMethod serializableMethod = new SerializableMethod(methodWithGenerics, myClass.getClass());
 
       Method copyOfMethodWithGenerics = serializableMethod.toMethod();
 
@@ -437,7 +449,7 @@
 
       Method method = myClass.getClass().getMethod("methodWithPrimitiveParamsAndReturningVoid", new Class[]
       {byte.class, short.class, int.class, long.class, char.class, float.class, double.class, boolean.class});
-      SerializableMethod serializableMethod = new SerializableMethod(method);
+      SerializableMethod serializableMethod = new SerializableMethod(method, myClass.getClass());
       // invoke the toMethod()
       Method copyOfMethod = serializableMethod.toMethod();
 
@@ -467,7 +479,7 @@
 
       Method methodReturningInteger = myClass.getClass().getMethod("methodReturingInteger", new Class[]
       {Integer.class});
-      SerializableMethod serializableMethod = new SerializableMethod(methodReturningInteger);
+      SerializableMethod serializableMethod = new SerializableMethod(methodReturningInteger, myClass.getClass());
       // invoke the toMethod()
       Method copyOfMethodReturingInteger = serializableMethod.toMethod();
 
@@ -501,7 +513,8 @@
       Method methodAcceptingArrayOfPrimitives = myClass.getClass().getMethod("methodAcceptingArrayOfPrimitives",
             new Class[]
             {int[].class});
-      SerializableMethod serializableMethod = new SerializableMethod(methodAcceptingArrayOfPrimitives);
+      SerializableMethod serializableMethod = new SerializableMethod(methodAcceptingArrayOfPrimitives, myClass
+            .getClass());
       // invoke the toMethod()
       Method copyOfMethodAcceptingArrayOfPrimitives = serializableMethod.toMethod();
 
@@ -523,7 +536,8 @@
 
       Method methodAcceptingArrayOfObjects = myClass.getClass().getMethod("methodAcceptingArrayOfObjects", new Class[]
       {Object[].class});
-      SerializableMethod serializableMethod_arrayOfObjParams = new SerializableMethod(methodAcceptingArrayOfObjects);
+      SerializableMethod serializableMethod_arrayOfObjParams = new SerializableMethod(methodAcceptingArrayOfObjects,
+            myClass.getClass());
       //invoke the toMethod()
       Method copyOfMethodAcceptingArrayOfObjects = serializableMethod_arrayOfObjParams.toMethod();
 
@@ -554,10 +568,14 @@
 
       Method method = myClass.getClass().getMethod("methodAcceptingMyClass", new Class[]
       {MyClass.class});
-      SerializableMethod serializableMethod = new SerializableMethod(method);
+      Method methodToString = myClass.getClass().getMethod("toString", new Class[]
+      {});
+      SerializableMethod serializableMethod = new SerializableMethod(method, myClass.getClass());
+      SerializableMethod serializableMethodToString = new SerializableMethod(methodToString, myClass.getClass());
 
       // invoke toMethod
       Method copyOfMethod = serializableMethod.toMethod(this.getClass().getClassLoader());
+      Method copyOfMethodToString = serializableMethodToString.toMethod(this.getClass().getClassLoader());
 
       // test equals 
       assertTrue("Failure - equals fails with classsloader passed to toMethod", method.equals(copyOfMethod));
@@ -566,6 +584,9 @@
       assertEquals("Failure - hashCode does not match when classloader is passed to toMethod", method.hashCode(),
             copyOfMethod.hashCode());
 
+      // test toString
+      assertEquals("Roundtrip of inherited method toString failed",copyOfMethodToString, methodToString);
+
       logger.info("Completed testing the toMethod(Classloader)");
 
    }
@@ -588,7 +609,7 @@
       Method method = myClass.getClass().getMethod("methodAcceptingMyClass", new Class[]
       {MyClass.class});
 
-      SerializableMethod serializableMethod = new SerializableMethod(method);
+      SerializableMethod serializableMethod = new SerializableMethod(method, myClass.getClass());
 
       // now make a copy through serialization/de-serialization
       SerializableMethod copyOfSerializableMethod = (SerializableMethod) SerializationUtil.getCopy(serializableMethod);




More information about the jboss-cvs-commits mailing list