[jboss-cvs] JBossAS SVN: r95672 - in projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5: jbosscl and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 04:54:37 EDT 2009
Author: alesj
Date: 2009-10-28 04:54:37 -0400 (Wed, 28 Oct 2009)
New Revision: 95672
Modified:
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/RegisterModuleCallback.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/SecurityActions.java
Log:
At least remove the CL:toString hack.
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/RegisterModuleCallback.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/RegisterModuleCallback.java 2009-10-28 08:49:59 UTC (rev 95671)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/RegisterModuleCallback.java 2009-10-28 08:54:37 UTC (rev 95672)
@@ -21,12 +21,9 @@
*/
package org.jboss.classpool.plugins.as5;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import org.jboss.classloading.spi.dependency.ClassLoading;
@@ -44,9 +41,6 @@
*/
public class RegisterModuleCallback implements ModuleRegistry
{
- // TODO JBREFLECT-65 Remove ugly hack
- public static Map<String, WeakReference<ClassLoader>> CLASSLOADERS = new HashMap<String, WeakReference<ClassLoader>>();
-
Logger logger = Logger.getLogger(this.getClass());
private Set<Module> registeredModules = new HashSet<Module>();
@@ -75,9 +69,6 @@
public synchronized void registerModule(Module module)
{
logger.debug("Registering module " + module);
- // TODO JBREFLECT-65 Remove ugly hack
- ClassLoader classLoader = ClassLoading.getClassLoaderForModule(module);
- CLASSLOADERS.put(classLoader.toString(), new WeakReference<ClassLoader>(classLoader));
registeredModules.add(module);
unregisteredModules.remove(module);
}
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolFactory.java 2009-10-28 08:49:59 UTC (rev 95671)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/JBossClDelegatingClassPoolFactory.java 2009-10-28 08:54:37 UTC (rev 95672)
@@ -107,11 +107,11 @@
ClassLoaderDomain parentDomain = sys.getDomain(parentDomainName);
if (parentDomain == null)
{
- throw new RuntimeException("No domain found called: " + parentDomainName);
+ throw new RuntimeException("No domain found, domain name: " + parentDomainName);
}
parentPoolDomain = ClassPoolDomainRegistry.getInstance().getDomain(parentDomain);
}
- if (parentDomainName == null)
+ else
{
ClassLoader parentUnitLoader = registry.getParentUnitLoader(cl);
if (parentUnitLoader != null)
@@ -125,16 +125,19 @@
// JBREFLECT-65 fix hack
try
{
- ClassLoader loader = RegisterModuleCallback.CLASSLOADERS.get(domain.getParent().toString()).get();
+ ClassLoaderToLoaderAdapter cp2la = (ClassLoaderToLoaderAdapter)domain.getParent();
+ ClassLoader loader = SecurityActions.getClassLoader(cp2la);
ClassPool parentPool = ClassPoolRepository.getInstance().registerClassLoader(loader);
if (parentPool == null)
{
poolDomain = new JBossClClassPoolDomain(domain.getName(), parentPoolDomain, domain.getParentPolicy(), registry);
}
else
- poolDomain = new JBossClClassPoolDomain(domain.getName(), parentPool, domain.getParentPolicy(), registry);
+ {
+ poolDomain = new JBossClClassPoolDomain(domain.getName(), parentPool, domain.getParentPolicy(), registry);
+ }
}
- catch(NullPointerException npe)
+ catch(NullPointerException npe) // FIXME - ugh, since when are we handling code by catching NPEs?
{
poolDomain = new JBossClClassPoolDomain(domain.getName(), parentPoolDomain, domain.getParentPolicy(), registry);
}
Modified: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/SecurityActions.java 2009-10-28 08:49:59 UTC (rev 95671)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/plugins/as5/jbosscl/SecurityActions.java 2009-10-28 08:54:37 UTC (rev 95672)
@@ -18,45 +18,88 @@
* 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.classpool.plugins.as5.jbosscl;
+import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import org.jboss.classloader.spi.base.BaseClassLoaderSource;
+
/**
- *
+ * Security actions.
+ *
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision$
*/
class SecurityActions
{
-
- interface GetClassLoaderAction
+ private static final Method getClassLoader;
+
+ static
{
+ getClassLoader = AccessController.doPrivileged(new PrivilegedAction<Method>()
+ {
+ public Method run()
+ {
+ try
+ {
+ Method method = BaseClassLoaderSource.class.getDeclaredMethod("getClassLoader");
+ method.setAccessible(true);
+ return method;
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("Cannot get classloader from " + BaseClassLoaderSource.class.getName(), e);
+ }
+ }
+ });
+ }
+
+ static ClassLoader getClassLoader(BaseClassLoaderSource clSource)
+ {
+ try
+ {
+ return (ClassLoader)getClassLoader.invoke(clSource);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ interface GetClassLoaderAction
+ {
ClassLoader getClassLoader(Class<?> clazz);
-
- GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+ GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction()
+ {
public ClassLoader getClassLoader(Class<?> clazz)
{
return clazz.getClassLoader();
- }};
+ }
+ };
- GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+ GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction()
+ {
public ClassLoader getClassLoader(final Class<?> clazz)
{
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
public ClassLoader run()
{
return clazz.getClassLoader();
- }});
- }};
+ }
+ });
+ }
+ };
}
-
+
static ClassLoader getClassLoader(Class<?> clazz)
{
if (System.getSecurityManager() == null)
@@ -68,11 +111,11 @@
return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
}
}
-
+
public static class GetContextClassLoaderAction implements PrivilegedAction<ClassLoader>
{
public static GetContextClassLoaderAction INSTANCE = new GetContextClassLoaderAction();
-
+
public ClassLoader run()
{
return Thread.currentThread().getContextClassLoader();
@@ -86,5 +129,4 @@
else
return AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE);
}
-
}
More information about the jboss-cvs-commits
mailing list