[jboss-cvs] JBossAS SVN: r66460 - trunk/server/src/main/org/jboss/naming.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 25 17:56:30 EDT 2007
Author: dimitris at jboss.org
Date: 2007-10-25 17:56:30 -0400 (Thu, 25 Oct 2007)
New Revision: 66460
Modified:
trunk/server/src/main/org/jboss/naming/ExternalContext.java
Log:
JBAS-4753, avoid passing duplicate interfaces when creating Proxies.
Modified: trunk/server/src/main/org/jboss/naming/ExternalContext.java
===================================================================
--- trunk/server/src/main/org/jboss/naming/ExternalContext.java 2007-10-25 21:53:53 UTC (rev 66459)
+++ trunk/server/src/main/org/jboss/naming/ExternalContext.java 2007-10-25 21:56:30 UTC (rev 66460)
@@ -1,24 +1,24 @@
/*
-* 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.
-*/
+ * 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.naming;
import java.io.IOException;
@@ -30,9 +30,10 @@
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;
@@ -46,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
@@ -513,13 +513,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