Top Description Methods
groovy.lang

public Interface MetaObjectProtocol

Known Direct Subinterfaces
groovy.lang.MetaClass
Imports
java.util.List

An interface that defines the API usable by clients of Groovy's Meta Object Protocol (MOP). These methods are implemented by the reference implementation of the groovy.lang.MetaClass interface.

See Also
MetaClassImpl

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The attribute value
getAttribute
(Object
An instance of the class returned by the getTheClass() method
object
,
String
The name of the attribute to retrieve the value for
attribute
)

Retrieves an attribute of an instance of the class returned by the getTheClass() method.

public MetaMethod

Returns:

A MetaMethod or null if it doesn't exist
getMetaMethod
(String
The name of the MetaMethod
name
,
Object[]
Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument types
args
)

Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod

public MetaProperty

Returns:

A MetaProperty or null
getMetaProperty
(String
The name of the MetaProperty
name
)

Returns a MetaProperty for the given name or null if it doesn't exist

public List<MetaMethod>

Returns:

A list of MetaMethod instances
getMethods
()

Obtain a list of all the meta methods available on this meta class

public List<MetaProperty>

Returns:

A list of MetaProperty instances
getProperties
()

Obtain a list of all meta properties available on this meta class

public Object

Returns:

The properties value
getProperty
(Object
An instance of the class returned by the getTheClass() method
object
,
String
The name of the property to retrieve the value for
property
)

Retrieves a property of an instance of the class returned by the getTheClass() method.

public MetaMethod

Returns:

A MetaMethod or null if it doesn't exist
getStaticMetaMethod
(String
The name of the MetaMethod
name
,
Object[]
The argument types
args
)

Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod

public Class<T>

Returns:

The java.lang.Class instance
getTheClass
()

Retrieves that Java Class that the attached Meta behaviours apply to

public MetaProperty

Returns:

The MetaProperty or null if it doesn't exist
hasProperty
(Object
The object to inspect
obj
,
String
The name of the property
name
)

Returns true of the implementing MetaClass has a property of the given name

Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing

public Object

Returns:

An instance of the java.lang.Class that this MetaObjectProtocol object applies to
invokeConstructor
(Object[]
The arguments to the constructor
arguments
)

Invokes a constructor for the given arguments.

public Object

Returns:

The return value of the method which is null if the return type is void
invokeMethod
(Object
The instance which the method is invoked on
object
,
String
The name of the method
methodName
,
Object[]
The arguments to the method
arguments
)

Invokes a method on the given Object with the given name and arguments.

public Object

Returns:

The return value of the method which is null if the return type is void
invokeMethod
(Object
The Object to invoke the method on
object
,
String
The name of the method
methodName
,
Object
The argument to the method
arguments
)

Invokes a method on the given object, with the given name and single argument.

public Object

Returns:

The return value of the method which is null if the return type is void
invokeStaticMethod
(Object
An instance of the class returned by the getTheClass() method or the class itself
object
,
String
The name of the method
methodName
,
Object[]
The arguments to the method
arguments
)

Invokes a static method on the given Object with the given name and arguments.

public List<MetaMethod>

Returns:

A List of MetaMethods matching the argument types which will be empty if no matching methods exist
respondsTo
(Object
The object to inspect
obj
,
String
The name of the method of interest
name
,
Object[]
The argument types to match against
argTypes
)

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

public List<MetaMethod>

Returns:

A List of MetaMethods which will be empty if no methods with the given name exist
respondsTo
(Object
The object to inspect
obj
,
String
The name of the method of interest
name
)

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.

public void
setAttribute(Object
An instance of the class returned by the getTheClass() method
object
,
String
The name of the attribute to set
attribute
,
Object
The new value of the attribute
newValue
)

Sets an attribute of an instance of the class returned by the getTheClass() method.

public void
setProperty(Object
An instance of the class returned by the getTheClass() method
object
,
String
The name of the property to set
property
,
Object
The new value of the property
newValue
)

Sets a property of an instance of the class returned by the getTheClass() method.

Method Detail

getAttributeback to summary
public Object getAttribute(Object object, String attribute)

Retrieves an attribute of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in attempt to read a field of the instance.

Parameters
object:Object

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

attribute:String

The name of the attribute to retrieve the value for

Returns:Object

The attribute value

See Also
MetaClassImpl
getMetaMethodback to summary
public MetaMethod getMetaMethod(String name, Object[] args)

Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod

Parameters
name:String

The name of the MetaMethod

args:Object[]

Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument types

Returns:MetaMethod

A MetaMethod or null if it doesn't exist

getMetaPropertyback to summary
public MetaProperty getMetaProperty(String name)

Returns a MetaProperty for the given name or null if it doesn't exist

Parameters
name:String

The name of the MetaProperty

Returns:MetaProperty

A MetaProperty or null

getMethodsback to summary
public List<MetaMethod> getMethods()

Obtain a list of all the meta methods available on this meta class

Returns:List<MetaMethod>

A list of MetaMethod instances

See Also
groovy.lang.MetaMethod
getPropertiesback to summary
public List<MetaProperty> getProperties()

Obtain a list of all meta properties available on this meta class

Returns:List<MetaProperty>

A list of MetaProperty instances

See Also
groovy.lang.MetaProperty
getPropertyback to summary
public Object getProperty(Object object, String property)

Retrieves a property of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean getter, or if no such getter exists a public field of the instance.

Parameters
object:Object

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

property:String

The name of the property to retrieve the value for

Returns:Object

The properties value

See Also
MetaClassImpl
getStaticMetaMethodback to summary
public MetaMethod getStaticMetaMethod(String name, Object[] args)

Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod

Parameters
name:String

The name of the MetaMethod

args:Object[]

The argument types

Returns:MetaMethod

A MetaMethod or null if it doesn't exist

getTheClassback to summary
public Class<T> getTheClass()

Retrieves that Java Class that the attached Meta behaviours apply to

Returns:Class<T>

The java.lang.Class instance

hasPropertyback to summary
public MetaProperty hasProperty(Object obj, String name)

Returns true of the implementing MetaClass has a property of the given name

Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing

Parameters
obj:Object

The object to inspect

name:String

The name of the property

Returns:MetaProperty

The MetaProperty or null if it doesn't exist

invokeConstructorback to summary
public Object invokeConstructor(Object[] arguments)

Invokes a constructor for the given arguments. The MetaClass will attempt to pick the best argument which matches the types of the objects passed within the arguments array

Parameters
arguments:Object[]

The arguments to the constructor

Returns:Object

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

invokeMethodback to summary
public Object invokeMethod(Object object, String methodName, Object[] arguments)

Invokes a method on the given Object with the given name and arguments. The MetaClass will attempt to pick the best method for the given name and arguments. If a method cannot be invoked a MissingMethodException will be thrown.

Parameters
object:Object

The instance which the method is invoked on

methodName:String

The name of the method

arguments:Object[]

The arguments to the method

Returns:Object

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

See Also
groovy.lang.MissingMethodException
invokeMethodback to summary
public Object invokeMethod(Object object, String methodName, Object arguments)

Invokes a method on the given object, with the given name and single argument.

Parameters
object:Object

The Object to invoke the method on

methodName:String

The name of the method

arguments:Object

The argument to the method

Returns:Object

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

See Also
invokeMethod(Object, String, Object[])
invokeStaticMethodback to summary
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments)

Invokes a static method on the given Object with the given name and arguments.

The Object can either be an instance of the class that this MetaObjectProtocol instance applies to or the java.lang.Class instance itself. If a method cannot be invoked a MissingMethodException is will be thrown

Parameters
object:Object

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

methodName:String

The name of the method

arguments:Object[]

The arguments to the method

Returns:Object

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

See Also
groovy.lang.MissingMethodException
respondsToback to summary
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes)

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

This method is "safe" in that it will always return a value and never throw an exception

Parameters
obj:Object

The object to inspect

name:String

The name of the method of interest

argTypes:Object[]

The argument types to match against

Returns:List<MetaMethod>

A List of MetaMethods matching the argument types which will be empty if no matching methods exist

respondsToback to summary
public List<MetaMethod> respondsTo(Object obj, String name)

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments. In other words this method will return for foo() and foo(String).

Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

This method is "safe" in that it will always return a value and never throw an exception

Parameters
obj:Object

The object to inspect

name:String

The name of the method of interest

Returns:List<MetaMethod>

A List of MetaMethods which will be empty if no methods with the given name exist

setAttributeback to summary
public void setAttribute(Object object, String attribute, Object newValue)

Sets an attribute of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to set a field of the instance.

Parameters
object:Object

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

attribute:String

The name of the attribute to set

newValue:Object

The new value of the attribute

See Also
MetaClassImpl
setPropertyback to summary
public void setProperty(Object object, String property, Object newValue)

Sets a property of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean setter, or if no such setter exists to set a public field of the instance.

Parameters
object:Object

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

property:String

The name of the property to set

newValue:Object

The new value of the property

See Also
MetaClassImpl