private synchronized void registerActorClasses() { if (actorClasses.isEmpty()) { try { final ClassLoader classLoader = userClassLoader != null ? userClassLoader : this.getClass().getClassLoader(); ClassLoaderUtil.accept( (URLClassLoader) classLoader, new ClassLoaderUtil.Visitor() { @Override public final void visit(String resource, URL url, ClassLoader cl) { if (packagePrefixes != null) { boolean found = false; for (final String packagePrefix : packagePrefixes) { if (packagePrefix != null && resource.startsWith(packagePrefix.replace('.', '/'))) { found = true; break; } } if (!found) return; } if (!ClassLoaderUtil.isClassFile(resource)) return; final String className = ClassLoaderUtil.resourceToClass(resource); try (final InputStream is = cl.getResourceAsStream(resource)) { if (AnnotationUtil.hasClassAnnotation(WebActor.class, is)) registerWebActor(cl.loadClass(className)); } catch (final IOException | ClassNotFoundException e) { log.error( "Exception while scanning class " + className + " for WebActor annotation", e); throw new RuntimeException(e); } } private void registerWebActor(Class<?> c) { actorClasses.add(c); } }); } catch (final IOException e) { log.error("IOException while scanning classes for WebActor annotation", e); } } }
public static void accept(URLClassLoader ucl, Visitor visitor) throws IOException { accept(ucl, ucl.getURLs(), visitor); }