Class RealmClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
UberJarRealmClassLoader

class RealmClassLoader extends URLClassLoader
Classloader for ClassRealms.
Version:
$Id: RealmClassLoader.java 126 2006-01-12 04:17:51Z $
Author:
bob mcwhirter
  • Field Details

  • Constructor Details

    • RealmClassLoader

      RealmClassLoader(DefaultClassRealm realm)
      Construct.
      Parameters:
      realm - The realm for which this loads.
    • RealmClassLoader

      RealmClassLoader(DefaultClassRealm realm, ClassLoader classLoader)
      Construct.
      Parameters:
      realm - The realm for which this loads.
      classLoader - The parent ClassLoader.
  • Method Details

    • getRealm

      DefaultClassRealm getRealm()
      Retrieve the realm.
      Returns:
      The realm.
    • addConstituent

      void addConstituent(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(DataInputStream in) throws 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:
      IOException
    • loadClassDirect

      Class loadClassDirect(String name) throws ClassNotFoundException
      Load a class directly from this classloader without defering through any other ClassRealm.
      Parameters:
      name - The name of the class to load.
      Returns:
      The loaded class.
      Throws:
      ClassNotFoundException - If the class could not be found.
    • loadClass

      protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException
      Load a class.
      Overrides:
      loadClass in class ClassLoader
      Parameters:
      name - The name of the class to load.
      resolve - If true then resolve the class.
      Returns:
      The loaded class.
      Throws:
      ClassNotFoundException - If the class cannot be found.
    • getURLs

      public URL[] getURLs()
      Retrieve the URLs used by this ClassLoader.
      Overrides:
      getURLs in class URLClassLoader
      Returns:
      The urls.
    • findResource

      public URL findResource(String name)
      Find a resource within this ClassLoader only (don't delegate to the parent).
      Overrides:
      findResource in class URLClassLoader
      Returns:
      The resource.
    • getResource

      public URL getResource(String name)
      Overrides:
      getResource in class ClassLoader
    • getResourceDirect

      public URL getResourceDirect(String name)
      Get a resource from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.
      Returns:
      The resource.
    • findResources

      public Enumeration findResources(String name) throws IOException
      Overrides:
      findResources in class URLClassLoader
      Throws:
      IOException
    • findResourcesDirect

      public Enumeration findResourcesDirect(String name) throws IOException
      Find resources from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.
      Returns:
      The resource.
      Throws:
      IOException