Groovy Documentation

org.codehaus.groovy.grails.commons.metaclass
[Java] Class ProxyMetaClass

java.lang.Object
  groovy.lang.MetaClassImpl
      org.codehaus.groovy.grails.commons.metaclass.ProxyMetaClass
All Implemented Interfaces:
groovy.lang.AdaptingMetaClass

@SuppressWarnings({"unchecked","rawtypes"})
public class ProxyMetaClass
extends groovy.lang.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. This is based on original code by Dierk Koenig, but uses a callback object for thread safety and supports not only method interception, but property and constructor interception too.

Authors:
Dierk Koenig
Graeme Rocher


Field Summary
protected groovy.lang.MetaClass adaptee

protected Interceptor interceptor

 
Constructor Summary
ProxyMetaClass(groovy.lang.MetaClassRegistry registry, java.lang.Class theClass, groovy.lang.MetaClass adaptee)

@param adaptee the MetaClass to decorate with interceptability

 
Method Summary
groovy.lang.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.

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.Class aClass, java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments, boolean b, boolean b1)

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(groovy.lang.MetaClass adaptee)

@param adaptee the adaptee to set

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.

void use(groovy.lang.Closure closure)

Use the ProxyMetaClass for the given Closure.

void use(groovy.lang.GroovyObject object, groovy.lang.Closure closure)

Use the ProxyMetaClass for the given Closure.

 
Methods inherited from class groovy.lang.MetaClassImpl
groovy.lang.MetaClassImpl#setProperty(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#setProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.MetaClassImpl#getProperty(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#getProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.MetaClassImpl#toString(), groovy.lang.MetaClassImpl#getMethods(), groovy.lang.MetaClassImpl#getProperties(), groovy.lang.MetaClassImpl#setProperties(java.lang.Object, java.util.Map), groovy.lang.MetaClassImpl#initialize(), groovy.lang.MetaClassImpl#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.MetaClassImpl#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.MetaClassImpl#getAttribute(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#getVersion(), groovy.lang.MetaClassImpl#getTheClass(), groovy.lang.MetaClassImpl#hasProperty(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Class, java.lang.Object, java.lang.String, [Ljava.lang.Object;, boolean, boolean), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#pickMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.MetaClassImpl#invokeMissingMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeMissingProperty(java.lang.Object, java.lang.String, java.lang.Object, boolean), groovy.lang.MetaClassImpl#setAttribute(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#setAttribute(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.MetaClassImpl#getClassNode(), groovy.lang.MetaClassImpl#getMetaMethods(), groovy.lang.MetaClassImpl#selectConstructorAndTransformArguments(int, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#respondsTo(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#respondsTo(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaProperty(java.lang.String), groovy.lang.MetaClassImpl#getStaticMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeConstructor([Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeStaticMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getClassInfo(), groovy.lang.MetaClassImpl#incVersion(), groovy.lang.MetaClassImpl#createPojoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Object, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getTheCachedClass(), groovy.lang.MetaClassImpl#getMethodWithoutCaching(java.lang.Class, java.lang.String, [Ljava.lang.Class;, boolean), groovy.lang.MetaClassImpl#addMetaBeanProperty(groovy.lang.MetaBeanProperty), groovy.lang.MetaClassImpl#isModified(), groovy.lang.MetaClassImpl#createStaticSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createPogoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createPogoCallCurrentSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Class, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createConstructorSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#isGroovyObject(), groovy.lang.MetaClassImpl#addNewInstanceMethod(java.lang.reflect.Method), groovy.lang.MetaClassImpl#addNewStaticMethod(java.lang.reflect.Method), groovy.lang.MetaClassImpl#getMethodWithCaching(java.lang.Class, java.lang.String, [Ljava.lang.Object;, boolean), groovy.lang.MetaClassImpl#retrieveConstructor([Ljava.lang.Class;), groovy.lang.MetaClassImpl#retrieveStaticMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getEffectiveGetMetaProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.MetaClassImpl#addMetaMethod(groovy.lang.MetaMethod), groovy.lang.MetaClassImpl#getAdditionalMetaMethods(), groovy.lang.MetaClassImpl#getRegistry(), groovy.lang.MetaClassImpl#wait(), groovy.lang.MetaClassImpl#wait(long), groovy.lang.MetaClassImpl#wait(long, int), groovy.lang.MetaClassImpl#equals(java.lang.Object), groovy.lang.MetaClassImpl#hashCode(), groovy.lang.MetaClassImpl#getClass(), groovy.lang.MetaClassImpl#notify(), groovy.lang.MetaClassImpl#notifyAll()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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 groovy.lang.MetaClass adaptee


interceptor

protected Interceptor interceptor


 
Constructor Detail

ProxyMetaClass

public ProxyMetaClass(groovy.lang.MetaClassRegistry registry, java.lang.Class theClass, groovy.lang.MetaClass adaptee)
throws:
java.beans.IntrospectionException Thrown when the class cannot be introspected
Parameters:
adaptee - the MetaClass to decorate with interceptability
registry - The MetaClassRegistry instance
theClass - The class to apply this ProxyMetaClass to


 
Method Detail

getAdaptee

public groovy.lang.MetaClass getAdaptee()


getInstance

public static ProxyMetaClass getInstance(java.lang.Class theClass)
convenience factory method for the most usual case.
Parameters:
theClass - The class to create a ProxyMetaClass for
Returns:
A new ProxyMetaClass instance


getInterceptor

public Interceptor getInterceptor()
Returns:
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) {
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


invokeConstructor

@Override
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

@Override
public java.lang.Object invokeMethod(java.lang.Class aClass, java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments, boolean b, boolean b1)
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

@Override
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(groovy.lang.MetaClass adaptee)
Parameters:
adaptee - the adaptee to set


setInterceptor

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


setProperty

public void setProperty(Class aClass, Object object, String property, Object newValue, boolean b, boolean b1) {
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 void use(groovy.lang.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(groovy.lang.GroovyObject object, groovy.lang.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
object - The GroovyObject to use this ProxyMetaClass with


 

Groovy Documentation