/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
- package com.atlassian.activeobjects.osgi;
- import com.google.common.base.Function;
- import org.osgi.framework.Bundle;
- import static com.google.common.base.Preconditions.checkNotNull;
- class LoadClassFromBundleFunction implements Function<String, Class> {
- private final Bundle bundle;
- LoadClassFromBundleFunction(Bundle bundle) {
- this.bundle = checkNotNull(bundle);
- }
- @Override
- public Class<?> apply(String className) {
- try {
- return bundle.loadClass(className);
- } catch (ClassNotFoundException e) {
- throw new IllegalStateException("How did this happen? We're loading class '" + className + "'from the " + bundle, e);
- }
- }
- }