ClassManagerImpl (jEdit API Documentation)
Date: 2015-10-20

org.gjt.sp.jedit.bsh.classpath

## Class ClassManagerImpl

- java.lang.Object
- - org.gjt.sp.jedit.bsh.BshClassManager
  - - org.gjt.sp.jedit.bsh.classpath.ClassManagerImpl

-     public class ClassManagerImpl
      extends BshClassManager

              Manage all classloading in BeanShell.
              Allows classpath extension and class file reloading.

              This class holds the implementation of the BshClassManager so that it
              can be separated from the core package.

              This class currently relies on 1.2 for BshClassLoader and weak references.
              Is there a workaround for weak refs?  If so we could make this work
              with 1.1 by supplying our own classloader code...

              See "http://www.beanshell.org/manual/classloading.html" for details
              on the bsh classloader architecture.

              Bsh has a multi-tiered class loading architecture.  No class loader is
              created unless/until a class is generated, the classpath is modified,
              or a class is reloaded.

              Note: we may need some synchronization in here

              Note on jdk1.2 dependency:

              We are forced to use weak references here to accomodate all of the
              fleeting namespace listeners.  (NameSpaces must be informed if the class
              space changes so that they can un-cache names).  I had the interesting
              thought that a way around this would be to implement BeanShell's own
              garbage collector...  Then I came to my senses and said - screw it,
              class re-loading will require 1.2.

              ---------------------

              Classloading precedence:

              in-script evaluated class (scripted class)
              in-script added / modified classpath

              optionally, external classloader
              optionally, thread context classloader

              plain Class.forName()
              source class (.java file in classpath)

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.gjt.sp.jedit.bsh.BshClassManager

      `BshClassManager.Listener`

  - ### Field Summary

    - ### Fields inherited from class org.gjt.sp.jedit.bsh.BshClassManager

      `absoluteClassCache, absoluteNonClasses, definingClasses, definingClassesBaseNames, externalClassLoader, resolvedObjectMethods, resolvedStaticMethods`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClassManagerImpl()` Used by BshClassManager singleton constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addClassPath(java.net.URL path)`
    `void` | `addListener(BshClassManager.Listener l)`
    `java.lang.Class` | `classForName(java.lang.String name)` Load the specified class by name, taking into account added classpath and reloaded classes, etc.
    `protected void` | `classLoaderChanged()` Clear global class cache and notify namespaces to clear their class caches.
    `java.lang.Class` | `defineClass(java.lang.String name, byte[] code)` Get the BeanShell classloader.
    `void` | `doSuperImport()` Support for "import *;" Hide details in here as opposed to NameSpace.
    `void` | `dump(java.io.PrintWriter i)`
    `java.lang.ClassLoader` | `getBaseLoader()`
    `java.lang.String` | `getClassNameByUnqName(java.lang.String name)` Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous.
    `BshClassPath` | `getClassPath()` Get the full blown classpath.
    `java.net.URL` | `getResource(java.lang.String path)` Get a resource URL using the BeanShell classpath
    `java.io.InputStream` | `getResourceAsStream(java.lang.String path)` Get a resource stream using the BeanShell classpath
    `protected boolean` | `hasSuperImport()` A "super import" ("import *") operation has been performed.
    `void` | `reloadAllClasses()` Overlay the entire path with a new class loader.
    `void` | `reloadClasses(java.lang.String[] classNames)` Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space.
    `void` | `reloadPackage(java.lang.String pack)` Reload all classes in the specified package: e.g.
    `void` | `removeListener(BshClassManager.Listener l)`
    `void` | `reset()` Clear all classloading behavior and class caches and reset to initial state.
    `void` | `setClassPath(java.net.URL[] cp)` Set a new base classpath and create a new base classloader.

    - ### Methods inherited from class org.gjt.sp.jedit.bsh.BshClassManager

      `cacheClassInfo, cacheResolvedMethod, classExists, clearCaches, cmUnavailable, createClassManager, definingClass, doneDefiningClass, getClassBeingDefined, getResolvedMethod, isClassBeingDefined, loadSourceClass, noClassDefFound, plainClassForName, setClassLoader`

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

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

- - ### Constructor Detail

    - #### ClassManagerImpl

          public ClassManagerImpl()

      Used by BshClassManager singleton constructor

  - ### Method Detail

    - #### classForName

          public java.lang.Class classForName(java.lang.String name)

      Description copied from class: `BshClassManager`
      Load the specified class by name, taking into account added classpath and reloaded classes, etc. Note: Again, this is just a trivial implementation. See bsh.classpath.ClassManagerImpl for the fully functional class management package.
      Overrides:
        `classForName` in class `BshClassManager`
      Returns:
        the class or null

    - #### getResource

          public java.net.URL getResource(java.lang.String path)

      Get a resource URL using the BeanShell classpath
      Overrides:
        `getResource` in class `BshClassManager`
      Parameters:
        `path` - should be an absolute path

    - #### getResourceAsStream

          public java.io.InputStream getResourceAsStream(java.lang.String path)

      Get a resource stream using the BeanShell classpath
      Overrides:
        `getResourceAsStream` in class `BshClassManager`
      Parameters:
        `path` - should be an absolute path

    - #### addClassPath

          public void addClassPath(java.net.URL path)
                            throws java.io.IOException

      Overrides:
        `addClassPath` in class `BshClassManager`
      Throws:
        `java.io.IOException`

    - #### reset

          public void reset()

      Clear all classloading behavior and class caches and reset to initial state.
      Overrides:
        `reset` in class `BshClassManager`

    - #### setClassPath

          public void setClassPath(java.net.URL[] cp)

      Set a new base classpath and create a new base classloader. This means all types change.
      Overrides:
        `setClassPath` in class `BshClassManager`

    - #### reloadAllClasses

          public void reloadAllClasses()
                                throws ClassPathException

      Overlay the entire path with a new class loader. Set the base path to the user path + base path. No point in including the boot class path (can't reload thos).
      Overrides:
        `reloadAllClasses` in class `BshClassManager`
      Throws:
        `ClassPathException`

    - #### reloadClasses

          public void reloadClasses(java.lang.String[] classNames)
                             throws ClassPathException

      Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space. For this we use a DiscreteFilesClassLoader
      Overrides:
        `reloadClasses` in class `BshClassManager`
      Throws:
        `ClassPathException`

    - #### reloadPackage

          public void reloadPackage(java.lang.String pack)
                             throws ClassPathException

      Reload all classes in the specified package: e.g. "com.sun.tools" The special package name "<unpackaged>" can be used to refer to unpackaged classes.
      Overrides:
        `reloadPackage` in class `BshClassManager`
      Throws:
        `ClassPathException`

    - #### getClassPath

          public BshClassPath getClassPath()
                                    throws ClassPathException

      Get the full blown classpath.
      Throws:
        `ClassPathException`

    - #### doSuperImport

          public void doSuperImport()
                             throws UtilEvalError

      Support for "import *;" Hide details in here as opposed to NameSpace.
      Overrides:
        `doSuperImport` in class `BshClassManager`
      Throws:
        `UtilEvalError`

    - #### hasSuperImport

          protected boolean hasSuperImport()

      Description copied from class: `BshClassManager`
      A "super import" ("import *") operation has been performed.
      Overrides:
        `hasSuperImport` in class `BshClassManager`

    - #### getClassNameByUnqName

          public java.lang.String getClassNameByUnqName(java.lang.String name)
                                                 throws ClassPathException

      Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous.
      Overrides:
        `getClassNameByUnqName` in class `BshClassManager`
      Throws:
        `ClassPathException`

    - #### addListener

          public void addListener(BshClassManager.Listener l)

      Overrides:
        `addListener` in class `BshClassManager`

    - #### removeListener

          public void removeListener(BshClassManager.Listener l)

      Overrides:
        `removeListener` in class `BshClassManager`

    - #### getBaseLoader

          public java.lang.ClassLoader getBaseLoader()

    - #### defineClass

          public java.lang.Class defineClass(java.lang.String name,
                                             byte[] code)

      Get the BeanShell classloader. public ClassLoader getClassLoader() { }
      Overrides:
        `defineClass` in class `BshClassManager`

    - #### classLoaderChanged

          protected void classLoaderChanged()

      Clear global class cache and notify namespaces to clear their class caches. The listener list is implemented with weak references so that we will not keep every namespace in existence forever.
      Overrides:
        `classLoaderChanged` in class `BshClassManager`

    - #### dump

          public void dump(java.io.PrintWriter i)

      Overrides:
        `dump` in class `BshClassManager`