Class AbstractURLClassPathHandle

  • All Implemented Interfaces:
    URLClassPathHandle, Prioritized, java.lang.Comparable<Prioritized>
    Direct Known Subclasses:
    ClassicURLClassPathHandle, ModernURLClassPathHandle

    public abstract class AbstractURLClassPathHandle
    extends java.lang.Object
    implements URLClassPathHandle, Prioritized
    Abstract implementation of URLClassPathHandle that provides a base for handling URL Class-Path entries.

    This class offers reflective access to internal structures like the ucp, urls, and loaders fields used by the JVM's class loading mechanism. It is primarily designed for advanced use cases where fine-grained control over class loader URLs is required, such as dynamic removal or modification of URLs from a class loader.

    Key Features:

    • Supports reflective manipulation of internal JVM class loading structures.
    • Provides abstraction over different versions of JVM internals (e.g., classic vs modern JDK).
    • Implements the Prioritized interface to allow prioritization among multiple handlers.

    Example Usage

    
     public class ClassicURLClassPathHandle extends AbstractURLClassPathHandle {
    
         public ClassicURLClassPathHandle() {
             // Default constructor
         }
    
         protected String getURLClassPathClassName() {
             return "sun.misc.URLClassPath";
         }
    
         protected String getUrlsFieldName() {
             return "urls"; // Classic field name
         }
     }
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    ClassicURLClassPathHandle, ModernURLClassPathHandle, URLClassPathHandle, Prioritized
    • Constructor Detail

      • AbstractURLClassPathHandle

        public AbstractURLClassPathHandle()
    • Method Detail

      • getURLs

        @Nonnull
        public java.net.URL[] getURLs​(java.lang.ClassLoader classLoader)
        Description copied from interface: URLClassPathHandle
        Get the Class-Path URLs from the specified ClassLoader
        Specified by:
        getURLs in interface URLClassPathHandle
        Parameters:
        classLoader - the specified ClassLoader
        Returns:
        the non-null array of URLs
      • removeURL

        public final boolean removeURL​(java.lang.ClassLoader classLoader,
                                       java.net.URL url)
        Description copied from interface: URLClassPathHandle
        Remove the Class-Path URL from the specified ClassLoader
        Specified by:
        removeURL in interface URLClassPathHandle
        Parameters:
        classLoader - the specified ClassLoader
        url - the Class-Path URL
        Returns:
        if removed, return true, otherwise false
      • setPriority

        public final void setPriority​(int priority)
      • getUrlClassPathClass

        protected final java.lang.Class<?> getUrlClassPathClass()
      • getLoaderClass

        protected final java.lang.Class<?> getLoaderClass()
      • findUcpField

        protected final java.lang.reflect.Field findUcpField​(java.lang.ClassLoader classLoader)
      • getPathField

        protected final java.lang.reflect.Field getPathField()
      • getUrlsField

        protected final java.lang.reflect.Field getUrlsField()
      • getLoadersField

        protected final java.lang.reflect.Field getLoadersField()
      • getBaseField

        protected final java.lang.reflect.Field getBaseField()
      • getURLClassPathClassName

        protected abstract java.lang.String getURLClassPathClassName()
      • getUrlsFieldName

        protected abstract java.lang.String getUrlsFieldName()