Groovy Documentation

groovy.lang
[Java] Class ProxyMetaClass

java.lang.Object
  groovy.lang.MetaClassImpl
      groovy.lang.ProxyMetaClass
All Implemented Interfaces:
AdaptingMetaClass

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.

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

Authors:
Dierk Koenig
Graeme Rocher
See Also:
MetaClassRegistry


Field Summary
protected MetaClass adaptee

protected Interceptor interceptor

 
Fields inherited from class MetaClassImpl
INVOKE_METHOD_METHOD, METHOD_MISSING, PROPERTY_MISSING, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, getPropertyMethod, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, registry, setPropertyMethod, theCachedClass, theClass
 
Constructor Summary
ProxyMetaClass(MetaClassRegistry registry, java.lang.Class theClass, MetaClass adaptee)

@param adaptee the MetaClass to decorate with interceptability

 
Method Summary
MetaClass getAdaptee()

static ProxyMetaClass getInstance(java.lang.Class theClass)

convenience factory method for the most usual case.

Interceptor getInterceptor()

@return the interceptor in use or null if no interceptor is used

java.lang.Object getProperty(java.lang.Class aClass, java.lang.Object object, java.lang.String property, boolean b, boolean b1)

Interceptors the call to getProperty if a PropertyAccessInterceptor is available

void initialize()

java.lang.Object invokeConstructor(java.lang.Object[] arguments)

Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.

java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)

Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.

java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)

Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor.

void setAdaptee(MetaClass metaClass)

void setInterceptor(Interceptor interceptor)

@param interceptor may be null to reset any interception

void setProperty(java.lang.Class aClass, java.lang.Object object, java.lang.String property, java.lang.Object newValue, boolean b, boolean b1)

Interceptors the call to a property setter if a PropertyAccessInterceptor is available

java.lang.Object use(Closure closure)

Use the ProxyMetaClass for the given Closure.

java.lang.Object use(GroovyObject object, Closure closure)

Use the ProxyMetaClass for the given Closure.

 
Methods inherited from class MetaClassImpl
addMetaBeanProperty, addMetaMethod, addMetaMethodToIndex, addNewInstanceMethod, addNewStaticMethod, applyPropertyDescriptors, checkIfGroovyObjectMethod, checkInitalised, chooseMethod, clearInvocationCaches, createConstructorSite, createPogoCallCurrentSite, createPogoCallSite, createPojoCallSite, createStaticSite, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMetaMethods, getMetaProperty, getMethodWithCaching, getMethodWithoutCaching, getMethods, getProperties, getProperty, getProperty, getRegistry, getStaticMetaMethod, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, hasProperty, incVersion, initialize, invokeConstructor, invokeMethod, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMethod, invokeStaticMissingProperty, isGroovyObject, isInitialized, isModified, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, pickMethod, respondsTo, respondsTo, retrieveConstructor, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setProperties, setProperty, setProperty, toString
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

adaptee

protected MetaClass adaptee


interceptor

protected Interceptor interceptor


 
Constructor Detail

ProxyMetaClass

public ProxyMetaClass(MetaClassRegistry registry, java.lang.Class theClass, MetaClass adaptee)
Parameters:
adaptee - the MetaClass to decorate with interceptability


 
Method Detail

getAdaptee

public MetaClass getAdaptee()


getInstance

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


getInterceptor

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


getProperty

public java.lang.Object getProperty(java.lang.Class aClass, java.lang.Object object, java.lang.String property, boolean b, boolean b1)
Interceptors the call to getProperty if a PropertyAccessInterceptor is available
Parameters:
object - the object to invoke the getter on
property - the property name
Returns:
the value of the property


initialize

public void initialize()


invokeConstructor

public java.lang.Object invokeConstructor(java.lang.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.


invokeMethod

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


invokeStaticMethod

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


setAdaptee

public void setAdaptee(MetaClass metaClass)


setInterceptor

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


setProperty

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


use

public java.lang.Object 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 java.lang.Object 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


 

Groovy Documentation