PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): Apache-2.0
 1package com.atlassian.activeobjects.osgi;
 2
 3import com.google.common.base.Function;
 4import org.osgi.framework.Bundle;
 5
 6import static com.google.common.base.Preconditions.checkNotNull;
 7
 8class 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}