Top Description Fields Constructors Methods
groovy.lang

public Class ProxyMetaClass

extends MetaClassImpl
implements AdaptingMetaClass
Class Inheritance
All Implemented Interfaces
groovy.lang.AdaptingMetaClass, groovy.lang.MetaClass, groovy.lang.MetaObjectProtocol
Imports
java.util.Objects, java.util.function.Supplier

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
groovy.lang.MetaClassRegistry

Field Summary

Modifier and TypeField and Description
protected MetaClass
protected Interceptor
Inherited from groovy.lang.MetaClassImpl:
EMPTY_ARGUMENTSgetPropertyMethodINVOKE_METHOD_METHODinvokeMethodMethodisGroovyObjectisMapmetaMethodIndexMETHOD_MISSINGPROPERTY_MISSINGregistrysetPropertyMethodSTATIC_METHOD_MISSINGSTATIC_PROPERTY_MISSINGtheCachedClasstheClass

Constructor Summary

AccessConstructor and Description
public
ProxyMetaClass(final MetaClassRegistry registry, final Class<T> theClass, final MetaClass
the MetaClass to decorate with interceptability
adaptee
)

Method Summary

Modifier and TypeMethod and Description
private Object
doCall(final Object object, final String methodName, final Object[] arguments, final Interceptor interceptor, final Supplier<Object> howToInvoke)

public MetaClass
getAdaptee()

Implements groovy.lang.AdaptingMetaClass.getAdaptee.

Returns the MetaClass that this adapter adapts
public static ProxyMetaClass
getInstance(final Class<T> theClass)

convenience factory method for the most usual case.

public Interceptor

Returns:

the interceptor in use or null if no interceptor is used
getInterceptor
()

public Object

Returns:

the value of the property
getProperty
(final Class<T>
The java.lang.Class instance that requested the property
aClass
,
final Object
the object to invoke the getter on
object
,
final String
the property name
property
,
final boolean
Whether the call is to a super class property
useSuper
,
final boolean
??
fromInsideClass
)

Overrides groovy.lang.MetaClassImpl.getProperty.

Implements groovy.lang.MetaClass.getProperty.

Interceptors the call to getProperty if a PropertyAccessInterceptor is available
public synchronized void
initialize()

Overrides groovy.lang.MetaClassImpl.initialize.

Implements groovy.lang.MetaClass.initialize.

Complete the initialisation process.
public Object
invokeConstructor(final Object[]
The arguments to the constructor
arguments
)

Overrides groovy.lang.MetaClassImpl.invokeConstructor.

Implements groovy.lang.MetaObjectProtocol.invokeConstructor.

Call invokeConstructor on adaptee with logic like in MetaClass unless we have an Interceptor.
public Object
invokeMethod(final Object
The instance which the method is invoked on
object
,
final String
The name of the method
methodName
,
final Object[]
The arguments to the method
arguments
)

Overrides groovy.lang.MetaClassImpl.invokeMethod.

Implements groovy.lang.MetaObjectProtocol.invokeMethod.

Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
public Object
invokeMethod(final Class<T>
The java.lang.Class instance that invoked the method
sender
,
final Object
The object which the method was invoked on
object
,
final String
The name of the method
methodName
,
final Object[]
The arguments to the method
arguments
,
final boolean
Whether the method is a call to a super class method
isCallToSuper
,
final boolean
Whether the call was invoked from the inside or the outside of the class
fromInsideClass
)

Overrides groovy.lang.MetaClassImpl.invokeMethod.

Implements groovy.lang.MetaClass.invokeMethod.

Call invokeMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
public Object
invokeStaticMethod(final Object
An instance of the class returned by the getTheClass() method or the class itself
object
,
final String
The name of the method
methodName
,
final Object[]
The arguments to the method
arguments
)

Overrides groovy.lang.MetaClassImpl.invokeStaticMethod.

Implements groovy.lang.MetaObjectProtocol.invokeStaticMethod.

Call invokeStaticMethod on adaptee with logic like in MetaClass unless we have an Interceptor.
public void
setAdaptee(final MetaClass
The MetaClass to adapt
metaClass
)

Implements groovy.lang.AdaptingMetaClass.setAdaptee.

Sets the MetaClass adapted by this MetaClass
public void
setInterceptor(final Interceptor
may be null to reset any interception
interceptor
)

public void
setProperty(final Class<T>
The java.lang.Class instance that is mutating the property
aClass
,
final Object
The object to invoke the setter on
object
,
final String
The property name to set
property
,
final Object
The new value of the property
newValue
,
final boolean
Whether the call is to a super class property
useSuper
,
final boolean
Whether the call was invoked from the inside or the outside of the class
fromInsideClass
)

Overrides groovy.lang.MetaClassImpl.setProperty.

Implements groovy.lang.MetaClass.setProperty.

Interceptors the call to a property setter if a PropertyAccessInterceptor is available
public Object
use(final Closure<V>
piece of code to be executed with registered ProxyMetaClass
closure
)

Use the ProxyMetaClass for the given Closure.

public Object
use(final GroovyObject object, final Closure<V>
piece of code to be executed with ProxyMetaClass
closure
)

Use the ProxyMetaClass for the given Closure.

Inherited from groovy.lang.MetaClassImpl:
addMetaBeanPropertyaddMetaMethodaddMetaMethodToIndexaddNewInstanceMethodaddNewStaticMethodapplyPropertyDescriptorscheckIfGroovyObjectMethodcheckInitalisedchooseMethodclearInvocationCachescreateConstructorSitecreateErrorMessageForAmbiguitycreatePogoCallCurrentSitecreatePogoCallSitecreatePojoCallSitecreateStaticSitecreateTransformMetaMethoddoChooseMostSpecificParamsdropMethodCachedropStaticMethodCachefindMethodInClassHierarchyfindMixinMethodfindOwnMethodfindPropertyInClassHierarchygetAdditionalMetaMethodsgetAttributegetAttributegetAttributegetClassInfogetClassNodegetEffectiveGetMetaPropertygetMetaMethodgetMetaMethodsgetMetaPropertygetMethodsgetMethodWithCachinggetMethodWithoutCachinggetPropertiesgetPropertygetRegistrygetStaticMetaMethodgetSubclassMetaMethodsgetSuperClassesgetTheCachedClassgetTheClassgetVersionhandleMatcheshasCustomInvokeMethodhasCustomStaticInvokeMethodhasPropertyincVersioninvokeMethodinvokeMissingMethodinvokeMissingPropertyinvokeStaticMissingPropertyisGroovyObjectisInitializedisModifiedisPermissivePropertyAccessonGetPropertyFoundInHierarchyonInvokeMethodFoundInHierarchyonMixinMethodFoundonSetPropertyFoundInHierarchyonSuperMethodFoundInHierarchyonSuperPropertyFoundInHierarchypickMethodreinitializerespondsTorespondsToretrieveConstructorretrieveConstructorretrieveStaticMethodselectConstructorAndTransformArgumentssetAttributesetAttributesetInitializedsetPermissivePropertyAccesssetPropertiessetPropertytoString

Field Detail

adapteeback to summary
protected MetaClass adaptee
interceptorback to summary
protected Interceptor interceptor

Constructor Detail

ProxyMetaClassback to summary
public ProxyMetaClass(final MetaClassRegistry registry, final Class<T> theClass, final MetaClass adaptee)
Parameters
adaptee:MetaClass

the MetaClass to decorate with interceptability

Method Detail

doCallback to summary
private Object doCall(final Object object, final String methodName, final Object[] arguments, final Interceptor interceptor, final Supplier<Object> howToInvoke)
getAdapteeback to summary
public MetaClass getAdaptee()

Implements groovy.lang.AdaptingMetaClass.getAdaptee.

Doc from groovy.lang.AdaptingMetaClass.getAdaptee.

Returns the MetaClass that this adapter adapts

Returns:MetaClass

The MetaClass instance

Annotations
@Override
getInstanceback to summary
public static ProxyMetaClass getInstance(final Class<T> theClass)

convenience factory method for the most usual case.

getInterceptorback to summary
public Interceptor getInterceptor()
Returns:Interceptor

the interceptor in use or null if no interceptor is used

getPropertyback to summary
public Object getProperty(final Class<T> aClass, final Object object, final String property, final boolean useSuper, final boolean fromInsideClass)

Overrides groovy.lang.MetaClassImpl.getProperty.

Implements groovy.lang.MetaClass.getProperty.

Interceptors the call to getProperty if a PropertyAccessInterceptor is available

Parameters
aClass:Class<T>

Doc from groovy.lang.MetaClass.getProperty.

The java.lang.Class instance that requested the property

object:Object

the object to invoke the getter on

property:String

the property name

useSuper:boolean

Doc from groovy.lang.MetaClass.getProperty.

Whether the call is to a super class property

fromInsideClass:boolean

Doc from groovy.lang.MetaClass.getProperty.

??

Returns:Object

the value of the property

initializeback to summary
public synchronized void initialize()

Overrides groovy.lang.MetaClassImpl.initialize.

Implements groovy.lang.MetaClass.initialize.

Doc from groovy.lang.MetaClass.initialize.

Complete the initialisation process. After this method is called no methods should be added to the meta class. 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.

Annotations
@Override
invokeConstructorback to summary
public Object invokeConstructor(final Object[] arguments)

Overrides groovy.lang.MetaClassImpl.invokeConstructor.

Implements groovy.lang.MetaObjectProtocol.invokeConstructor.

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.

Parameters
arguments:Object[]

Doc from groovy.lang.MetaObjectProtocol.invokeConstructor.

The arguments to the constructor

Returns:Object

Doc from groovy.lang.MetaObjectProtocol.invokeConstructor.

An instance of the java.lang.Class that this MetaObjectProtocol object applies to

Annotations
@Override
invokeMethodback to summary
public Object invokeMethod(final Object object, final String methodName, final Object[] arguments)

Overrides groovy.lang.MetaClassImpl.invokeMethod.

Implements groovy.lang.MetaObjectProtocol.invokeMethod.

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.

Parameters
object:Object

Doc from groovy.lang.MetaObjectProtocol.invokeMethod.

The instance which the method is invoked on

methodName:String

Doc from groovy.lang.MetaObjectProtocol.invokeMethod.

The name of the method

arguments:Object[]

Doc from groovy.lang.MetaObjectProtocol.invokeMethod.

The arguments to the method

Returns:Object

Doc from groovy.lang.MetaObjectProtocol.invokeMethod.

The return value of the method which is null if the return type is void

Annotations
@Override
invokeMethodback to summary
public Object invokeMethod(final Class<T> sender, final Object object, final String methodName, final Object[] arguments, final boolean isCallToSuper, final boolean fromInsideClass)

Overrides groovy.lang.MetaClassImpl.invokeMethod.

Implements groovy.lang.MetaClass.invokeMethod.

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.

Parameters
sender:Class<T>

Doc from groovy.lang.MetaClass.invokeMethod.

The java.lang.Class instance that invoked the method

object:Object

Doc from groovy.lang.MetaClass.invokeMethod.

The object which the method was invoked on

methodName:String

Doc from groovy.lang.MetaClass.invokeMethod.

The name of the method

arguments:Object[]

Doc from groovy.lang.MetaClass.invokeMethod.

The arguments to the method

isCallToSuper:boolean

Doc from groovy.lang.MetaClass.invokeMethod.

Whether the method is a call to a super class method

fromInsideClass:boolean

Doc from groovy.lang.MetaClass.invokeMethod.

Whether the call was invoked from the inside or the outside of the class

Returns:Object

Doc from groovy.lang.MetaClass.invokeMethod.

The return value of the method

Annotations
@Override
invokeStaticMethodback to summary
public Object invokeStaticMethod(final Object object, final String methodName, final Object[] arguments)

Overrides groovy.lang.MetaClassImpl.invokeStaticMethod.

Implements groovy.lang.MetaObjectProtocol.invokeStaticMethod.

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.

Parameters
object:Object

Doc from groovy.lang.MetaObjectProtocol.invokeStaticMethod.

An instance of the class returned by the getTheClass() method or the class itself

methodName:String

Doc from groovy.lang.MetaObjectProtocol.invokeStaticMethod.

The name of the method

arguments:Object[]

Doc from groovy.lang.MetaObjectProtocol.invokeStaticMethod.

The arguments to the method

Returns:Object

Doc from groovy.lang.MetaObjectProtocol.invokeStaticMethod.

The return value of the method which is null if the return type is void

Annotations
@Override
setAdapteeback to summary
public void setAdaptee(final MetaClass metaClass)

Implements groovy.lang.AdaptingMetaClass.setAdaptee.

Doc from groovy.lang.AdaptingMetaClass.setAdaptee.

Sets the MetaClass adapted by this MetaClass

Parameters
metaClass:MetaClass

The MetaClass to adapt

Annotations
@Override
setInterceptorback to summary
public void setInterceptor(final Interceptor interceptor)
Parameters
interceptor:Interceptor

may be null to reset any interception

setPropertyback to summary
public void setProperty(final Class<T> aClass, final Object object, final String property, final Object newValue, final boolean useSuper, final boolean fromInsideClass)

Overrides groovy.lang.MetaClassImpl.setProperty.

Implements groovy.lang.MetaClass.setProperty.

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

Parameters
aClass:Class<T>

Doc from groovy.lang.MetaClass.setProperty.

The java.lang.Class instance that is mutating the property

object:Object

The object to invoke the setter on

property:String

The property name to set

newValue:Object

The new value of the property

useSuper:boolean

Doc from groovy.lang.MetaClass.setProperty.

Whether the call is to a super class property

fromInsideClass:boolean

Doc from groovy.lang.MetaClass.setProperty.

Whether the call was invoked from the inside or the outside of the class

useback to summary
public Object use(final Closure<V> closure)

Use the ProxyMetaClass for the given Closure. Cares for balanced register/unregister.

Parameters
closure:Closure<V>

piece of code to be executed with registered ProxyMetaClass

useback to summary
public Object use(final GroovyObject object, final Closure<V> closure)

Use the ProxyMetaClass for the given Closure. Cares for balanced setting/unsetting ProxyMetaClass.

Parameters
closure:Closure<V>

piece of code to be executed with ProxyMetaClass