Class AbstractClassFinder

java.lang.Object
org.ocpsoft.rewrite.annotation.scan.AbstractClassFinder
All Implemented Interfaces:
org.ocpsoft.common.pattern.Weighted, ClassFinder
Direct Known Subclasses:
WebClassesFinder, WebLibFinder

public abstract class AbstractClassFinder extends Object implements ClassFinder
Base class for implementations of the ClassFinder interface.
Author:
Christian Kaltepoth
See Also:
  • Field Details

    • log

      protected final org.ocpsoft.logging.Logger log
      Common logger for all implementations
    • servletContext

      protected final jakarta.servlet.ServletContext servletContext
      The ServletContext
    • classLoader

      protected final ClassLoader classLoader
      The ClassLoader to get classes from
    • packageFilter

      protected final PackageFilter packageFilter
      The filter for checking which classes to process
  • Constructor Details

    • AbstractClassFinder

      public AbstractClassFinder(jakarta.servlet.ServletContext servletContext, ClassLoader classLoader, PackageFilter packageFilter, ByteCodeFilter byteCodeFilter)
      Initialization procedure
      Parameters:
      servletContext - The ServletContext of the web application.
      classLoader - The ClassLoader to use for loading classes
      packageFilter - The PackageFilter used to check if a package has to be scanned.
  • Method Details

    • stripKnownPrefix

      protected String stripKnownPrefix(String str, String prefix)
      Strip everything up to and including a given prefix from a string.
      Parameters:
      str - The string to process
      prefix - The prefix
      Returns:
      the stripped string or null if the prefix has not been found
    • getClassName

      protected static String getClassName(String filename)

      Creates a FQCN from an URL representing a .class file.

      Parameters:
      url - The path of the class file
      Returns:
      the FQCN of the class
    • mustProcessClass

      protected boolean mustProcessClass(String className)
      Checks if a supplied class has to be processed by checking the package name against the PackageFilter.
      Parameters:
      className - FQCN of the class
      Returns:
      true for classes to process, false for classes to ignore
    • processClass

      protected void processClass(String className, InputStream classFileStream, ClassVisitor visitor)

      Handle a single class to process. This method should only be called if the class name is accepted by the PackageFilter.

      If classFileStream is not null the method will first try to check whether the class files may contain annotations by scanning it with the ByteCodeFilter. If no InputStream is supplied, this check will be skipped. After that the method will create an instance of the class and then call ClassVisitor#visit(Class, org.ocpsoft.prettyfaces.annotation.PrettyConfig).

      Please not the the called of this method is responsible to close the supplied InputStream!

      Parameters:
      className - The FQCN of the class
      classFileStream - The Java class file of the class (may be null)
      visitor - the visitor