org.codehaus.classworlds

Class DefaultClassRealm

Implemented Interfaces:
ClassRealm

public class DefaultClassRealm
extends java.lang.Object
implements ClassRealm

Implementation of ClassRealm. The realm is the class loading gateway. The search is proceded as follows:
  1. Search the parent class loader (passed via the constructor) if there is one.
  2. Search the imports.
  3. Search this realm's constituents.
  4. Search the parent realm.
Version:
$Id: DefaultClassRealm.java 126 2006-01-12 04:17:51Z $
Authors:
bob mcwhirter
Jason van Zyl

Constructor Summary

DefaultClassRealm(ClassWorld world, String id)
DefaultClassRealm(ClassWorld world, String id, ClassLoader foreignClassLoader)

Method Summary

void
addConstituent(String constituent, byte[] b)
Adds a byte[] class definition as a constituent for locating classes.
void
addConstituent(URL constituent)
ClassRealm
createChildRealm(String id)
void
display()
Enumeration
findResources(String name)
ClassLoader
getClassLoader()
URL[]
getConstituents()
String
getId()
ClassRealm
getParent()
URL
getResource(String name)
InputStream
getResourceAsStream(String name)
ClassWorld
getWorld()
void
importFrom(String realmId, String packageName)
Class
loadClass(String name)
ClassRealm
locateSourceRealm(String classname)
void
setParent(ClassRealm parent)

Constructor Details

DefaultClassRealm

public DefaultClassRealm(ClassWorld world,
                         String id)

DefaultClassRealm

public DefaultClassRealm(ClassWorld world,
                         String id,
                         ClassLoader foreignClassLoader)

Method Details

addConstituent

public void addConstituent(String constituent,
                           byte[] b)
            throws ClassNotFoundException
Adds a byte[] class definition as a constituent for locating classes. Currently uses BytesURLStreamHandler to hold a reference of the byte[] in memory. This ensures we have a unifed URL resource model for all constituents. The code to cache to disk is commented out - maybe a property to choose which method?
Parameters:
constituent - class name
b - the class definition as a byte[]

addConstituent

public void addConstituent(URL constituent)
Specified by:
addConstituent in interface ClassRealm

createChildRealm

public ClassRealm createChildRealm(String id)
            throws DuplicateRealmException
Specified by:
createChildRealm in interface ClassRealm

display

public void display()
Specified by:
display in interface ClassRealm

findResources

public Enumeration findResources(String name)
            throws IOException
Specified by:
findResources in interface ClassRealm

getClassLoader

public ClassLoader getClassLoader()
Specified by:
getClassLoader in interface ClassRealm

getConstituents

public URL[] getConstituents()
Specified by:
getConstituents in interface ClassRealm

getId

public String getId()
Specified by:
getId in interface ClassRealm

getParent

public ClassRealm getParent()
Specified by:
getParent in interface ClassRealm

getResource

public URL getResource(String name)
Specified by:
getResource in interface ClassRealm

getResourceAsStream

public InputStream getResourceAsStream(String name)
Specified by:
getResourceAsStream in interface ClassRealm

getWorld

public ClassWorld getWorld()
Specified by:
getWorld in interface ClassRealm

importFrom

public void importFrom(String realmId,
                       String packageName)
            throws NoSuchRealmException
Specified by:
importFrom in interface ClassRealm

loadClass

public Class loadClass(String name)
            throws ClassNotFoundException
Specified by:
loadClass in interface ClassRealm

locateSourceRealm

public ClassRealm locateSourceRealm(String classname)
Specified by:
locateSourceRealm in interface ClassRealm

setParent

public void setParent(ClassRealm parent)
Specified by:
setParent in interface ClassRealm