org.apache.commons.betwixt.expression
Class MethodExpression

java.lang.Object
  extended by org.apache.commons.betwixt.expression.MethodExpression
All Implemented Interfaces:
Expression

public class MethodExpression
extends java.lang.Object
implements Expression

MethodExpression evaluates a method on the current bean context.

Version:
$Revision: 471234 $
Author:
James Strachan

Field Summary
protected static java.lang.Object[] NULL_ARGUMENTS
          null arguments
protected static java.lang.Class[] NULL_CLASSES
          null classes
 
Constructor Summary
MethodExpression()
          Base constructor
MethodExpression(java.lang.reflect.Method method)
          Convenience constructor sets method property
 
Method Summary
 java.lang.Object evaluate(Context context)
          Evaluate by calling the read method on the current bean
protected  java.lang.reflect.Method findAlternateMethod(java.lang.Class type, java.lang.reflect.Method method)
          Tries to find an alternate method for the given type using interfaces which gets around the problem of inner classes, such as on Map.Entry implementations.
protected  java.lang.Object[] getArguments()
          Allows derived objects to create arguments for the method call
 java.lang.reflect.Method getMethod()
          Gets the method used to evaluate this expression.
protected  void handleException(Context context, java.lang.Exception e)
          Log error to context's logger.
protected  void handleException(Context context, java.lang.Exception e, java.lang.reflect.Method m)
          Log error to context's logger.
 void setMethod(java.lang.reflect.Method method)
          Sets the method used to evaluate this expression
 java.lang.String toString()
          Returns something useful for logging.
 void update(Context context, java.lang.String newValue)
          Do nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_ARGUMENTS

protected static java.lang.Object[] NULL_ARGUMENTS
null arguments


NULL_CLASSES

protected static java.lang.Class[] NULL_CLASSES
null classes

Constructor Detail

MethodExpression

public MethodExpression()
Base constructor


MethodExpression

public MethodExpression(java.lang.reflect.Method method)
Convenience constructor sets method property

Parameters:
method - the Method whose return value when invoked on the bean will the value of this expression
Method Detail

evaluate

public java.lang.Object evaluate(Context context)
Evaluate by calling the read method on the current bean

Specified by:
evaluate in interface Expression
Parameters:
context - the context against which this expression will be evaluated
Returns:
the value returned by the method when it's invoked on the context's bean, so long as the method can be invoked. Otherwise, null.

update

public void update(Context context,
                   java.lang.String newValue)
Do nothing.

Specified by:
update in interface Expression
Parameters:
context - update this Context
newValue - the new value for this expression
See Also:
Expression

getMethod

public java.lang.reflect.Method getMethod()
Gets the method used to evaluate this expression.

Returns:
the method whose value (when invoked against the context's bean) will be used to evaluate this expression.

setMethod

public void setMethod(java.lang.reflect.Method method)
Sets the method used to evaluate this expression

Parameters:
method - method whose value (when invoked against the context's bean) will be used to evaluate this expression

getArguments

protected java.lang.Object[] getArguments()
Allows derived objects to create arguments for the method call

Returns:
NULL_ARGUMENTS

findAlternateMethod

protected java.lang.reflect.Method findAlternateMethod(java.lang.Class type,
                                                       java.lang.reflect.Method method)
Tries to find an alternate method for the given type using interfaces which gets around the problem of inner classes, such as on Map.Entry implementations.

Parameters:
type - the Class whose methods are to be searched
method - the Method for which an alternative is to be search for
Returns:
the alternative Method, if one can be found. Otherwise null.

handleException

protected void handleException(Context context,
                               java.lang.Exception e,
                               java.lang.reflect.Method m)

Log error to context's logger.

Allows derived objects to handle exceptions differently.

Parameters:
context - the Context being evaluated when the exception occured
e - the exception to handle
Since:
0.8

handleException

protected void handleException(Context context,
                               java.lang.Exception e)

Log error to context's logger.

Allows derived objects to handle exceptions differently.

Parameters:
context - the Context being evaluated when the exception occured
e - the exception to handle

toString

public java.lang.String toString()
Returns something useful for logging.

Overrides:
toString in class java.lang.Object
Returns:
something useful for logging


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.