grails.test
Class AbstractClosureProxy

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by groovy.lang.Closure
          extended by grails.test.AbstractClosureProxy
All Implemented Interfaces:
groovy.lang.GroovyObject, Serializable, Cloneable, Runnable
Direct Known Subclasses:
MockClosureProxy

public abstract class AbstractClosureProxy
extends groovy.lang.Closure

Skeleton implementation of a wrapper class for closures that allows you to intercept invocations of the closure. The wrapper can be used anywhere that the target closure can be used.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class groovy.lang.Closure
DELEGATE_FIRST, DELEGATE_ONLY, DONE, maximumNumberOfParameters, OWNER_FIRST, OWNER_ONLY, parameterTypes, SKIP, TO_SELF
 
Constructor Summary
AbstractClosureProxy(groovy.lang.Closure closure)
          Creates a new instance that wraps the target closure and sends profiling events to the given profiler log.
 
Method Summary
 groovy.lang.Closure asWritable()
           
 Object call(Object[] objects)
          This is the important one: logs entry and exit of the closure call.
protected abstract  groovy.lang.Closure createWrapper(groovy.lang.Closure c)
          Called when a new instance of the proxy needs to be created for the given closure.
 groovy.lang.Closure curry(Object[] objects)
           
protected abstract  void doAfterCall(Object[] args)
          This method is called after the target closure is invoked.
protected abstract  void doBeforeCall(Object[] args)
          This method is called before the target closure is invoked.
 boolean equals(Object obj)
          Compares based on identities, but unlike the standard implementation this one will return true if the given object is the target closure for this wrapper as well.
 Object getDelegate()
           
 int getDirective()
           
 int getMaximumNumberOfParameters()
           
 Class[] getParameterTypes()
           
 Object getProperty(String property)
           
 int getResolveStrategy()
           
 int hashCode()
           
 boolean isCase(Object o)
           
 void setDelegate(Object o)
           
 void setDirective(int i)
           
 void setProperty(String s, Object o)
           
 void setResolveStrategy(int i)
           
 
Methods inherited from class groovy.lang.Closure
call, call, clone, getOwner, getThisObject, run, throwRuntimeException
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, invokeMethod, setMetaClass
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractClosureProxy

public AbstractClosureProxy(groovy.lang.Closure closure)
Creates a new instance that wraps the target closure and sends profiling events to the given profiler log.

Parameters:
closure - The target closure to wrap.
Method Detail

doBeforeCall

protected abstract void doBeforeCall(Object[] args)
This method is called before the target closure is invoked. This is a passive interceptor, so you cannot prevent the call to the target closure. You can modify the arguments, though, but it's not recommended unless you really know what you're doing.

Parameters:
args - The arguments passed to the closure.

doAfterCall

protected abstract void doAfterCall(Object[] args)
This method is called after the target closure is invoked. It will be triggered whether or not an exception is thrown by the target closure.

Parameters:
args - The arguments passed to the closure.

createWrapper

protected abstract groovy.lang.Closure createWrapper(groovy.lang.Closure c)
Called when a new instance of the proxy needs to be created for the given closure. Usually the implementation simply creates a new instance of the current class, copying over the existing proxy properties:
    return new MyClosureProxy(c, this.field1, ...)
 

Parameters:
c - The closure to wrap/proxy.

call

public Object call(Object[] objects)
This is the important one: logs entry and exit of the closure call.

Overrides:
call in class groovy.lang.Closure

equals

public boolean equals(Object obj)
Compares based on identities, but unlike the standard implementation this one will return true if the given object is the target closure for this wrapper as well.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

curry

public groovy.lang.Closure curry(Object[] objects)
Overrides:
curry in class groovy.lang.Closure

isCase

public boolean isCase(Object o)
Overrides:
isCase in class groovy.lang.Closure

asWritable

public groovy.lang.Closure asWritable()
Overrides:
asWritable in class groovy.lang.Closure

getProperty

public Object getProperty(String property)
Specified by:
getProperty in interface groovy.lang.GroovyObject
Overrides:
getProperty in class groovy.lang.Closure

setProperty

public void setProperty(String s,
                        Object o)
Specified by:
setProperty in interface groovy.lang.GroovyObject
Overrides:
setProperty in class groovy.lang.Closure

getMaximumNumberOfParameters

public int getMaximumNumberOfParameters()
Overrides:
getMaximumNumberOfParameters in class groovy.lang.Closure

getParameterTypes

public Class[] getParameterTypes()
Overrides:
getParameterTypes in class groovy.lang.Closure

getDelegate

public Object getDelegate()
Overrides:
getDelegate in class groovy.lang.Closure

setDelegate

public void setDelegate(Object o)
Overrides:
setDelegate in class groovy.lang.Closure

getDirective

public int getDirective()
Overrides:
getDirective in class groovy.lang.Closure

setDirective

public void setDirective(int i)
Overrides:
setDirective in class groovy.lang.Closure

getResolveStrategy

public int getResolveStrategy()
Overrides:
getResolveStrategy in class groovy.lang.Closure

setResolveStrategy

public void setResolveStrategy(int i)
Overrides:
setResolveStrategy in class groovy.lang.Closure


Copyright (c) 2005-2009 The Grails project