Class WebAppClassLoader

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  WebAppClassLoader.Context
      The Context in which the classloader operates.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addClassFileTransformer​(java.lang.instrument.ClassFileTransformer transformer)
      void addClassPath​(java.lang.String classPath)  
      void addClassPath​(Resource resource)  
      void addJars​(Resource lib)
      Add elements to the class path for the context from the jar and zip files found in the specified resource.
      void addTransformer​(java.lang.instrument.ClassFileTransformer transformer)  
      void close()  
      WebAppClassLoader.Context getContext()  
      java.lang.String getName()  
      java.security.PermissionCollection getPermissions​(java.security.CodeSource cs)  
      java.net.URL getResource​(java.lang.String name)
      Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present.
      java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)  
      boolean isServerClass​(java.lang.Class<?> clazz)
      Is the class a Server Class.
      boolean isSystemClass​(java.lang.Class<?> clazz)
      Is the class a System Class.
      boolean removeClassFileTransformer​(java.lang.instrument.ClassFileTransformer transformer)
      boolean removeTransformer​(java.lang.instrument.ClassFileTransformer transformer)  
      static <T> T runWithServerClassAccess​(java.security.PrivilegedExceptionAction<T> action)
      Run an action with access to ServerClasses
      void setName​(java.lang.String name)  
      java.lang.String toString()  
      • Methods inherited from class java.net.URLClassLoader

        findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
      • Methods inherited from class java.lang.ClassLoader

        clearAssertionStatus, getDefinedPackage, getDefinedPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • WebAppClassLoader

        public WebAppClassLoader​(WebAppClassLoader.Context context)
                          throws java.io.IOException
        Constructor.
        Parameters:
        context - the context for this classloader
        Throws:
        java.io.IOException - if unable to initialize from context
      • WebAppClassLoader

        public WebAppClassLoader​(java.lang.ClassLoader parent,
                                 WebAppClassLoader.Context context)
                          throws java.io.IOException
        Constructor.
        Parameters:
        parent - the parent classloader
        context - the context for this classloader
        Throws:
        java.io.IOException - if unable to initialize classloader
    • Method Detail

      • runWithServerClassAccess

        public static <T> T runWithServerClassAccess​(java.security.PrivilegedExceptionAction<T> action)
                                              throws java.lang.Exception
        Run an action with access to ServerClasses

        Run the passed PrivilegedExceptionAction with the classloader configured so as to allow server classes to be visible

        Type Parameters:
        T - The type returned by the action
        Parameters:
        action - The action to run
        Returns:
        The return from the action
        Throws:
        java.lang.Exception - if thrown by the action
      • getName

        public java.lang.String getName()
        Overrides:
        getName in class java.lang.ClassLoader
        Returns:
        the name of the classloader
      • setName

        public void setName​(java.lang.String name)
        Parameters:
        name - the name of the classloader
      • addClassPath

        public void addClassPath​(Resource resource)
                          throws java.io.IOException
        Parameters:
        resource - Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
        Throws:
        java.io.IOException - if unable to add classpath from resource
      • addClassPath

        public void addClassPath​(java.lang.String classPath)
                          throws java.io.IOException
        Parameters:
        classPath - Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
        Throws:
        java.io.IOException - if unable to add classpath
      • addJars

        public void addJars​(Resource lib)
        Add elements to the class path for the context from the jar and zip files found in the specified resource.
        Parameters:
        lib - the resource that contains the jar and/or zip files.
      • getPermissions

        public java.security.PermissionCollection getPermissions​(java.security.CodeSource cs)
      • getResources

        public java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
                                                         throws java.io.IOException
        Overrides:
        getResources in class java.lang.ClassLoader
        Throws:
        java.io.IOException
      • getResource

        public java.net.URL getResource​(java.lang.String name)
        Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present. This is non-standard and it is recommended to not rely on this behavior
        Overrides:
        getResource in class java.lang.ClassLoader
      • addClassFileTransformer

        @Deprecated
        public void addClassFileTransformer​(java.lang.instrument.ClassFileTransformer transformer)
        Parameters:
        transformer - the transformer to add
      • removeClassFileTransformer

        @Deprecated
        public boolean removeClassFileTransformer​(java.lang.instrument.ClassFileTransformer transformer)
        Parameters:
        transformer - the transformer to remove
        Returns:
        true if transformer was removed
      • addTransformer

        public void addTransformer​(java.lang.instrument.ClassFileTransformer transformer)
      • removeTransformer

        public boolean removeTransformer​(java.lang.instrument.ClassFileTransformer transformer)
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.net.URLClassLoader
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isSystemClass

        public boolean isSystemClass​(java.lang.Class<?> clazz)
        Description copied from interface: ClassVisibilityChecker
        Is the class a System Class. A System class is a class that is visible to a webapplication, but that cannot be overridden by the contents of WEB-INF/lib or WEB-INF/classes
        Specified by:
        isSystemClass in interface ClassVisibilityChecker
        Parameters:
        clazz - The fully qualified name of the class.
        Returns:
        True if the class is a system class.
      • isServerClass

        public boolean isServerClass​(java.lang.Class<?> clazz)
        Description copied from interface: ClassVisibilityChecker
        Is the class a Server Class. A Server class is a class that is part of the implementation of the server and is NIT visible to a webapplication. The web application may provide it's own implementation of the class, to be loaded from WEB-INF/lib or WEB-INF/classes
        Specified by:
        isServerClass in interface ClassVisibilityChecker
        Parameters:
        clazz - The fully qualified name of the class.
        Returns:
        True if the class is a server class.