freemarker.ext.beans2
Class MethodWrapper

java.lang.Object
  extended by freemarker.ext.beans2.MethodWrapper
All Implemented Interfaces:
TemplateMethodModel2, TemplateModel

public class MethodWrapper
extends java.lang.Object
implements TemplateMethodModel2

Wraps a method identifier. The method identifier is resolved to a Method object when the method is invoked. This allows different Method objects to be invoked depending on the number and type of objects supplied to the call.

Since:
1.9
Version:
$Id: MethodWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull

Field Summary
protected static Converter[] emptyConverters
          Convenience value for methods that need no argument conversions
protected static TemplateModel[] emptyModelArguments
          Convenience value for methods where no arguments were supplied
protected static java.lang.Object[] emptyParamValues
          Convenience value for methods that take zero arguments
protected  java.lang.String identifier
          The name of the method, which may be overloaded, to be resolved against the object
protected  java.lang.Object object
          The object on which the method will be called
 
Constructor Summary
MethodWrapper()
          Default constructor where no target method object or identifier are supplied.
MethodWrapper(java.lang.Object object, java.lang.String identifier)
          Constructor that takes an object on which the method will be called, and an identifier to resolve to a method.
 
Method Summary
 TemplateModel exec(java.util.List<TemplateModel> arguments)
          Executes a method call.
 boolean isEmpty()
          Is the object empty?
 void setIdentifier(java.lang.String identifier)
          Sets the identifier for the method, possibly overloaded.
 void setObject(java.lang.Object object)
          Sets the object on which the method will be resolved and called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyParamValues

protected static final java.lang.Object[] emptyParamValues
Convenience value for methods that take zero arguments


emptyConverters

protected static final Converter[] emptyConverters
Convenience value for methods that need no argument conversions


emptyModelArguments

protected static final TemplateModel[] emptyModelArguments
Convenience value for methods where no arguments were supplied


object

protected java.lang.Object object
The object on which the method will be called


identifier

protected java.lang.String identifier
The name of the method, which may be overloaded, to be resolved against the object

Constructor Detail

MethodWrapper

public MethodWrapper()
Default constructor where no target method object or identifier are supplied.


MethodWrapper

public MethodWrapper(java.lang.Object object,
                     java.lang.String identifier)
Constructor that takes an object on which the method will be called, and an identifier to resolve to a method.

Parameters:
object - the object on which the method will be called
identifier - the identifier for the method
Method Detail

setObject

public void setObject(java.lang.Object object)
Sets the object on which the method will be resolved and called.

Parameters:
object - the object on which the method will be called

setIdentifier

public void setIdentifier(java.lang.String identifier)
Sets the identifier for the method, possibly overloaded.

Parameters:
identifier - the identifier for the method

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Description copied from interface: TemplateModel
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

exec

public TemplateModel exec(java.util.List<TemplateModel> arguments)
                   throws TemplateModelException
Description copied from interface: TemplateMethodModel2
Executes a method call. Arguments are passed as a List of TemplateModel objects.

Specified by:
exec in interface TemplateMethodModel2
Parameters:
arguments - a List of TemplateModel objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException