Package ch.grengine.load
Class BytecodeClassLoader
java.lang.Object
java.lang.ClassLoader
ch.grengine.load.SourceClassLoader
ch.grengine.load.BytecodeClassLoader
- All Implemented Interfaces:
Cloneable
Bytecode-based class loader that also implements the
SourceClassLoader
interface.
Loads classes based on given bytecode or from the parent class loader. Depending on the given load mode, the parent class loader is searched first or last.
- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
Constructor Summary
ConstructorsConstructorDescriptionBytecodeClassLoader(ClassLoader parent, LoadMode loadMode, Code code) constructor. -
Method Summary
Modifier and TypeMethodDescriptionclone()creates a clone with identical behavior, typically sharing the same bytecode.tries to find the bytecode class loader that can load classes that were created by compiling the given source.protected Class<?>getCode()gets the code.gets the load mode.Class<?>loads a class with the given name and from the given source.protected Class<?>static Class<?>loadClassBySourceAndName(ClassLoader classLoader, Source source, String name) Helper method for loading a class with the given name and from the given source from the given class loader.Class<?>loadMainClass(Source source) loads the main class of the given source.static Class<?>loadMainClassBySource(ClassLoader classLoader, Source source) Helper method for loading the main class of the given source from the given class loader.voidreleaseClasses(ClassReleaser releaser) release metadata for all classed ever loaded by this class loader.Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
BytecodeClassLoader
constructor.- Parameters:
parent- parent class loaderloadMode- load modecode- code with bytecode for one or more classes- Throws:
NullPointerException- if any of the arguments is null- Since:
- 1.0
-
-
Method Details
-
findClass
- Overrides:
findClassin classClassLoader- Throws:
ClassNotFoundException
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
loadMainClass
Description copied from class:SourceClassLoaderloads the main class of the given source.First searches for the source, then loads the main class that resulted from compiling the source.
- Specified by:
loadMainClassin classSourceClassLoader- Parameters:
source- source- Returns:
- main class
-
loadClass
Description copied from class:SourceClassLoaderloads 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.
- Specified by:
loadClassin classSourceClassLoader- Parameters:
source- sourcename- class name- Returns:
- class
-
findBytecodeClassLoaderBySource
Description copied from class:SourceClassLoadertries to find the bytecode class loader that can load classes that were created by compiling the given source.- Specified by:
findBytecodeClassLoaderBySourcein classSourceClassLoader- Parameters:
source- source- Returns:
- bytecode class loader if found, null otherwise
-
getLoadMode
Description copied from class:SourceClassLoadergets the load mode.- Specified by:
getLoadModein classSourceClassLoader- Returns:
- load mode
-
loadMainClassBySource
Helper method for loading the main class of the given source from the given class loader.- Parameters:
classLoader- class loadersource- source- Returns:
- main class
- Throws:
LoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
loadClassBySourceAndName
public static Class<?> loadClassBySourceAndName(ClassLoader classLoader, Source source, String name) Helper method for loading a class with the given name and from the given source from the given class loader.- Parameters:
classLoader- class loadersource- sourcename- class name- Returns:
- class
- Throws:
LoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
clone
Description copied from class:SourceClassLoadercreates a clone with identical behavior, typically sharing the same bytecode.- Specified by:
clonein classSourceClassLoader- Returns:
- clone
-
releaseClasses
Description copied from class:SourceClassLoaderrelease 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.
- Specified by:
releaseClassesin classSourceClassLoader- Parameters:
releaser- class releaser
-
getCode
gets the code.- Returns:
- code
- Since:
- 1.0
-