Package net.apartium.cocoabeans.reflect
Class MapClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
net.apartium.cocoabeans.reflect.MapClassLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
A
ClassLoader that defines a fixed set of classes provided at construction time from an
in-memory mapping of fully-qualified binary name to JVM bytecode.
Every entry in the classDefs map passed to the constructor is eagerly defined in this
loader via ClassLoader.defineClass(String, byte[], int, int). Subsequent lookups for
any of those classes through ClassLoader.loadClass(String) resolve to the Class defined
by this loader; any other name is delegated to the parent loader using
the standard parent-first model inherited from URLClassLoader.
This loader exposes no URLs — only the classes supplied at construction are available directly from it.
-
Constructor Summary
ConstructorsConstructorDescriptionMapClassLoader(ClassLoader parent, Map<String, ImmutableByteArrayList> classDefs) Constructs a newMapClassLoaderthat eagerly defines every entry ofclassDefsas a class loaded by this loader. -
Method Summary
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
MapClassLoader
Constructs a newMapClassLoaderthat eagerly defines every entry ofclassDefsas a class loaded by this loader.- Parameters:
parent- parent class loader for delegation; may benullto delegate to the bootstrap class loader (seeClassLoader(ClassLoader))classDefs- map of fully-qualified binary name (e.g."com.example.Foo") to the bytecode for that class. The map is consumed at construction; later modifications to the supplied map have no effect on this loader.- Throws:
ClassFormatError- if a bytecode entry is not a well-formed class fileNoClassDefFoundError- if a key inclassDefsdoes not match the binary name encoded inside the corresponding bytecode- See Also:
-