You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by jc...@apache.org on 2006/05/06 19:04:44 UTC

svn commit: r400337 - /jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java

Author: jcarman
Date: Sat May  6 10:04:43 2006
New Revision: 400337

URL: http://svn.apache.org/viewcvs?rev=400337&view=rev
Log:
HiveMind LoggingInterceptor incompatible with proxies generated by outside means (CGLIB or Javassist)
PR: HIVEMIND-176

Modified:
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java?rev=400337&r1=400336&r2=400337&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java Sat May  6 10:04:43 2006
@@ -16,6 +16,7 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 
 /**
  * Static class containing utility methods.
@@ -106,13 +107,14 @@
     }
 
     /**
-     * Returns the class of an instance. However, if the instance is, in fact, a JDK proxy, returns
-     * the interfaceClass (because JDK proxies do not work with Javassist).
+     * Returns the class of an instance.  However, if the instance's class
+     * isn't compatible (externally generated, for instance), then 
+     * <code>interfaceClass</code> is returned instead.
      * 
      * @param instance
      *            the object instance to obtain a class from
      * @param interfaceClass
-     *            the interface class to return if the instance is a JDK proxy.
+     *            the interface class to return if the instance is not compatible
      */
     public static Class getInstanceClass(ClassFab classFab, Object instance, Class interfaceClass)
     {
@@ -124,6 +126,26 @@
         return instanceClass;
     }
 
+    /**
+     * Returns the class of an instance. However, if the instance is, in fact, a JDK proxy, returns
+     * the interfaceClass (because JDK proxies do not work with Javassist).
+     * 
+     * @param instance
+     *            the object instance to obtain a class from
+     * @param interfaceClass
+     *            the interface class to return if the instance is a JDK proxy.
+     * @deprecated Please use version which takes a ClassFab object.
+     */
+    public static Class getInstanceClass(Object instance, Class interfaceClass)
+    {
+        Class instanceClass = instance.getClass();
+
+        if (Proxy.isProxyClass(instanceClass))
+            return interfaceClass;
+
+        return instanceClass;
+    }
+    
     /**
      * Adds a method that does nothing. If the method returns a value, it will return null, 0 or
      * false (depending on the type).



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org