Class SourceClassLoader

java.lang.Object
java.lang.ClassLoader
ch.grengine.load.SourceClassLoader
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
BytecodeClassLoader, LayeredClassLoader

public abstract class SourceClassLoader extends ClassLoader implements Cloneable
Abstract class loader that can load the main and other classes of a source.
Since:
1.0
Author:
Alain Stalder, Made in Switzerland.
  • Constructor Details

    • SourceClassLoader

      public SourceClassLoader(ClassLoader parent)
      constructor from parent class loader.
      Parameters:
      parent - parent class loader
      Since:
      1.0
  • Method Details

    • loadMainClass

      public abstract Class<?> loadMainClass(Source source)
      loads the main class of the given source.

      First searches for the source, then loads the main class that resulted from compiling the source.

      Parameters:
      source - source
      Returns:
      main class
      Throws:
      CompileException - if compilation was necessary to load the class and failed
      LoadException - if loading failed, including if the class was not found
      Since:
      1.0
    • loadClass

      public abstract Class<?> loadClass(Source source, String name)
      loads a class with the given name and from the given source.

      First searches for the source, only then for the class with given name as part of the classes that resulted from compiling the source.

      Parameters:
      source - source
      name - class name
      Returns:
      class
      Throws:
      CompileException - if compilation was necessary to load the class and failed
      LoadException - if loading failed, including if the class was not found
      Since:
      1.0
    • findBytecodeClassLoaderBySource

      public abstract BytecodeClassLoader findBytecodeClassLoaderBySource(Source source)
      tries to find the bytecode class loader that can load classes that were created by compiling the given source.
      Parameters:
      source - source
      Returns:
      bytecode class loader if found, null otherwise
      Since:
      1.0
    • getLoadMode

      public abstract LoadMode getLoadMode()
      gets the load mode.
      Returns:
      load mode
      Since:
      1.0
    • clone

      public abstract SourceClassLoader clone()
      creates a clone with identical behavior, typically sharing the same bytecode.
      Overrides:
      clone in class Object
      Returns:
      clone
      Since:
      1.0
    • releaseClasses

      public abstract void releaseClasses(ClassReleaser releaser)
      release metadata for all classed ever loaded by this class loader.

      Allows to remove metadata associated by Groovy (or Java) with a class, which is often necessary to get on-the-fly garbage collection.

      Generally call only when really done using this class loader and all loaded classes; subsequently trying to use this class loader or its classes results generally in undefined behavior.

      Parameters:
      releaser - class releaser
      Since:
      1.1