Package 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:
  `java.io.Closeable`, `java.lang.AutoCloseable`

Direct Known Subclasses:
  `ClassRealmReverseAdapter`

    public class ClassRealm
    extends java.net.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
`ClassRealm​(ClassWorld world, java.lang.String id, java.lang.ClassLoader baseClassLoader)` Creates a new class realm.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addURL​(java.net.URL url)`
`ClassRealm` `createChildRealm​(java.lang.String id)`
`void` `display()`
`void` `display​(java.io.PrintStream out)`
`protected java.lang.Class<?>` `findClass​(java.lang.String name)`
`protected java.lang.Class<?>` `findClass​(java.lang.String moduleName, java.lang.String name)`
`java.net.URL` `findResource​(java.lang.String name)`
`java.util.Enumeration<java.net.URL>` `findResources​(java.lang.String name)`
`protected java.lang.Object` `getClassLoadingLock​(java.lang.String name)`
`java.lang.String` `getId()`
`java.lang.ClassLoader` `getImportClassLoader​(java.lang.String name)`
`java.util.Collection<ClassRealm>` `getImportRealms()`
`java.lang.ClassLoader` `getParentClassLoader()`
`ClassRealm` `getParentRealm()`
`java.net.URL` `getResource​(java.lang.String name)`
`java.util.Enumeration<java.net.URL>` `getResources​(java.lang.String name)`
`Strategy` `getStrategy()`
`ClassWorld` `getWorld()`
`void` `importFrom​(java.lang.ClassLoader classLoader, java.lang.String packageName)`
`void` `importFrom​(java.lang.String realmId, java.lang.String packageName)`
`void` `importFromParent​(java.lang.String packageName)`
`java.lang.Class<?>` `loadClass​(java.lang.String name)`
`protected java.lang.Class<?>` `loadClass​(java.lang.String name, boolean resolve)`
`java.lang.Class<?>` `loadClassFromImport​(java.lang.String name)`
`java.lang.Class<?>` `loadClassFromParent​(java.lang.String name)`
`java.lang.Class<?>` `loadClassFromSelf​(java.lang.String name)`
`java.net.URL` `loadResourceFromImport​(java.lang.String name)`
`java.net.URL` `loadResourceFromParent​(java.lang.String name)`
`java.net.URL` `loadResourceFromSelf​(java.lang.String name)`
`java.util.Enumeration<java.net.URL>` `loadResourcesFromImport​(java.lang.String name)`
`java.util.Enumeration<java.net.URL>` `loadResourcesFromParent​(java.lang.String name)`
`java.util.Enumeration<java.net.URL>` `loadResourcesFromSelf​(java.lang.String name)`
`void` `setParentClassLoader​(java.lang.ClassLoader parentClassLoader)`
`void` `setParentRealm​(ClassRealm realm)`
`java.lang.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, findResource, findSystemClass, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, 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,
                      java.lang.String id,
                      java.lang.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 java.lang.String getId()

#### getWorld

    public ClassWorld getWorld()

#### importFromParent

    public void importFromParent​(java.lang.String packageName)

#### importFrom

    public void importFrom​(java.lang.String realmId,
                           java.lang.String packageName)
                    throws NoSuchRealmException

Throws:
  `NoSuchRealmException`

#### importFrom

    public void importFrom​(java.lang.ClassLoader classLoader,
                           java.lang.String packageName)

#### getImportClassLoader

    public java.lang.ClassLoader getImportClassLoader​(java.lang.String name)

#### getImportRealms

    public java.util.Collection<ClassRealm> getImportRealms()

#### getStrategy

    public Strategy getStrategy()

#### setParentClassLoader

    public void setParentClassLoader​(java.lang.ClassLoader parentClassLoader)

#### getParentClassLoader

    public java.lang.ClassLoader getParentClassLoader()

#### setParentRealm

    public void setParentRealm​(ClassRealm realm)

#### getParentRealm

    public ClassRealm getParentRealm()

#### createChildRealm

    public ClassRealm createChildRealm​(java.lang.String id)
                                throws DuplicateRealmException

Throws:
  `DuplicateRealmException`

#### addURL

    public void addURL​(java.net.URL url)

Overrides:
  `addURL` in class `java.net.URLClassLoader`

#### loadClass

    public java.lang.Class<?> loadClass​(java.lang.String name)
                                 throws java.lang.ClassNotFoundException

Overrides:
  `loadClass` in class `java.lang.ClassLoader`
Throws:
  `java.lang.ClassNotFoundException`

#### loadClass

    protected java.lang.Class<?> loadClass​(java.lang.String name,
                                           boolean resolve)
                                    throws java.lang.ClassNotFoundException

Overrides:
  `loadClass` in class `java.lang.ClassLoader`
Throws:
  `java.lang.ClassNotFoundException`

#### findClass

    protected java.lang.Class<?> findClass​(java.lang.String moduleName,
                                           java.lang.String name)

Overrides:
  `findClass` in class `java.lang.ClassLoader`

#### findClass

    protected java.lang.Class<?> findClass​(java.lang.String name)
                                    throws java.lang.ClassNotFoundException

Overrides:
  `findClass` in class `java.net.URLClassLoader`
Throws:
  `java.lang.ClassNotFoundException`

#### getResource

    public java.net.URL getResource​(java.lang.String name)

Overrides:
  `getResource` in class `java.lang.ClassLoader`

#### findResource

    public java.net.URL findResource​(java.lang.String name)

Overrides:
  `findResource` in class `java.net.URLClassLoader`

#### getResources

    public java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
                                                     throws java.io.IOException

Overrides:
  `getResources` in class `java.lang.ClassLoader`
Throws:
  `java.io.IOException`

#### findResources

    public java.util.Enumeration<java.net.URL> findResources​(java.lang.String name)
                                                      throws java.io.IOException

Overrides:
  `findResources` in class `java.net.URLClassLoader`
Throws:
  `java.io.IOException`

#### display

    public void display()

#### display

    public void display​(java.io.PrintStream out)

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### loadClassFromImport

    public java.lang.Class<?> loadClassFromImport​(java.lang.String name)

#### loadClassFromSelf

    public java.lang.Class<?> loadClassFromSelf​(java.lang.String name)

#### getClassLoadingLock

    protected java.lang.Object getClassLoadingLock​(java.lang.String name)

Overrides:
  `getClassLoadingLock` in class `java.lang.ClassLoader`

#### loadClassFromParent

    public java.lang.Class<?> loadClassFromParent​(java.lang.String name)

#### loadResourceFromImport

    public java.net.URL loadResourceFromImport​(java.lang.String name)

#### loadResourceFromSelf

    public java.net.URL loadResourceFromSelf​(java.lang.String name)

#### loadResourceFromParent

    public java.net.URL loadResourceFromParent​(java.lang.String name)

#### loadResourcesFromImport

    public java.util.Enumeration<java.net.URL> loadResourcesFromImport​(java.lang.String name)

#### loadResourcesFromSelf

    public java.util.Enumeration<java.net.URL> loadResourcesFromSelf​(java.lang.String name)

#### loadResourcesFromParent

    public java.util.Enumeration<java.net.URL> loadResourcesFromParent​(java.lang.String name)