Class 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 Detail

      • basecl

        protected java.lang.ClassLoader basecl
        The base class loader.
      • 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.
    • 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).
      • 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 class java.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 class java.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 class java.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 class java.lang.Object