groovy.lang
Class ProxyMetaClass

java.lang.Object
  extended by groovy.lang.MetaClass
      extended by groovy.lang.MetaClassImpl
          extended by groovy.lang.ProxyMetaClass
Direct Known Subclasses:
MockProxyMetaClass

public class ProxyMetaClass
extends MetaClassImpl

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.

Author:
Dierk Koenig

Field Summary
protected  MetaClass adaptee
           
protected  Interceptor interceptor
           
 
Fields inherited from class groovy.lang.MetaClassImpl
registry
 
Fields inherited from class groovy.lang.MetaClass
log, NO_METHOD_FOUND, theClass, useReflection
 
Constructor Summary
ProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)
           
 
Method Summary
static ProxyMetaClass getInstance(Class theClass)
          convenience factory method for the most usual case.
 Interceptor getInterceptor()
           
 Object invokeConstructor(Object[] arguments)
          Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.
 Object invokeMethod(Object object, String methodName, Object[] arguments)
          Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
 Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
          Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
 void setInterceptor(Interceptor interceptor)
           
 void use(Closure closure)
          Use the ProxyMetaClass for the given Closure.
 void use(GroovyObject object, Closure closure)
          Use the ProxyMetaClass for the given Closure.
 
Methods inherited from class groovy.lang.MetaClassImpl
addMetaMethod, addNewInstanceMethod, addNewStaticMethod, cacheInstanceMethod, cacheStaticMethod, checkInitalised, clearInvocationCaches, getAttribute, getAttribute, getClassNode, getMetaMethods, getMethods, getProperties, getProperty, getProperty, initialize, invokeMethod, isInitialized, pickMethod, pickMethod, retrieveConstructor, retrieveMethod, retrieveMethod, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setProperties, setProperty, setProperty, toString
 
Methods inherited from class groovy.lang.MetaClass
getAttribute, invokeConstructorAt, invokeMethod, invokeMissingMethod, isGroovyObject, isUseReflection, setUseReflection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

adaptee

protected MetaClass adaptee

interceptor

protected Interceptor interceptor
Constructor Detail

ProxyMetaClass

public ProxyMetaClass(MetaClassRegistry registry,
                      Class theClass,
                      MetaClass adaptee)
               throws IntrospectionException
Parameters:
adaptee - the MetaClass to decorate with interceptability
Throws:
IntrospectionException
Method Detail

getInstance

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

Throws:
IntrospectionException

use

public void use(Closure closure)
Use the ProxyMetaClass for the given Closure. Cares for balanced register/unregister.

Parameters:
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.

Parameters:
closure - piece of code to be executed with ProxyMetaClass

getInterceptor

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

setInterceptor

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

invokeMethod

public Object invokeMethod(Object object,
                           String methodName,
                           Object[] 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.

Overrides:
invokeMethod in class MetaClassImpl

invokeStaticMethod

public Object invokeStaticMethod(Object object,
                                 String methodName,
                                 Object[] 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.

Overrides:
invokeStaticMethod in class MetaClassImpl

invokeConstructor

public Object invokeConstructor(Object[] 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.

Overrides:
invokeConstructor in class MetaClassImpl


Copyright © 2003-2008 The Codehaus. All Rights Reserved.