Package io.microsphere.classloading
Class AbstractURLClassPathHandle
- java.lang.Object
-
- io.microsphere.classloading.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 ofURLClassPathHandlethat provides a base for handling URL Class-Path entries.This class offers reflective access to internal structures like the
ucp,urls, andloadersfields 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
Prioritizedinterface 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
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_PRIORITYThe default priority isPrioritized.MAX_PRIORITY+ 99999-
Fields inherited from interface io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description AbstractURLClassPathHandle()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.reflect.FieldfindUcpField(java.lang.ClassLoader classLoader)protected java.lang.reflect.FieldgetBaseField()protected java.lang.Class<?>getLoaderClass()protected java.lang.reflect.FieldgetLoadersField()protected java.lang.reflect.FieldgetPathField()intgetPriority()Get the priorityprotected java.lang.Class<?>getUrlClassPathClass()protected abstract java.lang.StringgetURLClassPathClassName()java.net.URL[]getURLs(java.lang.ClassLoader classLoader)Get the Class-Path URLs from the specifiedClassLoaderprotected java.lang.reflect.FieldgetUrlsField()protected abstract java.lang.StringgetUrlsFieldName()booleanremoveURL(java.lang.ClassLoader classLoader, java.net.URL url)Remove the Class-PathURLfrom the specifiedClassLoadervoidsetPriority(int priority)booleansupports()Supports or not-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.microsphere.lang.Prioritized
compareTo
-
Methods inherited from interface io.microsphere.classloading.URLClassPathHandle
initializeLoaders
-
-
-
-
Field Detail
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
The default priority isPrioritized.MAX_PRIORITY+ 99999- See Also:
- Constant Field Values
-
-
Method Detail
-
supports
public boolean supports()
Description copied from interface:URLClassPathHandleSupports or not- Specified by:
supportsin interfaceURLClassPathHandle- Returns:
- if supports, return
true, otherwisefalse
-
getURLs
@Nonnull public java.net.URL[] getURLs(java.lang.ClassLoader classLoader)
Description copied from interface:URLClassPathHandleGet the Class-Path URLs from the specifiedClassLoader- Specified by:
getURLsin interfaceURLClassPathHandle- Parameters:
classLoader- the specifiedClassLoader- Returns:
- the non-null array of
URLs
-
removeURL
public final boolean removeURL(java.lang.ClassLoader classLoader, java.net.URL url)Description copied from interface:URLClassPathHandleRemove the Class-PathURLfrom the specifiedClassLoader- Specified by:
removeURLin interfaceURLClassPathHandle- Parameters:
classLoader- the specifiedClassLoaderurl- the Class-PathURL- Returns:
- if removed, return
true, otherwisefalse
-
setPriority
public final void setPriority(int priority)
-
getPriority
public final int getPriority()
Description copied from interface:URLClassPathHandleGet the priority- Specified by:
getPriorityin interfacePrioritized- Specified by:
getPriorityin interfaceURLClassPathHandle- Returns:
- the default value is
Prioritized.MIN_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()
-
-