Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.grails.commons.metaclass
Class ProxyMetaClass

    java.lang.Object
      groovy.lang.MetaClassImpl
          org.codehaus.groovy.grails.commons.metaclass.ProxyMetaClass

All Implemented Interfaces:
  groovy.lang.AdaptingMetaClass, groovy.lang.MetaClass, groovy.lang.MetaObjectProtocol, groovy.lang.MutableMetaClass

    public class ProxyMetaClass

extends groovy.lang.MetaClassImpl
implements groovy.lang.AdaptingMetaClass

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.

Author:
  Dierk Koenig, Graeme Rocher

Nested Class Summary

Nested classes/interfaces inherited from class groovy.lang.MetaClassImpl
`groovy.lang.MetaClassImpl.Index`

Field Summary
`protected groovy.lang.MetaClass` | `adaptee`
`protected Interceptor` | `interceptor`

Fields inherited from class groovy.lang.MetaClassImpl
`getPropertyMethod, INVOKE_METHOD_METHOD, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, METHOD_MISSING, PROPERTY_MISSING, registry, setPropertyMethod, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, theCachedClass, theClass`

Constructor Summary
`ProxyMetaClass(groovy.lang.MetaClassRegistry registry, Class<?> theClass, groovy.lang.MetaClass adaptee)`

Method Summary
`groovy.lang.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.
`Object` | `invokeConstructor(Object[] arguments)` Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.
`Object` | `invokeMethod(Class aClass, Object object, String methodName, Object[] arguments, boolean b, boolean b1)` 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` | `setAdaptee(groovy.lang.MetaClass adaptee)`
`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(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
`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, getMethods, getMethodWithCaching, getMethodWithoutCaching, getProperties, getProperty, getStaticMetaMethod, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, hasProperty, incVersion, initialize, invokeConstructorAt, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMissingProperty, isGroovyObject, isInitialized, isModified, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, pickMethod, respondsTo, respondsTo, retrieveConstructor, retrieveMethod, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setProperties, setProperty, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface groovy.lang.MetaClass
`getAttribute, getClassNode, getMetaMethods, getMethods, getProperties, initialize, invokeMissingMethod, invokeMissingProperty, pickMethod, selectConstructorAndTransformArguments, setAttribute`

Methods inherited from interface groovy.lang.MetaObjectProtocol
`getAttribute, getMetaMethod, getMetaProperty, getProperty, getStaticMetaMethod, getTheClass, hasProperty, invokeMethod, invokeMethod, respondsTo, respondsTo, setAttribute, setProperty`

Field Detail

### adaptee

    protected groovy.lang.MetaClass adaptee

### interceptor

    protected Interceptor interceptor

Constructor Detail

### ProxyMetaClass

    public ProxyMetaClass(groovy.lang.MetaClassRegistry registry,
                          Class<?> theClass,
                          groovy.lang.MetaClass adaptee)

Parameters:
  `adaptee` - the MetaClass to decorate with interceptability
  `registry` - The MetaClassRegistry instance
  `theClass` - The class to apply this ProxyMetaClass to
Throws:
  `IntrospectionException` - Thrown when the class cannot be introspected

Method Detail

### getAdaptee

    public groovy.lang.MetaClass getAdaptee()

  Specified by:
    `getAdaptee` in interface `groovy.lang.AdaptingMetaClass`

### setAdaptee

    public void setAdaptee(groovy.lang.MetaClass adaptee)

  Specified by:
    `setAdaptee` in interface `groovy.lang.AdaptingMetaClass`
  Parameters:
    `adaptee` - the adaptee to set

### getInstance

    public static ProxyMetaClass getInstance(Class<?> theClass)

  convenience factory method for the most usual case.

  Parameters:
    `theClass` - The class to create a ProxyMetaClass for
  Returns:
    A new ProxyMetaClass instance

### 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

### 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(Class aClass,
                               Object object,
                               String methodName,
                               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.

  Specified by:
    `invokeMethod` in interface `groovy.lang.MetaClass`
  Overrides:
    `invokeMethod` in class `groovy.lang.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.

  Specified by:
    `invokeStaticMethod` in interface `groovy.lang.MetaObjectProtocol`
  Overrides:
    `invokeStaticMethod` in class `groovy.lang.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.

  Specified by:
    `invokeConstructor` in interface `groovy.lang.MetaObjectProtocol`
  Overrides:
    `invokeConstructor` in class `groovy.lang.MetaClassImpl`

### getProperty

    public Object getProperty(Class aClass,
                              Object object,
                              String property,
                              boolean b,
                              boolean b1)

  Interceptors the call to getProperty if a PropertyAccessInterceptor is available.

  Specified by:
    `getProperty` in interface `groovy.lang.MetaClass`
  Overrides:
    `getProperty` in class `groovy.lang.MetaClassImpl`
  Parameters:
    `object` - the object to invoke the getter on
    `property` - the property name
  Returns:
    the value of the property

### 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.

  Specified by:
    `setProperty` in interface `groovy.lang.MetaClass`
  Overrides:
    `setProperty` in class `groovy.lang.MetaClassImpl`
  Parameters:
    `object` - The object to invoke the setter on
    `property` - The property name to set
    `newValue` - The new value of the property

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD