Package jadex.platform.service.library
Class DelegationURLClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- jadex.platform.service.library.DelegationURLClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class DelegationURLClassLoader extends java.net.URLClassLoader
The delegation url classloader is responsible for managing a own resource plus a set of fixed delegate loaders.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoader
basecl
The base class loader.protected java.util.List<DelegationURLClassLoader>
delegates
The delegation classloader.protected java.util.Set<DelegationURLClassLoader>
dependencies
The flattened transitive dependencies without duplicates (created lazy from delegates list).protected java.util.List<DelegationURLClassLoader>
parents
The parent classloaders (i.e.protected IResourceIdentifier
rid
The resource identifier.
-
Constructor Summary
Constructors Constructor Description DelegationURLClassLoader(IResourceIdentifier rid, java.net.URL url, java.lang.ClassLoader basecl, DelegationURLClassLoader[] delegates)
Create a new classloader.DelegationURLClassLoader(java.lang.ClassLoader basecl, DelegationURLClassLoader[] delegates)
Create a new classloader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addDelegateClassLoader(DelegationURLClassLoader classloader)
Add a new delegate loader.boolean
addParentClassLoader(DelegationURLClassLoader parent)
Add a parent loader.static java.util.Set<DelegationURLClassLoader>
computeFlattenedDependencies(java.util.List<DelegationURLClassLoader> deps)
Get transitive dependencies as flattened set (without duplicates).protected java.net.URL
findDirectResource(java.lang.String name)
Find the resource.protected java.util.Enumeration<java.net.URL>
findDirectResources(java.lang.String name)
Find the resource.java.net.URL
findResource(java.lang.String name)
Find the resource.java.util.Enumeration<java.net.URL>
findResources(java.lang.String name)
Find the resource.static void
getAllParentLoaders(java.lang.ClassLoader cl, java.util.Set<java.lang.ClassLoader> cls)
java.util.Set<IResourceIdentifier>
getAllResourceIdentifiers()
Get all managed resource identifiers inlcuding all subdependencies.java.util.Set<java.net.URL>
getALLURLs()
Get transitive dependencies as flattened set (without duplicates).protected java.lang.ClassLoader
getBaseClassLoader()
DelegationURLClassLoader[]
getDelegateClassLoaders()
Get the delegates.java.util.List<IResourceIdentifier>
getDelegateResourceIdentifiers()
Get the delegates.java.util.List<DelegationURLClassLoader>
getDelegates()
Get the delegates.java.util.Set<DelegationURLClassLoader>
getFlattenedDependencies()
Get transitive dependencies as flattened set (without duplicates).java.util.List<DelegationURLClassLoader>
getParentClassLoaders()
Get the parent class loaders.IResourceIdentifier
getResourceIdentifier()
Get the resource identifier.java.net.URL
getURL()
Get the own url.boolean
hasParentClassLoader()
Test if has parent classloader.boolean
isClassLoaderCompatible(java.lang.Class<?> clazz)
protected java.lang.Class<?>
loadClass(java.lang.String name, boolean resolve)
Load class.protected java.lang.Class<?>
loadDirectClass(java.lang.String name, boolean resolve)
Load a class directly, without delegation to dependencies or base class loaderboolean
removeDelegateClassLoader(DelegationURLClassLoader classloader)
Remove a new delegate loader.boolean
removeParentClassLoader(DelegationURLClassLoader parent)
Remove a parent classloader.void
setResourceIdentifier(IResourceIdentifier rid)
Set the rid.java.lang.String
toString()
Get a string representation.-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
Methods 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, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
rid
protected IResourceIdentifier rid
The resource identifier.
-
basecl
protected java.lang.ClassLoader basecl
The base class loader.
-
delegates
protected java.util.List<DelegationURLClassLoader> delegates
The delegation classloader.
-
parents
protected java.util.List<DelegationURLClassLoader> parents
The parent classloaders (i.e. the support).
-
dependencies
protected volatile java.util.Set<DelegationURLClassLoader> dependencies
The flattened transitive dependencies without duplicates (created lazy from delegates list).
-
-
Constructor Detail
-
DelegationURLClassLoader
public DelegationURLClassLoader(java.lang.ClassLoader basecl, DelegationURLClassLoader[] delegates)
Create a new classloader.
-
DelegationURLClassLoader
public DelegationURLClassLoader(IResourceIdentifier rid, java.net.URL url, java.lang.ClassLoader basecl, DelegationURLClassLoader[] delegates)
Create a new classloader.
-
-
Method Detail
-
getDelegateResourceIdentifiers
public java.util.List<IResourceIdentifier> getDelegateResourceIdentifiers()
Get the delegates.- Returns:
- The delegates.
-
getDelegateClassLoaders
public DelegationURLClassLoader[] getDelegateClassLoaders()
Get the delegates.- Returns:
- The delegates.
-
addDelegateClassLoader
public boolean addDelegateClassLoader(DelegationURLClassLoader classloader)
Add a new delegate loader.- Parameters:
classloader
- The delegate classloader.
-
removeDelegateClassLoader
public boolean removeDelegateClassLoader(DelegationURLClassLoader classloader)
Remove a new delegate loader.- Parameters:
classloader
- The delegate classloader.- Returns:
- True, if classloader was removed.
-
addParentClassLoader
public boolean addParentClassLoader(DelegationURLClassLoader parent)
Add a parent loader.- Parameters:
classloader
- The parent loader.
-
removeParentClassLoader
public boolean removeParentClassLoader(DelegationURLClassLoader parent)
Remove a parent classloader.
-
hasParentClassLoader
public boolean hasParentClassLoader()
Test if has parent classloader.
-
getParentClassLoaders
public java.util.List<DelegationURLClassLoader> getParentClassLoaders()
Get the parent class loaders.
-
getFlattenedDependencies
public java.util.Set<DelegationURLClassLoader> getFlattenedDependencies()
Get transitive dependencies as flattened set (without duplicates).
-
getALLURLs
public java.util.Set<java.net.URL> getALLURLs()
Get transitive dependencies as flattened set (without duplicates).
-
computeFlattenedDependencies
public static java.util.Set<DelegationURLClassLoader> computeFlattenedDependencies(java.util.List<DelegationURLClassLoader> deps)
Get transitive dependencies as flattened set (without duplicates).
-
getDelegates
public java.util.List<DelegationURLClassLoader> getDelegates()
Get the delegates.
-
getURL
public java.net.URL getURL()
Get the own url.
-
getResourceIdentifier
public IResourceIdentifier getResourceIdentifier()
Get the resource identifier.- Returns:
- The resource identifier.
-
setResourceIdentifier
public void setResourceIdentifier(IResourceIdentifier rid)
Set the rid.- Parameters:
rid
- The rid to set.
-
getAllResourceIdentifiers
public java.util.Set<IResourceIdentifier> getAllResourceIdentifiers()
Get all managed resource identifiers inlcuding all subdependencies.- Returns:
- The resource identifiers.
-
loadDirectClass
protected java.lang.Class<?> loadDirectClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
Load a class directly, without delegation to dependencies or base class loader- Throws:
java.lang.ClassNotFoundException
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
Load class. Overridden to delegate to dependencies, if not found.- Overrides:
loadClass
in classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
-
findDirectResource
protected java.net.URL findDirectResource(java.lang.String name)
Find the resource.- Parameters:
name
- The name.- Returns:
- The url.
-
findResource
public java.net.URL findResource(java.lang.String name)
Find the resource.- Overrides:
findResource
in classjava.net.URLClassLoader
- Parameters:
name
- The name.- Returns:
- The url.
-
getBaseClassLoader
protected java.lang.ClassLoader getBaseClassLoader()
-
findDirectResources
protected java.util.Enumeration<java.net.URL> findDirectResources(java.lang.String name) throws java.io.IOException
Find the resource.- Parameters:
name
- The name.- Returns:
- The url.
- Throws:
java.io.IOException
-
findResources
public java.util.Enumeration<java.net.URL> findResources(java.lang.String name) throws java.io.IOException
Find the resource.- Overrides:
findResources
in classjava.net.URLClassLoader
- Parameters:
name
- The name.- Returns:
- The url.
- Throws:
java.io.IOException
-
isClassLoaderCompatible
public boolean isClassLoaderCompatible(java.lang.Class<?> clazz)
-
getAllParentLoaders
public static void getAllParentLoaders(java.lang.ClassLoader cl, java.util.Set<java.lang.ClassLoader> cls)
-
toString
public java.lang.String toString()
Get a string representation.- Overrides:
toString
in classjava.lang.Object
-
-