Interface MetaObjectProtocol
- All Known Subinterfaces:
- AdaptingMetaClass,- MetaClass,- MutableMetaClass
- All Known Implementing Classes:
- ClosureMetaClass,- DelegatingMetaClass,- ExpandoMetaClass,- HandleMetaClass,- MetaClassImpl,- MixedInMetaClass,- MockProxyMetaClass,- OwnedMetaClass,- ProxyMetaClass
public interface MetaObjectProtocol
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 MetaClass interface.
- See Also:
- MetaClassImpl
- 
Method SummaryModifier and Type Method Description java.lang.ObjectgetAttribute(java.lang.Object object, java.lang.String attribute)Retrieves an attribute of an instance of the class returned by the getTheClass() method.MetaMethodgetMetaMethod(java.lang.String name, java.lang.Object[] args)Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethodMetaPropertygetMetaProperty(java.lang.String name)Returns a MetaProperty for the given name or null if it doesn't existjava.util.List<MetaMethod>getMethods()Obtain a list of all the meta methods available on this meta classjava.util.List<MetaProperty>getProperties()Obtain a list of all meta properties available on this meta classjava.lang.ObjectgetProperty(java.lang.Object object, java.lang.String property)Retrieves a property of an instance of the class returned by the getTheClass() method.MetaMethodgetStaticMetaMethod(java.lang.String name, java.lang.Object[] args)Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethodjava.lang.ClassgetTheClass()Retrieves that Java Class that the attached Meta behaviours apply toMetaPropertyhasProperty(java.lang.Object obj, java.lang.String name)Returns true of the implementing MetaClass has a property of the given namejava.lang.ObjectinvokeConstructor(java.lang.Object[] arguments)Invokes a constructor for the given arguments.java.lang.ObjectinvokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Invokes a method on the given object, with the given name and single argument.java.lang.ObjectinvokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)Invokes a method on the given Object with the given name and arguments.java.lang.ObjectinvokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)Invokes a static method on the given Object with the given name and arguments.java.util.List<MetaMethod>respondsTo(java.lang.Object obj, java.lang.String name)Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.java.util.List<MetaMethod>respondsTo(java.lang.Object obj, java.lang.String name, java.lang.Object[] argTypes)Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.voidsetAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)Sets an attribute of an instance of the class returned by the getTheClass() method.voidsetProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)Sets a property of an instance of the class returned by the getTheClass() method.
- 
Method Details- 
getPropertiesjava.util.List<MetaProperty> getProperties()Obtain a list of all meta properties available on this meta class- Returns:
- A list of MetaProperty instances
- See Also:
- MetaProperty
 
- 
getMethodsjava.util.List<MetaMethod> getMethods()Obtain a list of all the meta methods available on this meta class- Returns:
- A list of MetaMethod instances
- See Also:
- MetaMethod
 
- 
respondsTojava.util.List<MetaMethod> respondsTo(java.lang.Object obj, java.lang.String name, java.lang.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- The object to inspect
- name- The name of the method of interest
- argTypes- The argument types to match against
- Returns:
- A List of MetaMethods matching the argument types which will be empty if no matching methods exist
 
- 
respondsToReturns 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- The object to inspect
- name- The name of the method of interest
- Returns:
- A List of MetaMethods which will be empty if no methods with the given name exist
 
- 
hasPropertyReturns 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- The object to inspect
- name- The name of the property
- Returns:
- The MetaProperty or null if it doesn't exist
 
- 
getMetaPropertyReturns a MetaProperty for the given name or null if it doesn't exist- Parameters:
- name- The name of the MetaProperty
- Returns:
- A MetaProperty or null
 
- 
getStaticMetaMethodRetrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod- Parameters:
- name- The name of the MetaMethod
- args- The argument types
- Returns:
- A MetaMethod or null if it doesn't exist
 
- 
getMetaMethodRetrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod- Parameters:
- name- The name of the MetaMethod
- args- Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument types
- Returns:
- A MetaMethod or null if it doesn't exist
 
- 
getTheClassjava.lang.Class getTheClass()Retrieves that Java Class that the attached Meta behaviours apply to- Returns:
- The java.lang.Class instance
 
- 
invokeConstructorjava.lang.Object invokeConstructor(java.lang.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- The arguments to the constructor
- Returns:
- An instance of the java.lang.Class that this MetaObjectProtocol object applies to
 
- 
invokeMethodjava.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.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- The instance which the method is invoked on
- methodName- The name of the method
- arguments- The arguments to the method
- Returns:
- The return value of the method which is null if the return type is void
- See Also:
- MissingMethodException
 
- 
invokeMethodjava.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Invokes a method on the given object, with the given name and single argument.- Parameters:
- object- The Object to invoke the method on
- methodName- The name of the method
- arguments- The argument to the method
- Returns:
- The return value of the method which is null if the return type is void
- See Also:
- invokeMethod(Object, String, Object[])
 
- 
invokeStaticMethodjava.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.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- An instance of the class returned by the getTheClass() method or the class itself
- methodName- The name of the method
- arguments- The arguments to the method
- Returns:
- The return value of the method which is null if the return type is void
- See Also:
- MissingMethodException
 
- 
getPropertyjava.lang.Object getProperty(java.lang.Object object, java.lang.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- An instance of the class returned by the getTheClass() method
- property- The name of the property to retrieve the value for
- Returns:
- The properties value
- See Also:
- MetaClassImpl
 
- 
setPropertyvoid setProperty(java.lang.Object object, java.lang.String property, java.lang.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- An instance of the class returned by the getTheClass() method
- property- The name of the property to set
- newValue- The new value of the property
- See Also:
- MetaClassImpl
 
- 
getAttributejava.lang.Object getAttribute(java.lang.Object object, java.lang.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- An instance of the class returned by the getTheClass() method
- attribute- The name of the attribute to retrieve the value for
- Returns:
- The attribute value
- See Also:
- MetaClassImpl
 
- 
setAttributevoid setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.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- An instance of the class returned by the getTheClass() method
- attribute- The name of the attribute to set
- newValue- The new value of the attribute
- See Also:
- MetaClassImpl
 
 
-