|
Knopflerfish OSGi 1.3.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knopflerfish.util.ClassLoaderUtil
Utility class for handling common class loading cases, like wrapping external libraries in the correct context class loader.
Constructor Summary | |
ClassLoaderUtil()
|
Method Summary | |
static java.lang.Object |
doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedAction action)
Run the specified action in a specified ContextClassLoader. |
static java.lang.Object |
doContextClassLoader(java.lang.ClassLoader classloader,
java.security.PrivilegedExceptionAction action)
Run the specified action in a specified ContextClassLoader. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ClassLoaderUtil()
Method Detail |
public static java.lang.Object doContextClassLoader(java.lang.ClassLoader classloader, java.security.PrivilegedAction 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 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
|
Knopflerfish OSGi 1.3.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |