Package groovy.util
Class ProxyGenerator
java.lang.Object
groovy.util.ProxyGenerator
Generates 'Proxy' objects which implement interfaces, maps of closures and/or
extend classes/delegates.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ProxyGeneratorShared proxy generator instance used by Groovy's coercion helpers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleangetDebug()Reports whether generated source is echoed for debugging.booleanReports whether unimplemented generated methods use empty bodies.Returns the override class loader used for proxy generation.instantiateAggregate(List<Class> interfaces) Creates an aggregate proxy implementing the supplied interfaces.instantiateAggregate(Map closureMap, List<Class> interfaces) Creates an aggregate proxy implementing the supplied interfaces.instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz) Creates an aggregate proxy with optional interfaces and base class.Creates an aggregate proxy with optional interfaces, base class and constructor arguments.instantiateAggregateFromBaseClass(Closure cl, Class clazz) Creates an aggregate proxy that routes all unresolved methods through one closure.Creates an aggregate proxy that extends the supplied base class.instantiateAggregateFromBaseClass(Class clazz, Object[] constructorArgs) Creates an aggregate proxy with constructor arguments.instantiateAggregateFromBaseClass(Map map, Class clazz) Creates an aggregate proxy that extends the supplied base class.instantiateAggregateFromBaseClass(Map map, Class clazz, Object[] constructorArgs) Creates an aggregate proxy with closures and constructor arguments.Creates an aggregate proxy that implements a single interface.instantiateAggregateFromInterface(Map map, Class clazz) Creates an aggregate proxy that implements a single interface.instantiateDelegate(Object delegate) Creates a delegating proxy around the supplied object.instantiateDelegate(List<Class> interfaces, Object delegate) Creates a delegating proxy with additional implemented interfaces.instantiateDelegate(Map closureMap, List<Class> interfaces, Object delegate) Creates a delegating proxy with supplemental closure implementations.instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate) Creates a delegating proxy whose base class is the delegate type.instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass) Creates a delegating proxy with an explicit base class.instantiateDelegateWithBaseClass(Map closureMap, List<Class> interfaces, Object delegate, Class baseClass, String name) Creates a proxy with a delegate object.voidsetDebug(boolean debug) InstructsProxyGeneratorto dump generated Groovy source code to standard output during construction.voidsetEmptyMethods(boolean emptyMethods) Changes generated methods to have empty implementations.voidsetOverride(ClassLoader override) Sets the override class loader used for proxy generation.
-
Field Details
-
INSTANCE
Shared proxy generator instance used by Groovy's coercion helpers.
-
-
Constructor Details
-
ProxyGenerator
public ProxyGenerator()
-
-
Method Details
-
getDebug
public boolean getDebug()Reports whether generated source is echoed for debugging.- Returns:
truewhen debug output is enabled
-
setDebug
public void setDebug(boolean debug) InstructsProxyGeneratorto 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
-
getEmptyMethods
public boolean getEmptyMethods()Reports whether unimplemented generated methods use empty bodies.- Returns:
truewhen empty method bodies are generated
-
setEmptyMethods
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
UnsupportedOperationExceptionbut setting this boolean will leave it empty.- Parameters:
emptyMethods- true if you want generated methods to be empty
-
getOverride
Returns the override class loader used for proxy generation.- Returns:
- the override class loader, or
null
-
setOverride
Sets the override class loader used for proxy generation.- Parameters:
override- the override class loader
-
instantiateAggregateFromBaseClass
Creates an aggregate proxy that extends the supplied base class.- Parameters:
clazz- the base class to extend- Returns:
- the generated proxy
-
instantiateAggregateFromBaseClass
Creates an aggregate proxy that extends the supplied base class.- Parameters:
map- closures implementing selected methodsclazz- the base class to extend- Returns:
- the generated proxy
-
instantiateAggregateFromBaseClass
Creates an aggregate proxy that routes all unresolved methods through one closure.- Parameters:
cl- fallback closure for method callsclazz- the base class to extend- Returns:
- the generated proxy
-
instantiateAggregateFromBaseClass
Creates an aggregate proxy with constructor arguments.- Parameters:
clazz- the base class to extendconstructorArgs- constructor arguments for the proxy instance- Returns:
- the generated proxy
-
instantiateAggregateFromBaseClass
public GroovyObject instantiateAggregateFromBaseClass(Map map, Class clazz, Object[] constructorArgs) Creates an aggregate proxy with closures and constructor arguments.- Parameters:
map- closures implementing selected methodsclazz- the base class to extendconstructorArgs- constructor arguments for the proxy instance- Returns:
- the generated proxy
-
instantiateAggregateFromInterface
Creates an aggregate proxy that implements a single interface.- Parameters:
clazz- the interface to implement- Returns:
- the generated proxy
-
instantiateAggregateFromInterface
Creates an aggregate proxy that implements a single interface.- Parameters:
map- closures implementing selected methodsclazz- the interface to implement- Returns:
- the generated proxy
-
instantiateAggregate
Creates an aggregate proxy implementing the supplied interfaces.- Parameters:
interfaces- interfaces to implement- Returns:
- the generated proxy
-
instantiateAggregate
Creates an aggregate proxy implementing the supplied interfaces.- Parameters:
closureMap- closures implementing selected methodsinterfaces- interfaces to implement- Returns:
- the generated proxy
-
instantiateAggregate
Creates an aggregate proxy with optional interfaces and base class.- Parameters:
closureMap- closures implementing selected methodsinterfaces- interfaces to implementclazz- the base class to extend- Returns:
- the generated proxy
-
instantiateAggregate
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 methodsinterfaces- interfaces to implementclazz- the base class to extendconstructorArgs- constructor arguments for the proxy instance- Returns:
- the generated proxy
-
instantiateDelegate
Creates a delegating proxy around the supplied object.- Parameters:
delegate- the delegate object- Returns:
- the generated proxy
-
instantiateDelegate
Creates a delegating proxy with additional implemented interfaces.- Parameters:
interfaces- interfaces to implementdelegate- the delegate object- Returns:
- the generated proxy
-
instantiateDelegate
Creates a delegating proxy with supplemental closure implementations.- Parameters:
closureMap- closures implementing selected methodsinterfaces- interfaces to implementdelegate- the delegate object- Returns:
- the generated proxy
-
instantiateDelegateWithBaseClass
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 methodsinterfaces- interfaces to implementdelegate- the delegate object- Returns:
- the generated proxy
-
instantiateDelegateWithBaseClass
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 methodsinterfaces- interfaces to implementdelegate- the delegate objectbaseClass- the base class to extend- Returns:
- the generated proxy
-
instantiateDelegateWithBaseClass
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 delegateinterfaces- interfaces to be implementeddelegate- the delegate objectbaseClass- the base classname- 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
-