Package org.kohsuke.groovy.sandbox
Class GroovyInterceptor
java.lang.Object
org.kohsuke.groovy.sandbox.GroovyInterceptor
- Direct Known Subclasses:
GroovyValueFilter,RejectEverythingInterceptor
Interceptor of Groovy method calls.
Once created, it needs to be registered to start receiving interceptions. List of interceptors are maintained per thread.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents the next interceptor in the chain. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<GroovyInterceptor>onGetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index) Intercepts an array access, like "z=foo[bar]"onGetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute) Intercepts an attribute access, like "z=foo.@bar"onGetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property) Intercepts a property access, like "z=foo.bar"onMethodCall(GroovyInterceptor.Invoker invoker, Object receiver, String method, Object... args) Intercepts an instance method call on some object of the form "foo.bar(...)"onNewInstance(GroovyInterceptor.Invoker invoker, Class receiver, Object... args) Intercepts an object instantiation, like "new Receiver(...)"onSetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index, Object value) Intercepts an attribute assignment like "foo[bar]=z"onSetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute, Object value) Intercepts an attribute assignment like "foo.@bar=z"onSetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property, Object value) Intercepts a property assignment like "foo.bar=z"onStaticCall(GroovyInterceptor.Invoker invoker, Class receiver, String method, Object... args) Intercepts a static method call on some class, like "Class.forName(...)".onSuperCall(GroovyInterceptor.Invoker invoker, Class senderType, Object receiver, String method, Object... args) Intercepts an super method call, like "super.foo(...)"voidonSuperConstructor(GroovyInterceptor.Invoker invoker, Class receiver, Object... args) Intercepts asuper(…)call from a constructor.voidregister()Registers this interceptor to the current thread's interceptor list.voidReverses the earlier effect ofregister()
-
Constructor Details
-
GroovyInterceptor
public GroovyInterceptor()
-
-
Method Details
-
onMethodCall
public Object onMethodCall(GroovyInterceptor.Invoker invoker, Object receiver, String method, Object... args) throws Throwable Intercepts an instance method call on some object of the form "foo.bar(...)"- Throws:
Throwable
-
onStaticCall
public Object onStaticCall(GroovyInterceptor.Invoker invoker, Class receiver, String method, Object... args) throws Throwable Intercepts a static method call on some class, like "Class.forName(...)". Note that Groovy doesn't clearly differentiate static method calls from instance method calls. If calls are determined to be static at compile-time, you get this method called, but method calls whose receivers areClasscan invoke static methods, too (that is,x=Integer.class;x.valueOf(5)results inonMethodCall(invoker,Integer.class,"valueOf",5)- Throws:
Throwable
-
onNewInstance
public Object onNewInstance(GroovyInterceptor.Invoker invoker, Class receiver, Object... args) throws Throwable Intercepts an object instantiation, like "new Receiver(...)"- Throws:
Throwable
-
onSuperCall
public Object onSuperCall(GroovyInterceptor.Invoker invoker, Class senderType, Object receiver, String method, Object... args) throws Throwable Intercepts an super method call, like "super.foo(...)"- Throws:
Throwable
-
onSuperConstructor
public void onSuperConstructor(GroovyInterceptor.Invoker invoker, Class receiver, Object... args) throws Throwable Intercepts asuper(…)call from a constructor.- Throws:
Throwable
-
onGetProperty
public Object onGetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property) throws Throwable Intercepts a property access, like "z=foo.bar"- Parameters:
receiver- 'foo' in the above example, the object whose property is accessed.property- 'bar' in the above example, the name of the property- Throws:
Throwable
-
onSetProperty
public Object onSetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property, Object value) throws Throwable Intercepts a property assignment like "foo.bar=z"- Parameters:
receiver- 'foo' in the above example, the object whose property is accessed.property- 'bar' in the above example, the name of the propertyvalue- The value to be assigned.- Returns:
- The result of the assignment expression. Normally, you should return the same object as
value. - Throws:
Throwable
-
onGetAttribute
public Object onGetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute) throws Throwable Intercepts an attribute access, like "z=foo.@bar"- Parameters:
receiver- 'foo' in the above example, the object whose attribute is accessed.attribute- 'bar' in the above example, the name of the attribute- Throws:
Throwable
-
onSetAttribute
public Object onSetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute, Object value) throws Throwable Intercepts an attribute assignment like "foo.@bar=z"- Parameters:
receiver- 'foo' in the above example, the object whose attribute is accessed.attribute- 'bar' in the above example, the name of the attributevalue- The value to be assigned.- Returns:
- The result of the assignment expression. Normally, you should return the same object as
value. - Throws:
Throwable
-
onGetArray
public Object onGetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index) throws Throwable Intercepts an array access, like "z=foo[bar]"- Parameters:
receiver- 'foo' in the above example, the array-like object.index- 'bar' in the above example, the object that acts as an index.- Throws:
Throwable
-
onSetArray
public Object onSetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index, Object value) throws Throwable Intercepts an attribute assignment like "foo[bar]=z"- Parameters:
receiver- 'foo' in the above example, the array-like object.index- 'bar' in the above example, the object that acts as an index.value- The value to be assigned.- Returns:
- The result of the assignment expression. Normally, you should return the same object as
value. - Throws:
Throwable
-
register
public void register()Registers this interceptor to the current thread's interceptor list. -
unregister
public void unregister()Reverses the earlier effect ofregister() -
getApplicableInterceptors
-