org.codehaus.classworlds
Class DefaultClassRealm

java.lang.Object
  extended byorg.codehaus.classworlds.DefaultClassRealm
All Implemented Interfaces:
ClassRealm

class DefaultClassRealm
extends java.lang.Object
implements ClassRealm

Implementation of ClassRealm.

Version:
$Id: DefaultClassRealm.java,v 1.1 2003/09/23 14:09:46 jvanzyl Exp $
Author:
bob mcwhirter, Jason van Zyl

Field Summary
private  RealmClassLoader classLoader
          The classloader.
private  java.lang.String id
          The id of this realm.
private  java.util.Set imports
          Import spec entries.
private  ClassRealm parent
          Parent ClassRealm
private  ClassWorld world
          The world of which this realm is a member.
 
Constructor Summary
(package private) DefaultClassRealm(ClassWorld world, java.lang.String id)
          Construct.
 
Method Summary
 void addConstituent(java.net.URL constituent)
          Add a constituent to this realm for locating classes.
 ClassRealm createChildRealm(java.lang.String id)
          Create a child realm.
 java.lang.ClassLoader getClassLoader()
          Retrieve the ClassLoader view of this realm.
 java.lang.String getId()
          Retrieve the id.
 ClassRealm getParent()
           
 java.net.URL getResource(java.lang.String name)
          Retrieve a resource.
 ClassWorld getWorld()
          Retrieve the ClassWorld.
 void importFrom(java.lang.String realmId, java.lang.String pkgName)
          Import packages from another ClassRealm.
 java.lang.Class loadClass(java.lang.String name)
          Load a class.
(package private)  java.lang.Class loadClassDirect(java.lang.String name)
          Load a class.
(package private)  java.net.URL loadResourceDirect(java.lang.String name)
           
(package private)  DefaultClassRealm locateSourceRealm(java.lang.String classname)
          Locate the ClassRealm that should satisfy loading of a class.
 void setParent(ClassRealm parent)
          Set the parent ClassRealm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

world

private ClassWorld world
The world of which this realm is a member.


id

private java.lang.String id
The id of this realm.


imports

private java.util.Set imports
Import spec entries.


classLoader

private RealmClassLoader classLoader
The classloader.


parent

private ClassRealm parent
Parent ClassRealm

Constructor Detail

DefaultClassRealm

DefaultClassRealm(ClassWorld world,
                  java.lang.String id)
Construct.

Parameters:
world - The world of which this realm is a member.
id - This realm's id.
Method Detail

getParent

public ClassRealm getParent()
Returns:

setParent

public void setParent(ClassRealm parent)
Description copied from interface: ClassRealm
Set the parent ClassRealm.

Specified by:
setParent in interface ClassRealm
Parameters:
parent -

getId

public java.lang.String getId()
Retrieve the id.

Specified by:
getId in interface ClassRealm
Returns:
The id.

getWorld

public ClassWorld getWorld()
Retrieve the ClassWorld.

Specified by:
getWorld in interface ClassRealm
Returns:
The world.

importFrom

public void importFrom(java.lang.String realmId,
                       java.lang.String pkgName)
                throws NoSuchRealmException
Import packages from another ClassRealm.

Specific packages can be imported from another realm instead of attempting to load them locally from this one. When importing a package a realm defers completely to the foreign realm to satisfy the package dependencies.

Specified by:
importFrom in interface ClassRealm
Parameters:
realmId - The realm id from which to import.
pkgName - The package name to import.
Throws:
NoSuchRealmException - If the id of the realm from which to import does not correspond to a foreign realm within this realm's world.

addConstituent

public void addConstituent(java.net.URL constituent)
Add a constituent to this realm for locating classes.

Specified by:
addConstituent in interface ClassRealm
Parameters:
constituent - URL to contituent jar or directory.

locateSourceRealm

DefaultClassRealm locateSourceRealm(java.lang.String classname)
Locate the ClassRealm that should satisfy loading of a class.

Parameters:
classname - The name of the class to load.
Returns:
The appropriate realm.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Retrieve the ClassLoader view of this realm.

Specified by:
getClassLoader in interface ClassRealm
Returns:
The class-loader view of this realm.

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Load a class.

Specified by:
loadClass in interface ClassRealm
Parameters:
name - The name of the class to load.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If the class cannot be found.

loadClassDirect

java.lang.Class loadClassDirect(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Load a class.

Parameters:
name - The name of the class to load.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If the class cannot be found.

getResource

public java.net.URL getResource(java.lang.String name)
Retrieve a resource.

Specified by:
getResource in interface ClassRealm
Parameters:
name - The resource name.
Returns:
The URL to the located resource or null if none could be located.

loadResourceDirect

java.net.URL loadResourceDirect(java.lang.String name)

createChildRealm

public ClassRealm createChildRealm(java.lang.String id)
Description copied from interface: ClassRealm
Create a child realm.

Specified by:
createChildRealm in interface ClassRealm
Parameters:
id - The name of child realm.
See Also:
ClassRealm.createChildRealm(java.lang.String)