Package org.codehaus.classworlds
Class RealmClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.codehaus.classworlds.RealmClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
UberJarRealmClassLoader
class RealmClassLoader extends java.net.URLClassLoader
Classloader forClassRealm
s.- Version:
- $Id: RealmClassLoader.java 126 2006-01-12 04:17:51Z $
- Author:
- bob mcwhirter
-
-
Field Summary
Fields Modifier and Type Field Description protected DefaultClassRealm
realm
The realm.
-
Constructor Summary
Constructors Constructor Description RealmClassLoader(DefaultClassRealm realm)
Construct.RealmClassLoader(DefaultClassRealm realm, java.lang.ClassLoader classLoader)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addConstituent(java.net.URL constituent)
Add a constituent to this realm for locating classes.java.net.URL
findResource(java.lang.String name)
Find a resource within this ClassLoader only (don't delegate to the parent).java.util.Enumeration
findResources(java.lang.String name)
java.util.Enumeration
findResourcesDirect(java.lang.String name)
Find resources from this ClassLoader, and don't search the realm.byte[]
getBytesToEndOfStream(java.io.DataInputStream in)
Helper method for addConstituent that reads in a DataInputStream and returns it as a byte[] It attempts to use in.available - the size of the file - else defaults to 2048(package private) DefaultClassRealm
getRealm()
Retrieve the realm.java.net.URL
getResource(java.lang.String name)
java.net.URL
getResourceDirect(java.lang.String name)
Get a resource from this ClassLoader, and don't search the realm.java.net.URL[]
getURLs()
Retrieve theURL
s used by thisClassLoader
.protected java.lang.Class
loadClass(java.lang.String name, boolean resolve)
Load a class.(package private) java.lang.Class
loadClassDirect(java.lang.String name)
Load a class directly from this classloader without defering through any otherClassRealm
.-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, getPermissions, getResourceAsStream, newInstance, newInstance
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
realm
protected DefaultClassRealm realm
The realm.
-
-
Constructor Detail
-
RealmClassLoader
RealmClassLoader(DefaultClassRealm realm)
Construct.- Parameters:
realm
- The realm for which this loads.
-
RealmClassLoader
RealmClassLoader(DefaultClassRealm realm, java.lang.ClassLoader classLoader)
Construct.- Parameters:
realm
- The realm for which this loads.classLoader
- The parent ClassLoader.
-
-
Method Detail
-
getRealm
DefaultClassRealm getRealm()
Retrieve the realm.- Returns:
- The realm.
-
addConstituent
void addConstituent(java.net.URL constituent)
Add a constituent to this realm for locating classes. If the url definition ends in .class its a BytesURLStreamHandler so use defineClass insead. addURL is still called for byte[] even though it has no affect and we use defineClass instead, this is for consistentency and to allow access to the class with getURLs()- Parameters:
constituent
- URL to contituent jar or directory.
-
getBytesToEndOfStream
public byte[] getBytesToEndOfStream(java.io.DataInputStream in) throws java.io.IOException
Helper method for addConstituent that reads in a DataInputStream and returns it as a byte[] It attempts to use in.available - the size of the file - else defaults to 2048- Throws:
java.io.IOException
-
loadClassDirect
java.lang.Class loadClassDirect(java.lang.String name) throws java.lang.ClassNotFoundException
Load a class directly from this classloader without defering through any otherClassRealm
.- Parameters:
name
- The name of the class to load.- Returns:
- The loaded class.
- Throws:
java.lang.ClassNotFoundException
- If the class could not be found.
-
loadClass
protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
Load a class.- Overrides:
loadClass
in classjava.lang.ClassLoader
- Parameters:
name
- The name of the class to load.resolve
- Iftrue
then resolve the class.- Returns:
- The loaded class.
- Throws:
java.lang.ClassNotFoundException
- If the class cannot be found.
-
getURLs
public java.net.URL[] getURLs()
Retrieve theURL
s used by thisClassLoader
.- Overrides:
getURLs
in classjava.net.URLClassLoader
- Returns:
- The urls.
-
findResource
public java.net.URL findResource(java.lang.String name)
Find a resource within this ClassLoader only (don't delegate to the parent).- Overrides:
findResource
in classjava.net.URLClassLoader
- Returns:
- The resource.
-
getResource
public java.net.URL getResource(java.lang.String name)
- Overrides:
getResource
in classjava.lang.ClassLoader
-
getResourceDirect
public java.net.URL getResourceDirect(java.lang.String name)
Get a resource from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.- Returns:
- The resource.
-
findResources
public java.util.Enumeration findResources(java.lang.String name) throws java.io.IOException
- Overrides:
findResources
in classjava.net.URLClassLoader
- Throws:
java.io.IOException
-
findResourcesDirect
public java.util.Enumeration findResourcesDirect(java.lang.String name) throws java.io.IOException
Find resources from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.- Returns:
- The resource.
- Throws:
java.io.IOException
-
-