public class DynamicClassLoader extends java.net.URLClassLoader implements Dependency, Make, DynamicClassLoaderMXBean
DynamicClassLoaders can be chained creating one virtual class loader. From the perspective of the JDK, it's all one classloader. Internally, the class loader chain searches like a classpath.
Constructor and Description |
---|
DynamicClassLoader(java.lang.ClassLoader parent)
Create a new class loader.
|
DynamicClassLoader(java.lang.ClassLoader parent,
boolean enableDependencyCheck,
boolean isRoot)
Create a new class loader.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCodeBasePath(java.lang.String path) |
void |
addDependency(Dependency dependency)
Adds a dependency.
|
void |
addJar(Path jar)
Adds a jar loader.
|
void |
addJarManifestClassPath(Path path)
Adds jars based on a manifest classpath.
|
void |
addListener(ClassLoaderListener listener)
Adds a listener to detect class loader changes.
|
void |
addLoader(Loader loader)
Adds a resource loader to the end of the list.
|
void |
addLoader(Loader loader,
int offset)
Adds a resource loader.
|
void |
addManifestClassPath(java.lang.String classPath,
Path pwd)
Adds jars based on a manifest classpath.
|
void |
addNative(Path path)
Adds a native path.
|
void |
addParentPriorityPackage(java.lang.String pkg)
Add to the list of packages that don't use the
setServletHack(boolean) . |
void |
addParentPriorityPackages(java.lang.String[] pkg)
Add to the list of packages that don't use the hack.
|
void |
addPathClass(java.lang.String className,
Path path)
Adds a jar loader.
|
void |
addPermission(java.security.Permission permission)
Adds a permission to the loader.
|
void |
addPermission(java.lang.String path,
java.lang.String actions) |
void |
addPermissions(java.util.ArrayList<java.security.Permission> perms) |
void |
addPriorityPackage(java.lang.String pkg)
Add to the list of packages that take priority over the parent
|
void |
addRoot(Path root)
Adds a root loader.
|
void |
addScanRoot() |
void |
addTransformer(java.lang.instrument.ClassFileTransformer transformer)
Sets any enhancer.
|
void |
addURL(int index,
java.net.URL url)
Adds the URL to the URLClassLoader.
|
boolean |
addURL(Path path)
Adds the URL to the URLClassLoader.
|
void |
addURL(java.net.URL url)
Adds the URL to the URLClassLoader.
|
void |
appendToClassPathForInstrumentation(java.lang.String path)
Adds a class loader for instrumentation (jdk 1.6).
|
void |
buildClassPath(java.util.ArrayList<java.lang.String> cp)
Fill data for the class path.
|
protected void |
buildImportClassPath(java.util.ArrayList<java.lang.String> sb) |
protected void |
buildResourcePathSpecificFirst(java.util.ArrayList<java.lang.String> pathList)
Returns the resource path with most specific first.
|
protected void |
buildSourcePath(java.util.ArrayList<java.lang.String> cp)
Fill data for the class path.
|
void |
clearModified()
Returns true if any of the classes have been modified.
|
protected void |
configureEnhancerEvent()
Sends an event to notify than an event has changed.
|
protected void |
configurePostEnhancerEvent()
Sends an event to notify than an event has changed.
|
boolean |
containsURL(Path path)
Adds the URL to the URLClassLoader.
|
protected boolean |
containsURL(java.net.URL url)
Returns true if the loader contains the url.
|
protected java.lang.Package |
definePackage(java.lang.String name,
java.lang.String a1,
java.lang.String a2,
java.lang.String a3,
java.lang.String b1,
java.lang.String b2,
java.lang.String b3,
java.net.URL url)
Defines a new package.
|
void |
destroy()
Destroys the class loader.
|
protected java.lang.Class<?> |
findClass(java.lang.String name)
Load a class using this class loader
|
java.lang.Class<?> |
findClassImpl(java.lang.String name)
Load a class using this class loader
|
protected java.lang.Class<?> |
findImportClass(java.lang.String name)
Returns any import class, e.g.
|
java.lang.String |
findLibrary(java.lang.String name)
Returns the full library path for the name.
|
Path |
findPath(java.lang.String name)
Returns the matching single-level path.
|
java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name)
Returns an enumeration of matching resources.
|
protected ClassEntry |
getClassEntry(java.lang.String name)
Returns the matching class entry.
|
java.lang.String |
getClassPath()
Fill data for the class path.
|
long |
getDependencyCheckInterval()
Gets the dependency check interval.
|
static long |
getGlobalDependencyCheckInterval()
Returns the global dependency check interval.
|
java.lang.String |
getHash() |
static java.lang.String |
getHash(java.lang.ClassLoader loader) |
long |
getHashCrc() |
java.lang.String |
getId()
Gets the name.
|
protected java.net.URL |
getImportResource(java.lang.String name)
Get resource from OSGi
|
java.lang.ClassLoader |
getInstrumentableClassLoader() |
protected java.util.ArrayList<ClassLoaderListener> |
getListeners()
Returns the listeners.
|
java.util.ArrayList<Loader> |
getLoaders() |
java.lang.String |
getLocalClassPath()
Fill data for the class path.
|
java.lang.ClassLoader |
getNewTempClassLoader() |
java.util.ArrayList<java.security.Permission> |
getPermissions() |
protected java.security.PermissionCollection |
getPermissions(java.security.CodeSource codeSource)
Returns the permission collection for the given code source.
|
java.net.URL |
getResource(java.lang.String name)
Gets the named resource
|
protected java.lang.String |
getResourceAlias(java.lang.String name) |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Opens a stream to a resource somewhere in the classpath
|
java.lang.String |
getResourcePathSpecificFirst()
Returns the resource path with most specific first.
|
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name) |
java.lang.String |
getSourcePath()
Returns the source path.
|
java.lang.ClassLoader |
getThrowawayClassLoader() |
protected java.util.ArrayList<java.lang.instrument.ClassFileTransformer> |
getTransformerList() |
java.net.URL[] |
getURLs()
Returns the URLs.
|
void |
init()
Initialize the class loader.
|
boolean |
isDestroyed()
Returns true if the class loader is closed.
|
boolean |
isDirectoryLoader()
Returns true for a class-loader that contains a WEB-INF/classes
style directory.
|
boolean |
isDisableURLs() |
boolean |
isJarCacheEnabled()
Returns true if jar entries should be cached.
|
static boolean |
isJarCacheEnabledDefault()
Returns true if jar entries should be cached.
|
boolean |
isModified()
Returns true if any of the classes have been modified.
|
boolean |
isModified(boolean enable)
Returns true if any of the classes have been modified.
|
static boolean |
isModified(java.lang.ClassLoader loader)
Returns true if any of the classes have been modified.
|
boolean |
isModifiedNow()
Returns true if any of the classes have been modified, forcing a check.
|
boolean |
isRoot() |
java.lang.Class<?> |
loadClass(java.lang.String name) |
protected java.lang.Class<?> |
loadClass(java.lang.String name,
boolean resolve)
Load a class using this class loader
|
java.lang.Class<?> |
loadClass(java.lang.String className,
byte[] bytecode) |
protected java.lang.Class<?> |
loadClassEntry(ClassEntry entry)
Loads the class from the loader.
|
java.lang.Class<?> |
loadClassImpl(java.lang.String name,
boolean resolve)
Load a class using this class loader
|
boolean |
logModified(java.util.logging.Logger log)
Logs the reason for modification.
|
void |
make()
Makes any changed classes for the virtual class loader.
|
void |
removeListener(ClassLoaderListener listener)
Adds a listener to detect class loader changes.
|
void |
removeLoader(Loader loader)
Removes a loader (this should only be used by generating code, for example
EJB to deal with package-private).
|
protected void |
replace(DynamicClassLoader source)
Copies the loader.
|
void |
resetDependencyCheckInterval()
Returns true if any of the classes have been modified.
|
protected void |
scan() |
protected void |
sendAddLoaderEvent()
Adds a listener to detect class loader changes.
|
void |
setDependencyCheckInterval(long interval)
Sets the dependency check interval.
|
void |
setDisableURLs(boolean isDisable) |
void |
setEnableDependencyCheck(boolean enable)
Enables the dependency checking.
|
static void |
setGlobalDependencyCheckInterval(long interval)
Sets the global dependency check interval.
|
void |
setId(java.lang.String id)
Sets the name.
|
static void |
setJarCacheEnabled(boolean isEnabled)
Returns true if jar entries should be cached.
|
static void |
setOldLoader(java.lang.Thread thread,
java.lang.ClassLoader oldLoader)
Sets the old loader if not destroyed.
|
void |
setServletHack(boolean servletHack)
Set true if the loader should use the servlet spec's hack.
|
void |
stop()
stops the class loader.
|
protected static java.lang.String |
toClassPath(java.util.ArrayList<java.lang.String> list) |
java.lang.String |
toString() |
void |
updateScan() |
void |
validate()
Validates the class loader.
|
close, definePackage, findResource, newInstance, newInstance
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public DynamicClassLoader(java.lang.ClassLoader parent)
parent
- parent class loaderpublic DynamicClassLoader(java.lang.ClassLoader parent, boolean enableDependencyCheck, boolean isRoot)
parent
- parent class loaderpublic static boolean isJarCacheEnabledDefault()
public boolean isRoot()
public boolean isJarCacheEnabled()
public static void setJarCacheEnabled(boolean isEnabled)
public static long getGlobalDependencyCheckInterval()
public static void setGlobalDependencyCheckInterval(long interval)
public void setId(java.lang.String id)
public java.lang.String getId()
public boolean isDestroyed()
public boolean isDirectoryLoader()
public void addLoader(Loader loader)
public void removeLoader(Loader loader)
public void addLoader(Loader loader, int offset)
public java.util.ArrayList<Loader> getLoaders()
public void addJarManifestClassPath(Path path) throws java.io.IOException
java.io.IOException
public void addManifestClassPath(java.lang.String classPath, Path pwd)
public void addNative(Path path)
public void addJar(Path jar)
public void addRoot(Path root)
public void addPathClass(java.lang.String className, Path path)
public boolean addURL(Path path)
public void setDisableURLs(boolean isDisable)
public boolean isDisableURLs()
public boolean containsURL(Path path)
public void addURL(java.net.URL url)
addURL
in class java.net.URLClassLoader
public void addURL(int index, java.net.URL url)
public void appendToClassPathForInstrumentation(java.lang.String path)
public java.net.URL[] getURLs()
getURLs
in class java.net.URLClassLoader
protected boolean containsURL(java.net.URL url)
public void setDependencyCheckInterval(long interval)
public long getDependencyCheckInterval()
public void setEnableDependencyCheck(boolean enable)
public void addDependency(Dependency dependency)
public void addPermission(java.lang.String path, java.lang.String actions)
public void addPermission(java.security.Permission permission)
public java.util.ArrayList<java.security.Permission> getPermissions()
public void addPermissions(java.util.ArrayList<java.security.Permission> perms)
public void setServletHack(boolean servletHack)
public final void addListener(ClassLoaderListener listener)
public final void removeListener(ClassLoaderListener listener)
protected java.util.ArrayList<ClassLoaderListener> getListeners()
public final void updateScan()
protected final void sendAddLoaderEvent()
protected void configureEnhancerEvent()
protected void configurePostEnhancerEvent()
public void addParentPriorityPackages(java.lang.String[] pkg)
public void addParentPriorityPackage(java.lang.String pkg)
setServletHack(boolean)
.public void addPriorityPackage(java.lang.String pkg)
protected java.security.PermissionCollection getPermissions(java.security.CodeSource codeSource)
getPermissions
in class java.net.URLClassLoader
protected void addCodeBasePath(java.lang.String path)
public void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
protected java.util.ArrayList<java.lang.instrument.ClassFileTransformer> getTransformerList()
public static final java.lang.String getHash(java.lang.ClassLoader loader)
public java.lang.String getHash()
public long getHashCrc()
public final java.lang.String getClassPath()
public final void buildClassPath(java.util.ArrayList<java.lang.String> cp)
protected void buildImportClassPath(java.util.ArrayList<java.lang.String> sb)
public final java.lang.String getLocalClassPath()
public final java.lang.String getSourcePath()
protected final void buildSourcePath(java.util.ArrayList<java.lang.String> cp)
public final java.lang.String getResourcePathSpecificFirst()
protected final void buildResourcePathSpecificFirst(java.util.ArrayList<java.lang.String> pathList)
protected static java.lang.String toClassPath(java.util.ArrayList<java.lang.String> list)
public final boolean isModified()
isModified
in interface Dependency
public final boolean isModified(boolean enable)
public final boolean isModifiedNow()
public final boolean logModified(java.util.logging.Logger log)
logModified
in interface Dependency
public final void resetDependencyCheckInterval()
public final void clearModified()
public static boolean isModified(java.lang.ClassLoader loader)
public final void make() throws java.lang.Exception
protected java.lang.Package definePackage(java.lang.String name, java.lang.String a1, java.lang.String a2, java.lang.String a3, java.lang.String b1, java.lang.String b2, java.lang.String b3, java.net.URL url)
definePackage
in class java.lang.ClassLoader
public void init()
public void validate() throws ConfigException
ConfigException
public void addScanRoot()
protected void scan()
public java.lang.Class<?> loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
name
- the classname to loadresolve
- if true, resolve the classjava.lang.ClassNotFoundException
public java.lang.Class<?> loadClassImpl(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
name
- the classname to loadresolve
- if true, resolve the classjava.lang.ClassNotFoundException
protected java.lang.Class<?> findImportClass(java.lang.String name)
protected java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.net.URLClassLoader
name
- the classname using either '/' or '.'java.lang.ClassNotFoundException
public java.lang.Class<?> findClassImpl(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the classname using either '/' or '.'java.lang.ClassNotFoundException
protected ClassEntry getClassEntry(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
protected java.lang.Class<?> loadClassEntry(ClassEntry entry) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.Class<?> loadClass(java.lang.String className, byte[] bytecode)
public java.net.URL getResource(java.lang.String name)
getResource
in class java.lang.ClassLoader
name
- name of the resourceprotected java.lang.String getResourceAlias(java.lang.String name)
protected java.net.URL getImportResource(java.lang.String name)
public java.io.InputStream getResourceAsStream(java.lang.String name)
getResourceAsStream
in class java.net.URLClassLoader
name
- the path to the resourcepublic java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException
getResources
in class java.lang.ClassLoader
java.io.IOException
public java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
findResources
in class java.net.URLClassLoader
public java.lang.String findLibrary(java.lang.String name)
findLibrary
in class java.lang.ClassLoader
public Path findPath(java.lang.String name)
public void stop()
public void destroy()
public static void setOldLoader(java.lang.Thread thread, java.lang.ClassLoader oldLoader)
public java.lang.ClassLoader getInstrumentableClassLoader()
public java.lang.ClassLoader getThrowawayClassLoader()
public java.lang.ClassLoader getNewTempClassLoader()
protected void replace(DynamicClassLoader source)
public java.lang.String toString()
toString
in class java.lang.Object