Skip to content

Commit

Permalink
Changed the way class loaders are retrieved...experimental and needs …
Browse files Browse the repository at this point in the history
…testing in JBoss AS
  • Loading branch information
drallen committed May 3, 2010
1 parent b199f15 commit f5c2192
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
Expand Up @@ -18,6 +18,7 @@
package org.jboss.weld.bean.proxy.util;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
Expand All @@ -39,14 +40,24 @@ public class SimpleProxyServices implements ProxyServices

public ClassLoader getClassLoader(Class<?> type)
{
if (type.getName().startsWith("java"))
{
return this.getClass().getClassLoader();
}
else
{
return type.getClassLoader();
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
} else {
return Thread.currentThread().getContextClassLoader();
}
// if (type.getName().startsWith("java"))
// {
// return this.getClass().getClassLoader();
// }
// else
// {
// return type.getClassLoader();
// }
}

public ProtectionDomain getProtectionDomain(Class<?> type)
Expand Down Expand Up @@ -81,7 +92,8 @@ public Class<?> loadProxySuperClass(final String className)
{
public Object run() throws Exception
{
ClassLoader cl = Thread.currentThread().getContextClassLoader();
//ClassLoader cl = Thread.currentThread().getContextClassLoader();
ClassLoader cl = getClassLoader(this.getClass());
return Class.forName(className, true, cl);
}
});
Expand Down
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.weld.mock.cluster;

/**
* Class loader (CL) used during cluster tests so that proxies are not loaded into the
* CL being used by the test framework.
*
* @author David Allen
*
*/
public class ClusterClassLoader extends ClassLoader
{
public ClusterClassLoader(ClassLoader parentClassLoader)
{
super(parentClassLoader);
}
}

0 comments on commit f5c2192

Please sign in to comment.