Package: groovy.lang

## [Java] Class ProxyMetaClass

- groovy.lang.ProxyMetaClass

- All Implemented Interfaces and Traits:
    AdaptingMetaClass

      public class ProxyMetaClass
      extends MetaClassImpl
      implements AdaptingMetaClass

  As subclass of MetaClass, ProxyMetaClass manages calls from Groovy Objects to POJOs. It enriches MetaClass with the feature of making method invocations 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 thread-safe 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

  See Also:
    MetaClassRegistry

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected MetaClass` | `adaptee` | Wrapped meta class that performs the underlying dispatch.
    `protected Interceptor` | `interceptor` | Optional interceptor applied around meta-object protocol calls.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class MetaClassImpl` | `EMPTY_ARGUMENTS, INVOKE_METHOD_METHOD, METHOD_MISSING, PROPERTY_MISSING, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, getPropertyMethod, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, registry, setPropertyMethod, theCachedClass, theClass`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)` Parameters: `adaptee` - the MetaClass to decorate with interceptability

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public MetaClass` | `getAdaptee()` * Returns the MetaClass that this adapter adapts * * Returns: The MetaClass instance
    `` | `public static ProxyMetaClass` | `getInstance(Class theClass)` convenience factory method for the most usual case.
    `` | `public Interceptor` | `getInterceptor()` Returns: the interceptor in use or null if no interceptor is used
    `` | `public Object` | `getProperty(Class aClass, Object object, String property, boolean useSuper, boolean fromInsideClass)` Interceptors the call to getProperty if a PropertyAccessInterceptor is available
    `` | `public void` | `initialize()` * Complete the initialisation process. After this method * is called no methods should be added to the metaclass. * Invocation of methods or access to fields/properties is * forbidden unless this method is called. This method * should contain any initialisation code, taking a longer * time to complete. An example is the creation of the * Reflector. It is suggested to synchronize this * method.
    `` | `public Object` | `invokeConstructor(Object[] arguments)` Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.
    `` | `public Object` | `invokeMethod(Object object, String methodName, Object[] arguments)` Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
    `` | `public Object` | `invokeMethod(Class sender, Object object, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)` Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
    `` | `public Object` | `invokeStaticMethod(Object object, String methodName, Object[] arguments)` Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
    `` | `public void` | `setAdaptee(MetaClass metaClass)` * Sets the MetaClass adapted by this MetaClass * * Parameters: `metaClass` - The MetaClass to adapt
    `` | `public void` | `setInterceptor(Interceptor interceptor)` Parameters: `interceptor` - may be null to reset any interception
    `` | `public void` | `setProperty(Class aClass, Object object, String property, Object newValue, boolean useSuper, boolean fromInsideClass)` Interceptors the call to a property setter if a PropertyAccessInterceptor is available
    `` | `public Object` | `use(Closure closure)` Use the ProxyMetaClass for the given Closure.
    `` | `public Object` | `use(GroovyObject object, Closure closure)` Use the ProxyMetaClass for the given Closure.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class MetaClassImpl` | `addMetaBeanProperty, addMetaMethod, addMetaMethodToIndex, addNewInstanceMethod, addNewStaticMethod, applyPropertyDescriptors, checkIfGroovyObjectMethod, checkInitalised, chooseConstructor, chooseMethod, chooseNamedArgCompatibleConstructor, clearInvocationCaches, createErrorMessageForAmbiguity, createTransformMetaMethod, doChooseMostSpecificParams, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMetaMethods, getMetaProperty, getMethodWithCaching, getMethodWithCaching, getMethodWithoutCaching, getMethods, getNonClosureOuter, getProperties, getProperty, getProperty, getRegistry, getStaticMetaMethod, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, handleMatches, hasCustomInvokeMethod, hasCustomStaticInvokeMethod, hasProperty, incVersion, initialize, invokeConstructor, invokeMethod, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMethod, invokeStaticMissingProperty, isGroovyObject, isInitialized, isModified, isPermissivePropertyAccess, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, pickMethod, reinitialize, respondsTo, respondsTo, retrieveConstructor, retrieveConstructor, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setInitialized, setPermissivePropertyAccess, setProperties, setProperty, setProperty, toString`

- - ### Field Detail

    - #### protected MetaClass adaptee

      Wrapped meta class that performs the underlying dispatch.

    - #### protected Interceptor interceptor

      Optional interceptor applied around meta-object protocol calls.

  - ### Constructor Detail

    - #### public ProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee)

      Parameters:
        `adaptee` - the MetaClass to decorate with interceptability

  - ### Method Detail

    - #### public MetaClass getAdaptee()

      * Returns the MetaClass that this adapter adapts * *

      Returns:
        The MetaClass instance

    - #### public static ProxyMetaClass getInstance(Class theClass)

      convenience factory method for the most usual case.

    - #### public Interceptor getInterceptor()

      Returns:
        the interceptor in use or null if no interceptor is used

    - #### public Object getProperty(Class aClass, Object object, String property, boolean useSuper, boolean fromInsideClass)

      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

    - #### public void initialize()

      * Complete the initialisation process. After this method * is called no methods should be added to the metaclass. * Invocation of methods or access to fields/properties is * forbidden unless this method is called. This method * should contain any initialisation code, taking a longer * time to complete. An example is the creation of the * Reflector. It is suggested to synchronize this * method.

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

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

    - #### public Object invokeMethod(Class sender, Object object, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)

      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.

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

    - #### public void setAdaptee(MetaClass metaClass)

      * Sets the MetaClass adapted by this MetaClass * *

      Parameters:
        `metaClass` - The MetaClass to adapt

    - #### public void setInterceptor(Interceptor interceptor)

      Parameters:
        `interceptor` - may be null to reset any interception

    - #### public void setProperty(Class aClass, Object object, String property, Object newValue, boolean useSuper, boolean fromInsideClass)

      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

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

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