groovy.lang
Class MetaClassImpl

java.lang.Object
  extended bygroovy.lang.MetaClass
      extended bygroovy.lang.MetaClassImpl
Direct Known Subclasses:
ProxyMetaClass

public class MetaClassImpl
extends MetaClass

Allows methods to be dynamically added to existing classes at runtime

Version:
$Revision: 1.9 $
Author:
James Strachan, Guillaume Laforge, Jochen Theodorou

Field Summary
protected  MetaClassRegistry registry
           
 
Fields inherited from class groovy.lang.MetaClass
log, newGroovyMethodsList, NO_METHOD_FOUND, theClass, useReflection
 
Constructor Summary
MetaClassImpl(MetaClassRegistry registry, Class theClass)
           
 
Method Summary
protected  void addNewInstanceMethod(Method method)
          Allows static method definitions to be added to a meta class as if it was an instance method
protected  void addNewStaticMethod(Method method)
           
protected  void checkInitialised()
           
 Object getAttribute(Object object, String attribute)
          Looks up the given attribute (field) on the given object
 ClassNode getClassNode()
           
 List getMetaMethods()
           
 List getMethods()
           
 List getProperties()
          Get all the properties defined for this type
 Object getProperty(Object object, String property)
           
 Object invokeConstructor(Object[] arguments)
           
 Object invokeConstructorAt(Class at, Object[] arguments)
           
 Object invokeMethod(Object object, String methodName, Object[] arguments)
          Invokes the given method on the object.
 Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
           
protected  MetaMethod pickMethod(Object object, String methodName, Object[] arguments)
          Picks which method to invoke for the given object, method name and arguments
protected  MetaMethod pickMethod(String methodName, Class[] arguments)
          pick a method in a strict manner, i.e., without reinterpreting the first List argument.
 Constructor retrieveConstructor(Class[] arguments)
           
 MetaMethod retrieveMethod(Object owner, String methodName, Object[] arguments)
           
 MetaMethod retrieveMethod(String methodName, Class[] arguments)
           
 MetaMethod retrieveStaticMethod(String methodName, Class[] arguments)
           
 void setAttribute(Object object, String attribute, Object newValue)
          Sets the given attribute (field) on the given object
 void setProperties(Object bean, Map map)
          Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set
 void setProperty(Object object, String property, Object newValue)
          Sets the property value on an object
 String toString()
           
 
Methods inherited from class groovy.lang.MetaClass
invokeMethod, isUseReflection, setUseReflection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

registry

protected MetaClassRegistry registry
Constructor Detail

MetaClassImpl

public MetaClassImpl(MetaClassRegistry registry,
                     Class theClass)
              throws IntrospectionException
Method Detail

addNewInstanceMethod

protected void addNewInstanceMethod(Method method)
Allows static method definitions to be added to a meta class as if it was an instance method

Specified by:
addNewInstanceMethod in class MetaClass
Parameters:
method -

addNewStaticMethod

protected void addNewStaticMethod(Method method)
Specified by:
addNewStaticMethod in class MetaClass

invokeMethod

public Object invokeMethod(Object object,
                           String methodName,
                           Object[] arguments)
Invokes the given method on the object.

Specified by:
invokeMethod in class MetaClass

retrieveMethod

public MetaMethod retrieveMethod(Object owner,
                                 String methodName,
                                 Object[] arguments)
Specified by:
retrieveMethod in class MetaClass

retrieveMethod

public MetaMethod retrieveMethod(String methodName,
                                 Class[] arguments)
Specified by:
retrieveMethod in class MetaClass

retrieveConstructor

public Constructor retrieveConstructor(Class[] arguments)
Specified by:
retrieveConstructor in class MetaClass

retrieveStaticMethod

public MetaMethod retrieveStaticMethod(String methodName,
                                       Class[] arguments)
Specified by:
retrieveStaticMethod in class MetaClass

pickMethod

protected MetaMethod pickMethod(Object object,
                                String methodName,
                                Object[] arguments)
Picks which method to invoke for the given object, method name and arguments

Specified by:
pickMethod in class MetaClass

pickMethod

protected MetaMethod pickMethod(String methodName,
                                Class[] arguments)
pick a method in a strict manner, i.e., without reinterpreting the first List argument. this method is used only by ClassGenerator for static binding

Specified by:
pickMethod in class MetaClass
Parameters:
methodName -
arguments -
Returns:

invokeStaticMethod

public Object invokeStaticMethod(Object object,
                                 String methodName,
                                 Object[] arguments)
Specified by:
invokeStaticMethod in class MetaClass

invokeConstructor

public Object invokeConstructor(Object[] arguments)
Specified by:
invokeConstructor in class MetaClass

invokeConstructorAt

public Object invokeConstructorAt(Class at,
                                  Object[] arguments)
Specified by:
invokeConstructorAt in class MetaClass

setProperties

public void setProperties(Object bean,
                          Map map)
Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set

Specified by:
setProperties in class MetaClass

getProperty

public Object getProperty(Object object,
                          String property)
Specified by:
getProperty in class MetaClass
Returns:
the given property's value on the object

getProperties

public List getProperties()
Get all the properties defined for this type

Specified by:
getProperties in class MetaClass
Returns:
a list of MetaProperty objects

setProperty

public void setProperty(Object object,
                        String property,
                        Object newValue)
Sets the property value on an object

Specified by:
setProperty in class MetaClass

getAttribute

public Object getAttribute(Object object,
                           String attribute)
Looks up the given attribute (field) on the given object

Specified by:
getAttribute in class MetaClass

setAttribute

public void setAttribute(Object object,
                         String attribute,
                         Object newValue)
Sets the given attribute (field) on the given object

Specified by:
setAttribute in class MetaClass

getClassNode

public ClassNode getClassNode()
Specified by:
getClassNode in class MetaClass

toString

public String toString()

checkInitialised

protected void checkInitialised()
Specified by:
checkInitialised in class MetaClass

getMethods

public List getMethods()
Specified by:
getMethods in class MetaClass

getMetaMethods

public List getMetaMethods()
Specified by:
getMetaMethods in class MetaClass


Copyright © 2003-2007 The Codehaus. All Rights Reserved.