Loader() {
super(null);
}
public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
PackageScanFilter test = new AnnotatedWithPackageScanFilter(Converter.class, true);
Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
Set<String> packages = getConverterPackages(bundle.getEntry(META_INF_TYPE_CONVERTER));
if (LOG.isTraceEnabled()) {
LOG.trace("Found {} {} packages: {}", new Object[]{packages.size(), META_INF_TYPE_CONVERTER, packages});
}
// if we only have camel-core on the classpath then we have already pre-loaded all its type converters
// but we exposed the "org.apache.camel.core" package in camel-core. This ensures there is at least one
// packageName to scan, which triggers the scanning process. That allows us to ensure that we look for
// META-INF/services in all the JARs.
if (packages.size() == 1 && "org.apache.camel.core".equals(packages.iterator().next())) {
LOG.debug("No additional package names found in classpath for annotated type converters.");
// no additional package names found to load type converters so break out
return;
}
// now filter out org.apache.camel.core as its not needed anymore (it was just a dummy)
packages.remove("org.apache.camel.core");
for (String pkg : packages) {
if (StringHelper.hasUpperCase(pkg)) {
// its a FQN class name so load it directly
LOG.trace("Loading {} class", pkg);
try {
Class<?> clazz = bundle.loadClass(pkg);
if (test.matches(clazz)) {
classes.add(clazz);
}
// the class could be found and loaded so continue to next
continue;
} catch (Throwable t) {
// Ignore
LOG.trace("Failed to load " + pkg + " class due " + t.getMessage() + ". This exception will be ignored.", t);
}
}
// its not a FQN but a package name so scan for classes in the bundle
Enumeration<URL> e = bundle.findEntries("/" + pkg.replace('.', '/'), "*.class", true);
while (e != null && e.hasMoreElements()) {
String path = e.nextElement().getPath();
String externalName = path.substring(path.charAt(0) == '/' ? 1 : 0, path.indexOf('.')).replace('/', '.');
LOG.trace("Loading {} class", externalName);
try {
Class<?> clazz = bundle.loadClass(externalName);
if (test.matches(clazz)) {
classes.add(clazz);
}
} catch (Throwable t) {
// Ignore
LOG.trace("Failed to load " + externalName + " class due " + t.getMessage() + ". This exception will be ignored.", t);