/** * Populates the entries list with recursively found class entries. * * @param bundle The bundle to get class entries for. * @param entries The list to add the class entries to. * @param startPath The start path to look for entries. */ protected void collectClassEntries(Bundle bundle, List<Class> entries, String startPath) { Enumeration<String> entryPathEnumeration = bundle.getEntryPaths(startPath); while (entryPathEnumeration.hasMoreElements()) { String entryPath = entryPathEnumeration.nextElement(); if (entryPath.endsWith("/")) { collectClassEntries(bundle, entries, entryPath); } else if (entryPath.endsWith(".class")) { try { String classQName = entryPath.substring(0, entryPath.length() - 6).replace(File.separatorChar, '.'); if (classQName.startsWith("WEB-INF.classes.")) { classQName = classQName.substring(16); } Class entryClass = bundle.loadClass(classQName); // If not activatorMode is true then there will be classes in this list already on the // first // call to this method. Therefore we skip duplicates. if (!entries.contains(entryClass)) { entries.add(entryClass); } } catch (ClassNotFoundException cnfe) { this.activatorLogger.warn("Failed to load bundle class!", cnfe); } catch (NoClassDefFoundError ncdfe) { this.activatorLogger.warn("Failed to load bundle class!", ncdfe); } } } }
@Override public Class<?> findClass(String name) throws ClassNotFoundException { for (Bundle b : bundles.values()) { try { return b.loadClass(name); } catch (ClassNotFoundException e) { // Ignore, try next } } throw new ClassNotFoundException(name); }