Class AbstractClassLoader

java.lang.Object
java.lang.ClassLoader
org.frankframework.configuration.classloaders.AbstractClassLoader
All Implemented Interfaces:
IConfigurationClassLoader, org.springframework.beans.factory.DisposableBean, org.springframework.core.SmartClassLoader
Direct Known Subclasses:
AbstractBytesClassLoader, DirectoryClassLoader, DummyClassLoader, WebAppClassLoader

public abstract class AbstractClassLoader extends ClassLoader implements IConfigurationClassLoader
Abstract base class for IBIS Configuration ClassLoaders. Appends a BasePath to every resource when set. This allows the use of sub config's in src/main/resources When a file with prepended BasePath cannot be found it will traverse through it's classpath to find it.
Author:
Niels Meijer
  • Field Details

    • log

      protected org.apache.logging.log4j.Logger log
  • Constructor Details

    • AbstractClassLoader

      protected AbstractClassLoader()
    • AbstractClassLoader

      protected AbstractClassLoader(@Nullable ClassLoader parent)
  • Method Details

    • configure

      public void configure(@Nullable IbisContext ibisContext, @NonNull String configurationName) throws ClassLoaderException
      Description copied from interface: IConfigurationClassLoader
      Configure the IConfigurationClassLoader's implementation
      Specified by:
      configure in interface IConfigurationClassLoader
      Throws:
      ClassLoaderException - when the IConfigurationClassLoader's implementation cannot retrieve or load the configuration files
    • setBasePath

      public void setBasePath(String basePath)
      Sets the path prefix used when getLocalResource() is called.
      Parameters:
      basePath - path to use, defaults to the configuration name
    • getBasePath

      protected String getBasePath()
      The root directory where all resources are located. This may purely be used within the ClassLoader and resources should not be aware of this 'root' directory.

      The basePath can be determined from the configurationName if this includes a directory, or it's the name itself.

      For example:
      /myPath/to/configuration.xml becomes basePath='/myPath/to/' and configurationFile=configuration.xml
      /myPath/my-configuration.xml becomes basePath='/myPath/' and configurationFile=my-configuration.xml

      Returns:
      the path prefix that is used for retrieving files through this ClassLoader
    • getConfigurationName

      public @NonNull String getConfigurationName()
      Description copied from interface: IConfigurationClassLoader
      Retrieve the name of the configuration that uses this IConfigurationClassLoader
      Specified by:
      getConfigurationName in interface IConfigurationClassLoader
    • getConfigurationFile

      public String getConfigurationFile()
      The configurationFile should only ever be found in the current classloader and never in its parent
    • setConfigurationFile

      public void setConfigurationFile(String configurationFile)
    • getIbisManager

      protected IbisManager getIbisManager()
      Only for internal use within ClassLoaders Retrieve the IbisContext from the ClassLoader which is set when the configure method is called
    • setReportLevel

      public void setReportLevel(@NonNull String level)
      Description copied from interface: IConfigurationClassLoader
      Defines the log level for errors caused by the configure method
      Specified by:
      setReportLevel in interface IConfigurationClassLoader
      Parameters:
      level - ReportLevel in string format to be parsed by the ClassLoaderFactory digester
    • getReportLevel

      public @NonNull IConfigurationClassLoader.ReportLevel getReportLevel()
      Specified by:
      getReportLevel in interface IConfigurationClassLoader
      Returns:
      the IConfigurationClassLoader.ReportLevel set for this IConfigurationClassLoader
    • setAllowCustomClasses

      public void setAllowCustomClasses(boolean allow)
    • getAllowCustomClasses

      protected boolean getAllowCustomClasses()
    • getResource

      public final @Nullable URL getResource(@Nullable String name)
      Override this method and make it final so nobody can overwrite it. Implementations of this class should use getLocalResource(String)
      Specified by:
      getResource in interface IConfigurationClassLoader
      Overrides:
      getResource in class ClassLoader
    • getLocalResource

      protected abstract @Nullable URL getLocalResource(@NonNull String name)
      Parameters:
      name - of the file to search for in the current local classpath
      Returns:
      the URL of the file if found in the ClassLoader or null when the file cannot be found
    • getResource

      public @Nullable URL getResource(@Nullable String name, boolean useParent)
      In case of the getResources(String) we only want the local paths and not the parent path
      Parameters:
      name - of the file to retrieve
      useParent - only use local classpath or also traverse down the classpath
      Returns:
      the URL of the file if found in the ClassLoader or null
    • getResources

      public final @NonNull Enumeration<URL> getResources(@NonNull String name) throws IOException
      Overrides:
      getResources in class ClassLoader
      Throws:
      IOException
    • loadClass

      protected @NonNull Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • publicDefineClass

      public @NonNull Class<?> publicDefineClass(@NonNull String name, byte @NonNull [] b, @Nullable ProtectionDomain protectionDomain)

      Partially fixes --add-opens=java.base/java.lang=ALL-UNNAMED problem when loading classes dynamically when CGLIB is enabled. Full solution will require the base classloaders to also implement this interface, which they currently don't. See spring github for more background information.

      Specified by:
      publicDefineClass in interface org.springframework.core.SmartClassLoader
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
    • toString

      public String toString()
      Overrides:
      toString in class Object