Package: org.codehaus.groovy.runtime.metaclass

## [Java] Class ReflectorLoader

- org.codehaus.groovy.runtime.metaclass.ReflectorLoader

-     public class ReflectorLoader
      extends ClassLoader

  Reflector creation helper. This class is used to define the Reflector classes. For each ClassLoader such a loader will be created by MetaClass. Special about this loader is, that it knows the classes form the Groovy Runtime. The Reflector class is resolved in different ways: During the definition of a class Reflector will resolve to the Reflector class of the runtime, even if there is another Reflector class in the parent loader. After the new class is defined Reflector will resolve like other Groovy classes. This loader is able to resolve all Groovy classes even if the parent does not know them, but the parent serves first (Reflector during a class definition is different).

- - ### Constructor Summary

    Constructors
    Constructor and description
    `ReflectorLoader(ClassLoader parent)` Creates a new ReflectorLoader with the specified parent class loader.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Class` | `defineClass(String name, byte[] bytecode, ProtectionDomain domain)` Helper method to define Reflector classes.
    `` | `protected Class` | `findClass(String name)` Tries to find a Groovy class.
    `` | `public Class` | `getLoadedClass(String name)` Retrieves a previously defined Reflector class by name from the cache.
    `` | `protected Class` | `loadClass(String name, boolean resolve)` Loads a class per name.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ClassLoader` | `clearAssertionStatus, equals, getClass, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, hashCode, isRegisteredAsParallelCapable, loadClass, notify, notifyAll, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public ReflectorLoader(ClassLoader parent)

      Creates a new ReflectorLoader with the specified parent class loader. This loader is responsible for defining Reflector classes that can resolve the Reflector class from the Groovy runtime correctly.

      Parameters:
        `parent` - the parent class loader (should never be null)

  - ### Method Detail

    - #### public Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)

      Helper method to define Reflector classes. This method sets the inDefine flag to true during class definition to ensure Reflector is resolved correctly, then resolves the newly defined class and stores it in the loadedClasses cache.

      Parameters:
        `name` - the fully qualified name of the Reflector class
        `bytecode` - the bytecode of the Reflector class
        `domain` - the protection domain for the class
      Returns:
        the newly defined class

    - #### protected Class findClass(String name)

      Tries to find a Groovy class. Uses the delegation loader to load classes when available.

      throws:
        ClassNotFoundException if the class cannot be found
      Parameters:
        `name` - the fully qualified name of the class to find
      Returns:
        the class if found

    - #### public Class getLoadedClass(String name)

      Retrieves a previously defined Reflector class by name from the cache.

      Parameters:
        `name` - the fully qualified name of the Reflector class
      Returns:
        the Reflector class if it has been defined, or null otherwise

    - #### protected Class loadClass(String name, boolean resolve)

      Loads a class per name. Unlike a normal loadClass this version behaves different during a class definition. In that case it checks if the class we want to load is Reflector and returns class if the check is successful. If it is not during a class definition it just calls the super class version of loadClass.

      Parameters:
        `name` - of the class to load
        `resolve` - is true if the class should be resolved
      See Also:
        Reflector
        ClassLoader.loadClass