View Javadoc
1   package com.atlassian.activeobjects.osgi;
2   
3   import com.google.common.base.Function;
4   import org.osgi.framework.Bundle;
5   
6   import static com.google.common.base.Preconditions.checkNotNull;
7   
8   class LoadClassFromBundleFunction implements Function<String, Class> {
9       private final Bundle bundle;
10  
11      LoadClassFromBundleFunction(Bundle bundle) {
12          this.bundle = checkNotNull(bundle);
13      }
14  
15      @Override
16      public Class<?> apply(String className) {
17          try {
18              return bundle.loadClass(className);
19          } catch (ClassNotFoundException e) {
20              throw new IllegalStateException("How did this happen? We're loading class '" + className + "'from the " + bundle, e);
21          }
22      }
23  }