groovy.lang
Class MetaClassImpl

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

public class MetaClassImpl
extends MetaClass

Allows methods to be dynamically added to existing classes at runtime

Version:
$Revision: 4611 $
Author:
James Strachan, Guillaume Laforge, Jochen Theodorou
See Also:
MetaClass

Field Summary
protected  MetaClassRegistry registry
           
 
Fields inherited from class groovy.lang.MetaClass
log, NO_METHOD_FOUND, theClass, useReflection
 
Constructor Summary
MetaClassImpl(MetaClassRegistry registry, Class theClass)
           
 
Method Summary
protected  void addMetaMethod(MetaMethod method)
          adds a MetaMethod to this class.
 void addNewInstanceMethod(Method method)
          adds a new instance method to this meta class.
 void addNewStaticMethod(Method method)
          adds a new static method to this meta class.
protected  void cacheInstanceMethod(MethodKey key, MetaMethod method)
           
protected  void cacheStaticMethod(MethodKey key, MetaMethod method)
           
protected  void checkInitalised()
          checks if the initialisation of the class id complete.
protected  void clearInvocationCaches()
          remove all method call cache entries.
 Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)
          Looks up the given attribute (field) on the given object
 Object getAttribute(Object object, String attribute)
          Deprecated.  
 ClassNode getClassNode()
           
 List getMetaMethods()
           
 List getMethods()
           
 List getProperties()
          Get all the properties defined for this type
 Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass)
           
 Object getProperty(Object object, String property)
          Deprecated.  
 void initialize()
          complete the initlialisation process.
 Object invokeConstructor(Object[] arguments)
           
 Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
          Invokes the given method on the object.
 Object invokeMethod(Object object, String methodName, Object[] originalArguments)
          Deprecated.  
 Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
           
protected  boolean isInitialized()
           
 MetaMethod pickMethod(Class sender, String methodName, Class[] arguments, boolean isCallToSuper)
          pick a method in a strict manner, i.e., without reinterpreting the first List argument.
 MetaMethod pickMethod(String methodName, Class[] arguments)
          Warning, this method will be removed until 1.0
 Constructor retrieveConstructor(Class[] arguments)
           
 MetaMethod retrieveMethod(Class sender, String methodName, Class[] arguments, boolean isCallToSuper)
           
protected  MetaMethod retrieveMethod(String methodName, Class[] arguments)
          Warning, this method will be removed until 1.0
 MetaMethod retrieveStaticMethod(String methodName, Class[] arguments)
           
 int selectConstructorAndTransformArguments(int numberOfCosntructors, Object[] arguments)
           
 void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)
          Sets the given attribute (field) on the given object
 void setAttribute(Object object, String attribute, Object newValue)
          Deprecated.  
 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(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass)
          Sets the property value on an object
 void setProperty(Object object, String property, Object newValue)
          Deprecated.  
 String toString()
           
 
Methods inherited from class groovy.lang.MetaClass
getAttribute, invokeConstructorAt, invokeMethod, invokeMissingMethod, isGroovyObject, 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)
Method Detail

addNewInstanceMethod

public void addNewInstanceMethod(Method method)
Description copied from class: MetaClass
adds a new instance method to this meta class. Instance methods are able to overwrite the original methods of the class. Calling this method should not be done after initlise was called.

Specified by:
addNewInstanceMethod in class MetaClass
Parameters:
method - the method to be added

addNewStaticMethod

public void addNewStaticMethod(Method method)
Description copied from class: MetaClass
adds a new static method to this meta class. This is only possible as long as initilise was not called.

Specified by:
addNewStaticMethod in class MetaClass
Parameters:
method - the method to be added

invokeMethod

public Object invokeMethod(Object object,
                           String methodName,
                           Object[] originalArguments)
Deprecated. 

Invokes the given method on the object.

Specified by:
invokeMethod in class MetaClass

invokeMethod

public Object invokeMethod(Class sender,
                           Object object,
                           String methodName,
                           Object[] originalArguments,
                           boolean isCallToSuper,
                           boolean fromInsideClass)
Invokes the given method on the object.

Overrides:
invokeMethod in class MetaClass

retrieveMethod

public MetaMethod retrieveMethod(Class sender,
                                 String methodName,
                                 Class[] arguments,
                                 boolean isCallToSuper)

cacheInstanceMethod

protected void cacheInstanceMethod(MethodKey key,
                                   MetaMethod method)

cacheStaticMethod

protected void cacheStaticMethod(MethodKey key,
                                 MetaMethod method)

retrieveConstructor

public Constructor retrieveConstructor(Class[] arguments)

retrieveStaticMethod

public MetaMethod retrieveStaticMethod(String methodName,
                                       Class[] arguments)

pickMethod

public MetaMethod pickMethod(Class sender,
                             String methodName,
                             Class[] arguments,
                             boolean isCallToSuper)
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

Parameters:
methodName -
arguments -

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

selectConstructorAndTransformArguments

public int selectConstructorAndTransformArguments(int numberOfCosntructors,
                                                  Object[] arguments)

checkInitalised

protected void checkInitalised()
checks if the initialisation of the class id complete. This method should be called as a form of assert, it is no way to test if there is still initialisation work to be done. Such logic must be implemented in a different way.

Throws:
IllegalStateException - if the initialisation is incomplete yet

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


getProperty

public Object getProperty(Class sender,
                          Object object,
                          String name,
                          boolean useSuper,
                          boolean fromInsideClass)
Overrides:
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(Class sender,
                        Object object,
                        String name,
                        Object newValue,
                        boolean useSuper,
                        boolean fromInsideClass)
Sets the property value on an object

Overrides:
setProperty in class MetaClass

getAttribute

public Object getAttribute(Class sender,
                           Object object,
                           String attribute,
                           boolean useSuper,
                           boolean fromInsideClass)
Looks up the given attribute (field) on the given object


setAttribute

public void setAttribute(Class sender,
                         Object object,
                         String attribute,
                         Object newValue,
                         boolean useSuper,
                         boolean fromInsideClass)
Sets the given attribute (field) on the given object

Overrides:
setAttribute in class MetaClass

getClassNode

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

toString

public String toString()
Overrides:
toString in class Object

addMetaMethod

protected void addMetaMethod(MetaMethod method)
adds a MetaMethod to this class. WARNING: this method will not do the neccessary steps for multimethod logic and using this method doesn't mean, that a method added here is replacing another method from a parent class completely. These steps are usually done by initalize, which means if you need these steps, you have to add the method before running initialize the first time.

Parameters:
method - the MetaMethod
See Also:
initialize()

isInitialized

protected boolean isInitialized()

initialize

public void initialize()
Description copied from class: MetaClass
complete the initlialisation process. After this method is called no methods should be added to the meta class. Invocation of methods or access to fields/proeprties 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.

Specified by:
initialize in class MetaClass

getMethods

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

getMetaMethods

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

getProperty

public Object getProperty(Object object,
                          String property)
Deprecated. 

Specified by:
getProperty in class MetaClass

setProperty

public void setProperty(Object object,
                        String property,
                        Object newValue)
Deprecated. 

Specified by:
setProperty in class MetaClass

getAttribute

public Object getAttribute(Object object,
                           String attribute)
Deprecated. 

Specified by:
getAttribute in class MetaClass

setAttribute

public void setAttribute(Object object,
                         String attribute,
                         Object newValue)
Deprecated. 

Specified by:
setAttribute in class MetaClass

pickMethod

public MetaMethod pickMethod(String methodName,
                             Class[] arguments)
Description copied from class: MetaClass
Warning, this method will be removed until 1.0

Specified by:
pickMethod in class MetaClass

retrieveMethod

protected MetaMethod retrieveMethod(String methodName,
                                    Class[] arguments)
Description copied from class: MetaClass
Warning, this method will be removed until 1.0

Specified by:
retrieveMethod in class MetaClass

clearInvocationCaches

protected void clearInvocationCaches()
remove all method call cache entries. This should be done if a method is added during runtime, but not by using a category.



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