org.knopflerfish.util
public class ClassLoaderUtil extends java.lang.Object
| Constructor and Description |
|---|
ClassLoaderUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object |
doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedAction<java.lang.Object> action)
Run the specified action in a specified ContextClassLoader.
|
static java.lang.Object |
doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedExceptionAction<java.lang.Object> action)
Run the specified action in a specified ContextClassLoader.
|
public static java.lang.Object doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedAction<java.lang.Object> action)
The doContextClassLoader sets the current thread's context class loader to the specified classloader, calls the action's run method, resets the thread's context class loader and finally returns the resulting value.
Example:
Object result = ClassLoaderUtil
.doContextClassLoader(Activator.getClass().getClassLoader(),
new PrivilegedAction() {
public Object run() {
// Use external library
// ...
return someresult;
}
};
where Activator is the bundle activator, or any other class
loaded by the bundle class loader.
classloader - Class loader to be used as the thread's context class loader.action - Action code to run in the specified class loader.public static java.lang.Object doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedExceptionAction<java.lang.Object> action)
throws java.lang.Exception
As above, but accepts and rethrows exceptions from the action.
classloader - Class loader to be used as the thread's context class loader.action - Action code to run in the specified class loader.java.lang.Exception - if action.run throws an exception, pass this
upwards