Class DefaultClasspathScanner

java.lang.Object
cz.cvut.kbss.jopa.loaders.DefaultClasspathScanner
All Implemented Interfaces:
ClasspathScanner

public class DefaultClasspathScanner extends Object implements ClasspathScanner
Processes classes available to the current classloader.
  • Field Details

  • Constructor Details

    • DefaultClasspathScanner

      public DefaultClasspathScanner()
  • Method Details

    • addListener

      public void addListener(Consumer<Class<?>> listener)
      Description copied from interface: ClasspathScanner
      Registers a listener to which discovered classes will be passed for processing.
      Specified by:
      addListener in interface ClasspathScanner
      Parameters:
      listener - Listener to invoke with discovered classes
    • processClasses

      public void processClasses(String scanPackage)
      Specified by:
      processClasses in interface ClasspathScanner
      Parameters:
      scanPackage - Package to scan
    • processElements

      protected void processElements(Enumeration<URL> urls, String scanPath) throws IOException
      Throws:
      IOException
    • sanitizePath

      protected static String sanitizePath(URL url)
      Handles possible non-ascii character encoding in the specified URL.
      Parameters:
      url - Resource URL (presumably leading to a local file)
      Returns:
      Decoded argument
    • isJar

      protected static boolean isJar(String filePath)
    • createJarFile

      protected static JarFile createJarFile(URL elementUrl) throws IOException
      Throws:
      IOException
    • processJarFile

      protected void processJarFile(JarFile jarFile)
      Processes the specified JarFile, looking for classes in the configured package.
      Parameters:
      jarFile - JAR file to scan
    • processClass

      protected void processClass(String className)
      Retrieves a Class with the specified name and passes it to the registered listeners.
      Parameters:
      className - Fully-qualified class name
    • processDirectory

      protected void processDirectory(File dir, String packageName) throws IOException
      Processes the specified directory, looking for classes in the specified package (and its descendants).
      Parameters:
      dir - Directory
      packageName - Package name
      Throws:
      IOException