Class GroovyInterceptor

java.lang.Object
org.kohsuke.groovy.sandbox.GroovyInterceptor
Direct Known Subclasses:
GroovyValueFilter, RejectEverythingInterceptor

public abstract class GroovyInterceptor extends Object
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
  • 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 are Class can invoke static methods, too (that is, x=Integer.class;x.valueOf(5) results in onMethodCall(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 a super(…) 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 property
      value - 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 attribute
      value - 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 of register()
    • getApplicableInterceptors

      public static List<GroovyInterceptor> getApplicableInterceptors()