Package eu.bandm.tools.util.classes
Class ConfigurableClassLoader
java.lang.Object
java.lang.ClassLoader
eu.bandm.tools.util.classes.ConfigurableClassLoader
A class loader that mimics the
-classpath behavior of
java. It supports loading from local directories and
jar files, also honoring Class-Path manifest entries.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassDirectory in the file system from which a class can be loaded.classAbstract location from which a class can be loaded.classA jar archive from which a class can be loaded. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ConfigurableClassLoader(String... classpath) Constructor which sets up the sources for class loading according to its string atguments. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd one or more sources.voidExecutesaddSource(String)for all arguments.protected Class<?> Central point of service: return the loaded class object for the class with the given name.byte[]getClassData(String name) Central point of service: return all class data for the class with the given name.Get an unmodifiable copy of the directory of all classes which already have been delivered by this class loader.protected Class<?> sources()Returns all currently known sources to search for class files.protected voidwatchClass(String name, byte[] data) Callback-hook to be overwritten by a user for diagnosis.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
-
Field Details
-
sources
Internal list of all sources. These will be searched in sequential order for the first found class. -
local
Directory of all classes which already have been delivered by this class loader.
-
-
Constructor Details
-
ConfigurableClassLoader
public ConfigurableClassLoader()Default constructor. Its result has no source from which to load a class. At least one must be added by callingaddSource(String)oraddSource(String[])explicitly. -
ConfigurableClassLoader
Constructor which sets up the sources for class loading according to its string atguments. These are parsed as described withaddSource(String).- Parameters:
classpath- array of strings, each standing for places to load classes from.
-
-
Method Details
-
watchClass
Callback-hook to be overwritten by a user for diagnosis. Is called whenever a class is successfully loaded byfindClass(String). -
addSource
ExecutesaddSource(String)for all arguments.- Parameters:
classpath- list of strings, seeaddSource(String).
-
addSource
Add one or more sources. The string can have the format of a Java "-classpath" argument and will be split byFile.pathSeparatorChar. Otherwise it stands for one directory from which to load classes. If it stands for a single (non-directory) file, this must be a ".jar" file.- Parameters:
classpath- either a single source (directory or jar file) or multiples joined byFile.pathSeparatorChar
-
sources
Returns all currently known sources to search for class files. -
getLocalClasses
Get an unmodifiable copy of the directory of all classes which already have been delivered by this class loader. -
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
findClass
Central point of service: return the loaded class object for the class with the given name. All sources contained insourcesare searched in sequential order for the first hit, by calling theirfindClass(name)method is called.- Overrides:
findClassin classClassLoader- Parameters:
name- the "binary name" of the class to look for, see the discussion withClassLoader- Returns:
- the class object
- Throws:
ClassNotFoundException- if no class with the given name is found in any source.
-
getClassData
Central point of service: return all class data for the class with the given name. All sources contained insourcesare searched in sequential order for the first hit.- Parameters:
name- of the class to look for- Returns:
- the byte array containing the complete byte code of the class.
- Throws:
ClassNotFoundException- if no class with the given name is found in any source.
-