org.codehaus.groovy.runtime
Class Invoker

java.lang.Object
  |
  +--org.codehaus.groovy.runtime.Invoker

public class Invoker
extends Object

A helper class to invoke methods or extract properties on arbitrary Java objects dynamically

Version:
$Revision: 1.26 $
Author:
James Strachan

Field Summary
protected static Object[] EMPTY_ARGUMENTS
           
 
Constructor Summary
Invoker()
           
 
Method Summary
 Object[] asArray(Object arguments)
          Converts the given object into an array; if its an array then just cast otherwise wrap it in an array
 Collection asCollection(Object value)
           
 int asInt(Object value)
           
 Iterator asIterator(Object value)
           
 List asList(Object value)
           
 int compareTo(Object left, Object right)
           
 groovy.lang.MetaClass getMetaClass(Object object)
           
 Object getProperty(Object object, String property)
          Looks up the given property of the given object
 Object invokeConstructor(String type, Object arguments)
           
 Object invokeConstructorOf(Class type, Object arguments)
           
 Object invokeMethod(Object object, String methodName, Object arguments)
          Invokes the given method on the object.
 Object invokeStaticMethod(String type, String method, Object arguments)
           
protected  Class loadClass(String type)
          Attempts to load the given class via name using the current class loader for this code or the thread context class loader
 Matcher objectFindRegex(Object left, Object right)
          Find the right hand regex within the left hand string and return a matcher.
 boolean objectMatchRegex(Object left, Object right)
          Find the right hand regex within the left hand string and return a matcher.
 boolean objectsEqual(Object left, Object right)
           
 Pattern regexPattern(String regex)
          Compile a regular expression from a string.
 void setProperty(Object object, String property, Object newValue)
          Sets the property on the given object
 String toString(Object arguments)
          A helper method to provide some better toString() behaviour such as turning arrays into tuples
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARGUMENTS

protected static final Object[] EMPTY_ARGUMENTS
Constructor Detail

Invoker

public Invoker()
Method Detail

getMetaClass

public groovy.lang.MetaClass getMetaClass(Object object)

invokeMethod

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

Parameters:
object -
methodName -
arguments -
Returns:

invokeStaticMethod

public Object invokeStaticMethod(String type,
                                 String method,
                                 Object arguments)

invokeConstructor

public Object invokeConstructor(String type,
                                Object arguments)

invokeConstructorOf

public Object invokeConstructorOf(Class type,
                                  Object arguments)

asArray

public Object[] asArray(Object arguments)
Converts the given object into an array; if its an array then just cast otherwise wrap it in an array


asList

public List asList(Object value)

asCollection

public Collection asCollection(Object value)
Returns:

asIterator

public Iterator asIterator(Object value)

compareTo

public int compareTo(Object left,
                     Object right)
Parameters:
left -
right -
Returns:

objectsEqual

public boolean objectsEqual(Object left,
                            Object right)
Returns:
true if the two objects are null or the objects are equal

toString

public String toString(Object arguments)
A helper method to provide some better toString() behaviour such as turning arrays into tuples


setProperty

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

Parameters:
object -
property -
newValue -
Returns:

getProperty

public Object getProperty(Object object,
                          String property)
Looks up the given property of the given object

Parameters:
object -
property -
Returns:

asInt

public int asInt(Object value)

loadClass

protected Class loadClass(String type)
Attempts to load the given class via name using the current class loader for this code or the thread context class loader


objectFindRegex

public Matcher objectFindRegex(Object left,
                               Object right)
Find the right hand regex within the left hand string and return a matcher.

Parameters:
left - string to compare
right - regular expression to compare the string to
Returns:

objectMatchRegex

public boolean objectMatchRegex(Object left,
                                Object right)
Find the right hand regex within the left hand string and return a matcher.

Parameters:
left - string to compare
right - regular expression to compare the string to
Returns:

regexPattern

public Pattern regexPattern(String regex)
Compile a regular expression from a string.

Parameters:
regex -
Returns:


Copyright © 2003 The Codehaus. All Rights Reserved.