/activeobjects-plugin/src/main/java/com/atlassian/activeobjects/osgi/LoadClassFromBundleFunction.java

https://bitbucket.org/activeobjects/ao-plugin · Java · 23 lines · 18 code · 5 blank · 0 comment · 0 complexity · e954b87a4d038c478d383b3f1f0dba1c MD5 · raw file

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