groovy.lang
Interface ProxyMetaClass

As subclass of MetaClass, ProxyMetaClass manages calls from Groovy Objects to POJOs. It enriches MetaClass with the feature of making method invokations interceptable by an Interceptor. To this end, it acts as a decorator (decorator pattern) allowing to add or withdraw this feature at runtime. See groovy/lang/InterceptorTest.groovy for details.

WARNING: This implementation of ProxyMetaClass is NOT threadsafe and hence should only be used for as a per-instance MetaClass running in a single thread. Do not place this MetaClass in the MetaClassRegistry as it will result in unpredictable behaviour

author:
Dierk Koenig
author:
Graeme Rocher
see:
MetaClassRegistry

Field Summary
 MetaClass adaptee
           
 Interceptor interceptor
           
 
Constructor Summary
ProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)
           
 
Method Summary
Object call()
          
Object doCall(Object object, String methodName, def arguments, Interceptor interceptor, Callable howToInvoke)
          
MetaClass getAdaptee()
          
static ProxyMetaClass getInstance(Class theClass)
           convenience factory method for the most usual case.
Interceptor getInterceptor()
          
Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1)
           Interceptors the call to getProperty if a PropertyAccessInterceptor is available
void initialize()
          
Object invokeConstructor(def arguments)
           Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.
Object invokeMethod(Object object, String methodName, def arguments)
           Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
Object invokeStaticMethod(Object object, String methodName, def arguments)
           Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
void setAdaptee(MetaClass metaClass)
          
void setInterceptor(Interceptor interceptor)
          
void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1)
           Interceptors the call to a property setter if a PropertyAccessInterceptor is available
void use(Closure closure)
           Use the ProxyMetaClass for the given Closure.
void use(GroovyObject object, Closure closure)
           Use the ProxyMetaClass for the given Closure.
 

Constructor Detail

ProxyMetaClass

public ProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)
param:
adaptee the MetaClass to decorate with interceptability


Method Detail

call

public Object call()


doCall

Object doCall(Object object, String methodName, def arguments, Interceptor interceptor, Callable howToInvoke)


getAdaptee

public MetaClass getAdaptee()


getInstance

public static ProxyMetaClass getInstance(Class theClass)
convenience factory method for the most usual case.


getInterceptor

public Interceptor getInterceptor()
return:
the interceptor in use or null if no interceptor is used


getProperty

public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1)
Interceptors the call to getProperty if a PropertyAccessInterceptor is available
param:
object the object to invoke the getter on
param:
property the property name
return:
the value of the property


initialize

public void initialize()


invokeConstructor

public Object invokeConstructor(def arguments)
Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor. With Interceptor the call is nested in its beforeInvoke and afterInvoke methods. The method call is suppressed if Interceptor.doInvoke() returns false. See Interceptor for details.


invokeMethod

public Object invokeMethod(Object object, String methodName, def arguments)
Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor. With Interceptor the call is nested in its beforeInvoke and afterInvoke methods. The method call is suppressed if Interceptor.doInvoke() returns false. See Interceptor for details.


invokeStaticMethod

public Object invokeStaticMethod(Object object, String methodName, def arguments)
Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor. With Interceptor the call is nested in its beforeInvoke and afterInvoke methods. The method call is suppressed if Interceptor.doInvoke() returns false. See Interceptor for details.


setAdaptee

public void setAdaptee(MetaClass metaClass)


setInterceptor

public void setInterceptor(Interceptor interceptor)
param:
interceptor may be null to reset any interception


setProperty

public void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1)
Interceptors the call to a property setter if a PropertyAccessInterceptor is available
param:
object The object to invoke the setter on
param:
property The property name to set
param:
newValue The new value of the property


use

public void use(Closure closure)
Use the ProxyMetaClass for the given Closure. Cares for balanced register/unregister.
param:
closure piece of code to be executed with registered ProxyMetaClass


use

public void use(GroovyObject object, Closure closure)
Use the ProxyMetaClass for the given Closure. Cares for balanced setting/unsetting ProxyMetaClass.
param:
closure piece of code to be executed with ProxyMetaClass