The delegation model used by this ClassLoader differs to the regular delegation model. When requested to load a class then this ClassLoader first maps the class name to its package name. If there a module defined to the Loader containing the package then the class loader attempts to load from that module. If the package is instead defined to a module in a "remote" ClassLoader then this class loader delegates directly to that class loader. The map of package name to remote class loader is created based on the modules read by modules defined to this class loader. If the package is not local or remote then this class loader will delegate to the parent class loader. This allows automatic modules (for example) to link to types in the unnamed module of the parent class loader.
ModuleLayer#defineModulesWithOneLoader, ModuleLayer#defineModulesWithManyLoaders
| Modifier and Type | Class and Description |
|---|---|
| private static class | Loader.
A module defined/loaded to a |
| private static class | Loader.
A ModuleReader that doesn't read any resources. |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final Map | |
| private final Map | |
| private final ClassLoader | |
| private final LoaderPool | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public | Loader(ResolvedModule resolvedModule, LoaderPool pool, ClassLoader parent)
Creates a |
| public | Loader(Collection<ResolvedModule> modules, ClassLoader parent)
Creates a |
| Modifier and Type | Method and Description |
|---|---|
| private ModuleReader | |
| protected Class | findClass(String cn)
Overrides java. Finds the class with the specified binary name. |
| protected Class | findClass(String mn, String cn)
Overrides java. Finds the class with the specified binary name in the given module. |
| private Class | Returns: the resulting Class ornull if not foundFinds the class with the specified binary name if in a module defined to this ClassLoader. |
| private Loader. | |
| private Optional | findModuleLayer(ModuleLayer parent, Configuration cf)
Find the layer corresponding to the given configuration in the tree of layers rooted at the given parent. |
| protected URL | findResource(String mn, String name)
Overrides java. Returns a URL to a resource of the given name in a module defined to this class loader. |
| public URL | findResource(String name)
Overrides java. Finds the resource with the given name. |
| public Enumeration | findResources(String name)
Overrides java. Returns an enumeration of |
| private List | |
| public URL | getResource(String name)
Overrides java. Finds the resource with the given name. |
| public Enumeration | getResources(String name)
Overrides java. Finds all the resources with the given name. |
| public Loader | initRemotePackageMap(Configuration
the Configuration containing at least modules to be defined to
this class loader cf, List<ModuleLayer> the parent ModuleLayers parentModuleLayers)Completes initialization of this Loader. |
| private boolean | isOpen(ModuleReference mref, String pn)
Returns true if the given module opens the given package unconditionally. |
| protected Class | loadClass(String cn, boolean resolve)
Overrides java. Loads the class with the specified binary name. |
| private ModuleReader | |
| private String | |
| public LoaderPool | pool()
Returns the loader pool that this loader is in or |
| private void | remotePackage(String pn, ClassLoader loader)
Adds to remotePackageToLoader so that an attempt to load a class in the package delegates to the given class loader. |
| localPackageToModule | back to summary |
|---|---|
| private final Map<String, Loader. | |
| moduleToReader | back to summary |
|---|---|
| private final Map<ModuleReference, ModuleReader> moduleToReader | |
| nameToModule | back to summary |
|---|---|
| private final Map<String, ModuleReference> nameToModule | |
| parent | back to summary |
|---|---|
| private final ClassLoader parent Hides java. | |
| pool | back to summary |
|---|---|
| private final LoaderPool pool | |
| remotePackageToLoader | back to summary |
|---|---|
| private final Map<String, ClassLoader> remotePackageToLoader | |
| Loader | back to summary |
|---|---|
| public Loader(ResolvedModule resolvedModule, LoaderPool pool, ClassLoader parent) Creates a | |
| Loader | back to summary |
|---|---|
| public Loader(Collection<ResolvedModule> modules, ClassLoader parent) Creates a
| |
| createModuleReader | back to summary |
|---|---|
| private ModuleReader createModuleReader(ModuleReference mref) Creates a ModuleReader for the given module. | |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Finds the class with the specified binary name.
| |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Finds the class with the specified binary name in the given module.
This method returns
| |
| findClassInModuleOrNull | back to summary |
|---|---|
| private Class Finds the class with the specified binary name if in a module defined to this ClassLoader.
| |
| findLoadedModule | back to summary |
|---|---|
| private Loader. Find the candidate module for the given class name.
Returns | |
| findModuleLayer | back to summary |
|---|---|
| private Optional Find the layer corresponding to the given configuration in the tree of layers rooted at the given parent. | |
| findResource | back to summary |
|---|---|
| protected URL findResource(String mn, String name) throws IOException Overrides java. Returns a URL to a resource of the given name in a module defined to this class loader.
| |
| findResource | back to summary |
|---|---|
| public URL findResource(String name) Overrides java. Doc from java. Finds the resource with the given name. Class loader implementations should override this method. For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| findResources | back to summary |
|---|---|
| public Enumeration Overrides java. Doc from java. Returns an enumeration of For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| findResourcesAsList | back to summary |
|---|---|
| private List Finds the resources with the given name in this class loader. | |
| getResource | back to summary |
|---|---|
| public URL getResource(String name) Overrides java. Doc from java. Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a ' Resources in named modules are subject to the encapsulation rules
specified by
| |
| getResources | back to summary |
|---|---|
| public Enumeration Overrides java. Doc from java. Finds all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a Resources in named modules are subject to the encapsulation rules
specified by
| |
| initRemotePackageMap | back to summary |
|---|---|
| public Loader initRemotePackageMap(Configuration cf, List<ModuleLayer> parentModuleLayers) Completes initialization of this Loader. This method populates remotePackageToLoader with the packages of the remote modules, where "remote modules" are the modules read by modules defined to this loader.
| |
| isOpen | back to summary |
|---|---|
| private boolean isOpen(ModuleReference mref, String pn) Returns true if the given module opens the given package unconditionally. Implementation Note This method currently iterates over each of the open packages. This will be replaced once the ModuleDescriptor.Opens API is updated. | |
| loadClass | back to summary |
|---|---|
| protected Class Overrides java. Loads the class with the specified binary name.
| |
| moduleReaderFor | back to summary |
|---|---|
| private ModuleReader moduleReaderFor(ModuleReference mref) Returns the ModuleReader for the given module. | |
| packageName | back to summary |
|---|---|
| private String packageName(String cn) Returns the package name for the given class name | |
| pool | back to summary |
|---|---|
| public LoaderPool pool() Returns the loader pool that this loader is in or | |
| remotePackage | back to summary |
|---|---|
| private void remotePackage(String pn, ClassLoader loader) Adds to remotePackageToLoader so that an attempt to load a class in the package delegates to the given class loader.
| |
Loader.
| Modifier and Type | Field and Description |
|---|---|
| private final CodeSource | |
| private final ModuleReference |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv CodeSource | |
| pack-priv ModuleReference | |
| pack-priv String |
| cs | back to summary |
|---|---|
| private final CodeSource cs | |
| mref | back to summary |
|---|---|
| private final ModuleReference mref | |
| LoadedModule | back to summary |
|---|---|
| pack-priv LoadedModule(ModuleReference mref) | |
| codeSource | back to summary |
|---|---|
| pack-priv CodeSource codeSource() | |
| mref | back to summary |
|---|---|
| pack-priv ModuleReference mref() | |
| name | back to summary |
|---|---|
| pack-priv String name() | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public Optional | find(String name)
Implements java. Finds a resource, returning a URI to the resource in the module. |
| public Stream | list()
Implements java. Lists the contents of the module, returning a stream of elements that are the names of all resources in the module. |
| NullModuleReader | back to summary |
|---|---|
| private NullModuleReader() | |
| close | back to summary |
|---|---|
| public void close() Implements java. Doc from java. Closes the module reader. Once closed then subsequent calls to locate or
read a resource will fail by throwing A module reader is not required to be asynchronously closeable. If a thread is reading a resource and another thread invokes the close method, then the second thread may block until the read operation is complete.
| |
| find | back to summary |
|---|---|
| public Optional Implements java. Doc from java. Finds a resource, returning a URI to the resource in the module. If the module reader can determine that the name locates a directory then the resulting URI will end with a slash ('/').
| |
| list | back to summary |
|---|---|
| public Stream Implements java. Doc from java. Lists the contents of the module, returning a stream of elements that are the names of all resources in the module. Whether the stream of elements includes names corresponding to directories in the module is module reader specific. In lazy implementations then an The returned stream may contain references to one or more open directories in the module. The directories are closed by closing the stream. The behavior of the stream when used after the module reader is closed is implementation specific and therefore not specified.
| |