Package org.jboss.util.loading
Class ContextClassLoaderSwitcher
- java.lang.Object
-
- org.jboss.util.loading.ContextClassLoader
-
- org.jboss.util.loading.ContextClassLoaderSwitcher
-
public class ContextClassLoaderSwitcher extends ContextClassLoader
A helper for context classloading switching.When a security manager is installed, the constructor checks for the runtime permissions "getClassLoader" and "setContextClassLoader". This allows the methods of this class to be used later without having to run in privileged blocks. There are optimized methods to perform the operations within a switch context. This avoids retrieving the current thread on every operation.
- Version:
- $Revision$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ContextClassLoaderSwitcher.NewInstance
class
ContextClassLoaderSwitcher.SwitchContext
A helper class to remember the original classloader and avoid continually retrieveing the current thread.
-
Field Summary
Fields Modifier and Type Field Description static ContextClassLoaderSwitcher.NewInstance
INSTANTIATOR
Instantiate a new context class loader switcherstatic java.lang.RuntimePermission
SETCONTEXTCLASSLOADER
Set the context classloader permission-
Fields inherited from class org.jboss.util.loading.ContextClassLoader
GETCLASSLOADER
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ContextClassLoaderSwitcher()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ContextClassLoaderSwitcher.SwitchContext
getSwitchContext()
Retrieve a switch contextContextClassLoaderSwitcher.SwitchContext
getSwitchContext(java.lang.Class clazz)
Deprecated.using a class to determine the classloader is a bad idea, it has the same problems as Class.forName()ContextClassLoaderSwitcher.SwitchContext
getSwitchContext(java.lang.ClassLoader cl)
Retrieve a switch context and set the new context classloadervoid
setContextClassLoader(java.lang.ClassLoader cl)
Set the context classloadervoid
setContextClassLoader(java.lang.Thread thread, java.lang.ClassLoader cl)
Set the context classloader for the given thread-
Methods inherited from class org.jboss.util.loading.ContextClassLoader
getContextClassLoader, getContextClassLoader
-
-
-
-
Field Detail
-
SETCONTEXTCLASSLOADER
public static final java.lang.RuntimePermission SETCONTEXTCLASSLOADER
Set the context classloader permission
-
INSTANTIATOR
public static final ContextClassLoaderSwitcher.NewInstance INSTANTIATOR
Instantiate a new context class loader switcher
-
-
Method Detail
-
setContextClassLoader
public void setContextClassLoader(java.lang.ClassLoader cl)
Set the context classloader- Parameters:
cl
-
-
setContextClassLoader
public void setContextClassLoader(java.lang.Thread thread, java.lang.ClassLoader cl)
Set the context classloader for the given thread- Parameters:
thread
- the threadcl
- the new context classloader
-
getSwitchContext
public ContextClassLoaderSwitcher.SwitchContext getSwitchContext()
Retrieve a switch context- Returns:
- the switch context
-
getSwitchContext
public ContextClassLoaderSwitcher.SwitchContext getSwitchContext(java.lang.ClassLoader cl)
Retrieve a switch context and set the new context classloader- Parameters:
cl
- the new classloader- Returns:
- the switch context
-
getSwitchContext
public ContextClassLoaderSwitcher.SwitchContext getSwitchContext(java.lang.Class clazz)
Deprecated.using a class to determine the classloader is a bad idea, it has the same problems as Class.forName()Retrieve a switch context for the classloader of a given class- Parameters:
clazz
- the class whose classloader should be set as the context classloader- Returns:
- the switch context
-
-