groovy.lang
Class MetaClass

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

public abstract class MetaClass
extends Object

Base class for meta class implementations. The meta class is used to invoke methods or to get fields/properties. For proper initialization of this class it is not enough to only call the constructor, the initialize() must be called too. The invoke methods should check that initialize() was called. Adding methods is valid unless initilise method was called. Therefore addNewStaticMethod and addNewInstanceMethod should check that that initilise awas not called before.

Author:
John Wilson

Field Summary
protected static Logger log
           
static Object NO_METHOD_FOUND
           
protected  Class theClass
           
protected static boolean useReflection
           
 
Constructor Summary
protected MetaClass(Class theClass)
           
 
Method Summary
abstract  void addNewInstanceMethod(Method method)
          adds a new instance method to this meta class.
abstract  void addNewStaticMethod(Method method)
          adds a new static method to this meta class.
 Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper)
           
abstract  Object getAttribute(Object object, String attribute)
           
abstract  ClassNode getClassNode()
           
abstract  List getMetaMethods()
           
abstract  List getMethods()
           
abstract  List getProperties()
           
 Object getProperty(Class sender, Object receiver, String messageName, boolean useSuper, boolean fromInsideClass)
           
abstract  Object getProperty(Object object, String property)
           
abstract  void initialize()
          complete the initlialisation process.
abstract  Object invokeConstructor(Object[] arguments)
           
 Object invokeConstructorAt(Class at, Object[] arguments)
          Deprecated.  
 Object invokeMethod(Class sender, Object receiver, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)
           
 Object invokeMethod(Object object, String methodName, Object arguments)
           
abstract  Object invokeMethod(Object object, String methodName, Object[] arguments)
           
 Object invokeMissingMethod(Object instance, String methodName, Object[] arguments)
           
abstract  Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
           
 boolean isGroovyObject()
           
static boolean isUseReflection()
           
abstract  MetaMethod pickMethod(String methodName, Class[] arguments)
          Deprecated.  
protected abstract  MetaMethod retrieveMethod(String methodName, Class[] arguments)
          Deprecated.  
 void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass)
           
abstract  void setAttribute(Object object, String attribute, Object newValue)
           
 void setProperty(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass)
           
abstract  void setProperty(Object object, String property, Object newValue)
           
static void setUseReflection(boolean useReflection)
          Allows reflection to be enabled in situations where bytecode generation of method invocations causes issues.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final Logger log

useReflection

protected static boolean useReflection

NO_METHOD_FOUND

public static final Object NO_METHOD_FOUND

theClass

protected final Class theClass
Constructor Detail

MetaClass

protected MetaClass(Class theClass)
Method Detail

isUseReflection

public static boolean isUseReflection()

setUseReflection

public static void setUseReflection(boolean useReflection)
Allows reflection to be enabled in situations where bytecode generation of method invocations causes issues.

Parameters:
useReflection -

isGroovyObject

public boolean isGroovyObject()

invokeMissingMethod

public Object invokeMissingMethod(Object instance,
                                  String methodName,
                                  Object[] arguments)

invokeMethod

public Object invokeMethod(Object object,
                           String methodName,
                           Object arguments)

invokeMethod

public Object invokeMethod(Class sender,
                           Object receiver,
                           String methodName,
                           Object[] arguments,
                           boolean isCallToSuper,
                           boolean fromInsideClass)

getProperty

public Object getProperty(Class sender,
                          Object receiver,
                          String messageName,
                          boolean useSuper,
                          boolean fromInsideClass)

setProperty

public void setProperty(Class sender,
                        Object receiver,
                        String messageName,
                        Object messageValue,
                        boolean useSuper,
                        boolean fromInsideClass)

getAttribute

public Object getAttribute(Class sender,
                           Object receiver,
                           String messageName,
                           boolean useSuper)

setAttribute

public void setAttribute(Class sender,
                         Object receiver,
                         String messageName,
                         Object messageValue,
                         boolean useSuper,
                         boolean fromInsideClass)

invokeConstructor

public abstract Object invokeConstructor(Object[] arguments)

invokeMethod

public abstract Object invokeMethod(Object object,
                                    String methodName,
                                    Object[] arguments)

invokeStaticMethod

public abstract Object invokeStaticMethod(Object object,
                                          String methodName,
                                          Object[] arguments)

getProperty

public abstract Object getProperty(Object object,
                                   String property)

setProperty

public abstract void setProperty(Object object,
                                 String property,
                                 Object newValue)

getAttribute

public abstract Object getAttribute(Object object,
                                    String attribute)

setAttribute

public abstract void setAttribute(Object object,
                                  String attribute,
                                  Object newValue)

addNewInstanceMethod

public abstract void addNewInstanceMethod(Method method)
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.

Parameters:
method - the method to be added

addNewStaticMethod

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

Parameters:
method - the method to be added

initialize

public abstract void initialize()
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.


getProperties

public abstract List getProperties()

getClassNode

public abstract ClassNode getClassNode()

getMetaMethods

public abstract List getMetaMethods()

getMethods

public abstract List getMethods()

invokeConstructorAt

public Object invokeConstructorAt(Class at,
                                  Object[] arguments)
Deprecated. 

Warning, this method will be removed until 1.0


pickMethod

public abstract MetaMethod pickMethod(String methodName,
                                      Class[] arguments)
Deprecated. 

Warning, this method will be removed until 1.0


retrieveMethod

protected abstract MetaMethod retrieveMethod(String methodName,
                                             Class[] arguments)
Deprecated. 

Warning, this method will be removed until 1.0



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