Package: groovy.util

## [Java] Class ProxyGenerator

- groovy.util.ProxyGenerator

-     public class ProxyGenerator
      extends Object

  Generates 'Proxy' objects which implement interfaces, maps of closures and/or extend classes/delegates.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static ProxyGenerator` | `INSTANCE` | Shared proxy generator instance used by Groovy's coercion helpers.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `getDebug()` Reports whether generated source is echoed for debugging.
    `` | `public boolean` | `getEmptyMethods()` Reports whether unimplemented generated methods use empty bodies.
    `` | `public ClassLoader` | `getOverride()` Returns the override class loader used for proxy generation.
    `` | `public GroovyObject` | `instantiateAggregate(List<Class> interfaces)` Creates an aggregate proxy implementing the supplied interfaces.
    `` | `public GroovyObject` | `instantiateAggregate(Map closureMap, List<Class> interfaces)` Creates an aggregate proxy implementing the supplied interfaces.
    `` | `public GroovyObject` | `instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz)` Creates an aggregate proxy with optional interfaces and base class.
    `` | `public GroovyObject` | `instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz, Object[] constructorArgs)` Creates an aggregate proxy with optional interfaces, base class and constructor arguments.
    `` | `public GroovyObject` | `instantiateAggregateFromBaseClass(Class clazz)` Creates an aggregate proxy that extends the supplied base class.
    `` | `public GroovyObject` | `instantiateAggregateFromBaseClass(Map map, Class clazz)` Creates an aggregate proxy that extends the supplied base class.
    `` | `public GroovyObject` | `instantiateAggregateFromBaseClass(Closure cl, Class clazz)` Creates an aggregate proxy that routes all unresolved methods through one closure.
    `` | `public GroovyObject` | `instantiateAggregateFromBaseClass(Class clazz, Object[] constructorArgs)` Creates an aggregate proxy with constructor arguments.
    `` | `public GroovyObject` | `instantiateAggregateFromBaseClass(Map map, Class clazz, Object[] constructorArgs)` Creates an aggregate proxy with closures and constructor arguments.
    `` | `public GroovyObject` | `instantiateAggregateFromInterface(Class clazz)` Creates an aggregate proxy that implements a single interface.
    `` | `public GroovyObject` | `instantiateAggregateFromInterface(Map map, Class clazz)` Creates an aggregate proxy that implements a single interface.
    `` | `public GroovyObject` | `instantiateDelegate(Object delegate)` Creates a delegating proxy around the supplied object.
    `` | `public GroovyObject` | `instantiateDelegate(List<Class> interfaces, Object delegate)` Creates a delegating proxy with additional implemented interfaces.
    `` | `public GroovyObject` | `instantiateDelegate(Map closureMap, List<Class> interfaces, Object delegate)` Creates a delegating proxy with supplemental closure implementations.
    `` | `public GroovyObject` | `instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate)` Creates a delegating proxy whose base class is the delegate type.
    `` | `public GroovyObject` | `instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass)` Creates a delegating proxy with an explicit base class.
    `` | `public GroovyObject` | `instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass, String name)` Creates a proxy with a delegate object.
    `` | `public void` | `setDebug(boolean debug)` Instructs `ProxyGenerator` to dump generated Groovy source code to standard output during construction.
    `` | `public void` | `setEmptyMethods(boolean emptyMethods)` Changes generated methods to have empty implementations.
    `` | `public void` | `setOverride(ClassLoader override)` Sets the override class loader used for proxy generation.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final ProxyGenerator INSTANCE

      Shared proxy generator instance used by Groovy's coercion helpers.

  - ### Method Detail

    - #### public boolean getDebug()

      Reports whether generated source is echoed for debugging.

      Returns:
        `true` when debug output is enabled

    - #### public boolean getEmptyMethods()

      Reports whether unimplemented generated methods use empty bodies.

      Returns:
        `true` when empty method bodies are generated

    - #### public ClassLoader getOverride()

      Returns the override class loader used for proxy generation.

      Returns:
        the override class loader, or `null`

    - #### public GroovyObject instantiateAggregate(List<Class> interfaces)

      Creates an aggregate proxy implementing the supplied interfaces.

      Parameters:
        `interfaces` - interfaces to implement
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregate(Map closureMap, List<Class> interfaces)

      Creates an aggregate proxy implementing the supplied interfaces.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz)

      Creates an aggregate proxy with optional interfaces and base class.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
        `clazz` - the base class to extend
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz, Object[] constructorArgs)

      Creates an aggregate proxy with optional interfaces, base class and constructor arguments.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
        `clazz` - the base class to extend
        `constructorArgs` - constructor arguments for the proxy instance
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromBaseClass(Class clazz)

      Creates an aggregate proxy that extends the supplied base class.

      Parameters:
        `clazz` - the base class to extend
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromBaseClass(Map map, Class clazz)

      Creates an aggregate proxy that extends the supplied base class.

      Parameters:
        `map` - closures implementing selected methods
        `clazz` - the base class to extend
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromBaseClass(Closure cl, Class clazz)

      Creates an aggregate proxy that routes all unresolved methods through one closure.

      Parameters:
        `cl` - fallback closure for method calls
        `clazz` - the base class to extend
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromBaseClass(Class clazz, Object[] constructorArgs)

      Creates an aggregate proxy with constructor arguments.

      Parameters:
        `clazz` - the base class to extend
        `constructorArgs` - constructor arguments for the proxy instance
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromBaseClass(Map map, Class clazz, Object[] constructorArgs)

      Creates an aggregate proxy with closures and constructor arguments.

      Parameters:
        `map` - closures implementing selected methods
        `clazz` - the base class to extend
        `constructorArgs` - constructor arguments for the proxy instance
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromInterface(Class clazz)

      Creates an aggregate proxy that implements a single interface.

      Parameters:
        `clazz` - the interface to implement
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateAggregateFromInterface(Map map, Class clazz)

      Creates an aggregate proxy that implements a single interface.

      Parameters:
        `map` - closures implementing selected methods
        `clazz` - the interface to implement
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegate(Object delegate)

      Creates a delegating proxy around the supplied object.

      Parameters:
        `delegate` - the delegate object
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegate(List<Class> interfaces, Object delegate)

      Creates a delegating proxy with additional implemented interfaces.

      Parameters:
        `interfaces` - interfaces to implement
        `delegate` - the delegate object
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegate(Map closureMap, List<Class> interfaces, Object delegate)

      Creates a delegating proxy with supplemental closure implementations.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
        `delegate` - the delegate object
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate)

      Creates a delegating proxy whose base class is the delegate type.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
        `delegate` - the delegate object
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass)

      Creates a delegating proxy with an explicit base class.

      Parameters:
        `closureMap` - closures implementing selected methods
        `interfaces` - interfaces to implement
        `delegate` - the delegate object
        `baseClass` - the base class to extend
      Returns:
        the generated proxy

    - #### public GroovyObject instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass, String name)

      Creates a proxy with a delegate object.

      Parameters:
        `closureMap` - the closure for methods not handled by the delegate
        `interfaces` - interfaces to be implemented
        `delegate` - the delegate object
        `baseClass` - the base class
        `name` - the name of the proxy, unused, but kept for compatibility with previous versions of Groovy.
      Returns:
        a proxy object implementing the specified interfaces, and delegating to the provided object

    - #### public void setDebug(boolean debug)

      Instructs `ProxyGenerator` to dump generated Groovy source code to standard output during construction. This is useful for debugging purposes but should be turned off in production.

      Parameters:
        `debug` - true if you want generated source to be printed

    - #### public void setEmptyMethods(boolean emptyMethods)

      Changes generated methods to have empty implementations.

      Methods in generated aggregates not supplied in a closures map or base class are given 'default' implementations. The implementation will normally throw an `UnsupportedOperationException` but setting this boolean will leave it empty.

      Parameters:
        `emptyMethods` - true if you want generated methods to be empty

    - #### public void setOverride(ClassLoader override)

      Sets the override class loader used for proxy generation.

      Parameters:
        `override` - the override class loader