[jboss-cvs] JBossAS SVN: r66461 - branches/Branch_4_2/server/src/main/org/jboss/naming.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 25 17:59:19 EDT 2007


Author: dimitris at jboss.org
Date: 2007-10-25 17:59:19 -0400 (Thu, 25 Oct 2007)
New Revision: 66461

Modified:
   branches/Branch_4_2/server/src/main/org/jboss/naming/ExternalContext.java
Log:
JBAS-4753, avoid passing duplicate interfaces when creating Proxies.

Modified: branches/Branch_4_2/server/src/main/org/jboss/naming/ExternalContext.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/ExternalContext.java	2007-10-25 21:56:30 UTC (rev 66460)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/ExternalContext.java	2007-10-25 21:59:19 UTC (rev 66461)
@@ -24,17 +24,16 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
-
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-
 import java.net.URL;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Properties;
+import java.util.Set;
 
 import javax.naming.CompositeName;
 import javax.naming.Context;
@@ -48,7 +47,6 @@
 import javax.naming.spi.ObjectFactory;
 
 import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.util.Classes;
 
 /**
  * A MBean that binds an arbitrary InitialContext into the JBoss default
@@ -512,13 +510,35 @@
          this.externalCtx = externalCtx;
       }
 
+      /**
+       * Returns an array containing all the unique interfaces implemented
+       * by the argument class c and all its superclasses. Interfaces that
+       * appear multiple times through inheritence are only accounted for once.
+       * 
+       * @param c - the class to start scanning for interfaces
+       */   
+      private static Class[] getAllUniqueInterfaces(Class c)
+      {
+         Set uniqueIfaces = new HashSet();
+         while (c != null )
+         {
+            Class[] ifaces = c.getInterfaces();
+            for (int n = 0; n < ifaces.length; n ++)
+            {
+               uniqueIfaces.add(ifaces[n]);
+            }
+            c = c.getSuperclass();
+         }
+         return (Class[])uniqueIfaces.toArray(new Class[uniqueIfaces.size()]);
+      }
+      
       static Context createProxyContext(Context ctx)
       {
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
-         ArrayList<Class> ifaces = new ArrayList<Class>();
-         Classes.getAllInterfaces(ifaces, ctx.getClass());
-         Class[] interfaces = new Class[ifaces.size()];
-         ifaces.toArray(interfaces);
+         // TODO, JBAS-4753 - remove the above method and replace the following
+         // line with a call to org.jboss.util.Classes.getAllUniqueInterfaces()
+         // when the next jboss-common release is made available.
+         Class[] interfaces = getAllUniqueInterfaces(ctx.getClass());
          InvocationHandler handler = new CachedContext(ctx);
          Context proxyCtx = (Context) Proxy.newProxyInstance(loader, interfaces, handler);
          return proxyCtx;




More information about the jboss-cvs-commits mailing list