1 package org.opendaylight.controller.sal.binding.impl.osgi;
5 import java.util.concurrent.Callable;
6 import static com.google.common.base.Preconditions.*;
8 public class ClassLoaderUtils {
10 public static <V> V withClassLoader(ClassLoader cls,Callable<V> function) throws Exception {
12 checkNotNull(function);
13 ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
15 Thread.currentThread().setContextClassLoader(cls);
16 V result = function.call();
17 Thread.currentThread().setContextClassLoader(oldCls);
19 } catch (Exception e) {
20 Thread.currentThread().setContextClassLoader(oldCls);
21 throw new Exception(e);