Skip to content

Commit

Permalink
fix SchemaLookup when not inside OSGi so we don't have a Bundle/Bundl…
Browse files Browse the repository at this point in the history
…eContext ##735
  • Loading branch information
jstrachan committed Nov 8, 2013
1 parent ca076a1 commit 046eb09
Showing 1 changed file with 22 additions and 7 deletions.
Expand Up @@ -7,6 +7,7 @@
import io.hawt.jsonschema.internal.BeanValidationAnnotationModule;
import io.hawt.jsonschema.internal.IgnorePropertiesBackedByTransientFields;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -67,15 +68,29 @@ protected String getDefaultObjectName() {
}

protected Class getClass(String name) {
Bundle[] bundles = FrameworkUtil.getBundle(getClass()).getBundleContext().getBundles();
for (Bundle bundle : bundles) {
if (bundle.getState() >= Bundle.RESOLVED) {
try {
return bundle.loadClass(name);
} catch (ClassNotFoundException e) {
// Ignore
BundleContext bundleContext = null;
Bundle currentBundle = FrameworkUtil.getBundle(getClass());
if (currentBundle != null) {
bundleContext = currentBundle.getBundleContext();
}
if (bundleContext != null) {
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
if (bundle.getState() >= Bundle.RESOLVED) {
try {
return bundle.loadClass(name);
} catch (ClassNotFoundException e) {
// Ignore
}
}
}
} else {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
LOG.warn("Failed to find class for {}", name);
throw new RuntimeException(e);
}
}
LOG.warn("Failed to find class for {}", name);
ClassNotFoundException e = new ClassNotFoundException(name);
Expand Down

0 comments on commit 046eb09

Please sign in to comment.