org.codehaus.plexus.classworlds.realm

## Class ClassRealm

- java.lang.Object
- - java.lang.ClassLoader
  - - java.security.SecureClassLoader
    - - java.net.URLClassLoader
      - - org.codehaus.plexus.classworlds.realm.ClassRealm

All Implemented Interfaces:
  Closeable, AutoCloseable

Direct Known Subclasses:
  ClassRealmReverseAdapter

    public class ClassRealm
    extends URLClassLoader

The class loading gateway. Each class realm has access to a base class loader, imports form zero or more other class loaders, an optional parent class loader and of course its own class path. When queried for a class/resource, a class realm will always query its base class loader first before it delegates to a pluggable strategy. The strategy in turn controls the order in which imported class loaders, the parent class loader and the realm itself are searched. The base class loader is assumed to be capable of loading of the bootstrap classes.

Author:
  bob mcwhirter, Jason van Zyl

### Constructor Summary

Constructors
Constructor and Description
`ClassRealm(ClassWorld world, String id, ClassLoader baseClassLoader)` Creates a new class realm.

### Method Summary

Methods
`void` `addURL(URL url)`
`ClassRealm` `createChildRealm(String id)`
`void` `display()`
`void` `display(PrintStream out)`
`protected Class<?>` `findClass(String name)`
`URL` `findResource(String name)`
`Enumeration<URL>` `findResources(String name)`
`String` `getId()`
`ClassLoader` `getImportClassLoader(String name)`
`Collection<ClassRealm>` `getImportRealms()`
`ClassLoader` `getParentClassLoader()`
`ClassRealm` `getParentRealm()`
`URL` `getResource(String name)`
`Enumeration<URL>` `getResources(String name)`
`Strategy` `getStrategy()`
`ClassWorld` `getWorld()`
`void` `importFrom(ClassLoader classLoader, String packageName)`
`void` `importFrom(String realmId, String packageName)`
`void` `importFromParent(String packageName)`
`Class<?>` `loadClass(String name)`
`protected Class<?>` `loadClass(String name, boolean resolve)`
`Class<?>` `loadClassFromImport(String name)`
`Class<?>` `loadClassFromParent(String name)`
`Class<?>` `loadClassFromSelf(String name)`
`URL` `loadResourceFromImport(String name)`
`URL` `loadResourceFromParent(String name)`
`URL` `loadResourceFromSelf(String name)`
`Enumeration<URL>` `loadResourcesFromImport(String name)`
`Enumeration<URL>` `loadResourcesFromParent(String name)`
`Enumeration<URL>` `loadResourcesFromSelf(String name)`
`void` `setParentClassLoader(ClassLoader parentClassLoader)`
`void` `setParentRealm(ClassRealm realm)`
`String` `toString()`

### Methods inherited from class java.net.URLClassLoader

`close, definePackage, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance`

### Methods inherited from class java.security.SecureClassLoader

`defineClass, defineClass`

### Methods inherited from class java.lang.ClassLoader

`clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### ClassRealm

    public ClassRealm(ClassWorld world,
              String id,
              ClassLoader baseClassLoader)

Creates a new class realm.

Parameters:
  `world` - The class world this realm belongs to, must not be `null`.
  `id` - The identifier for this realm, must not be `null`.
  `baseClassLoader` - The base class loader for this realm, may be `null` to use the bootstrap class loader.

### Method Detail

#### getId

    public String getId()

#### getWorld

    public ClassWorld getWorld()

#### importFromParent

    public void importFromParent(String packageName)

#### importFrom

    public void importFrom(String realmId,
                  String packageName)
                    throws NoSuchRealmException

Throws:
  `NoSuchRealmException`

#### importFrom

    public void importFrom(ClassLoader classLoader,
                  String packageName)

#### getImportClassLoader

    public ClassLoader getImportClassLoader(String name)

#### getImportRealms

    public Collection<ClassRealm> getImportRealms()

#### getStrategy

    public Strategy getStrategy()

#### setParentClassLoader

    public void setParentClassLoader(ClassLoader parentClassLoader)

#### getParentClassLoader

    public ClassLoader getParentClassLoader()

#### setParentRealm

    public void setParentRealm(ClassRealm realm)

#### getParentRealm

    public ClassRealm getParentRealm()

#### createChildRealm

    public ClassRealm createChildRealm(String id)
                                throws DuplicateRealmException

Throws:
  `DuplicateRealmException`

#### addURL

    public void addURL(URL url)

Overrides:
  `addURL` in class `URLClassLoader`

#### loadClass

    public Class<?> loadClass(String name)
                       throws ClassNotFoundException

Overrides:
  `loadClass` in class `ClassLoader`
Throws:
  `ClassNotFoundException`

#### loadClass

    protected Class<?> loadClass(String name,
                     boolean resolve)
                          throws ClassNotFoundException

Overrides:
  `loadClass` in class `ClassLoader`
Throws:
  `ClassNotFoundException`

#### findClass

    protected Class<?> findClass(String name)
                          throws ClassNotFoundException

Overrides:
  `findClass` in class `URLClassLoader`
Throws:
  `ClassNotFoundException`

#### getResource

    public URL getResource(String name)

Overrides:
  `getResource` in class `ClassLoader`

#### findResource

    public URL findResource(String name)

Overrides:
  `findResource` in class `URLClassLoader`

#### getResources

    public Enumeration<URL> getResources(String name)
                                  throws IOException

Overrides:
  `getResources` in class `ClassLoader`
Throws:
  `IOException`

#### findResources

    public Enumeration<URL> findResources(String name)
                                   throws IOException

Overrides:
  `findResources` in class `URLClassLoader`
Throws:
  `IOException`

#### display

    public void display()

#### display

    public void display(PrintStream out)

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### loadClassFromImport

    public Class<?> loadClassFromImport(String name)

#### loadClassFromSelf

    public Class<?> loadClassFromSelf(String name)

#### loadClassFromParent

    public Class<?> loadClassFromParent(String name)

#### loadResourceFromImport

    public URL loadResourceFromImport(String name)

#### loadResourceFromSelf

    public URL loadResourceFromSelf(String name)

#### loadResourceFromParent

    public URL loadResourceFromParent(String name)

#### loadResourcesFromImport

    public Enumeration<URL> loadResourcesFromImport(String name)

#### loadResourcesFromSelf

    public Enumeration<URL> loadResourcesFromSelf(String name)

#### loadResourcesFromParent

    public Enumeration<URL> loadResourcesFromParent(String name)