freemarker.ext.beans2
Class StaticMethodWrapper

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

public class StaticMethodWrapper
extends java.lang.Object
implements TemplateMethodModel2

Wraps a static 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: StaticMethodWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull

Field Summary
protected  java.lang.Class clazz
          The class on which the method will be called
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 class
 
Constructor Summary
StaticMethodWrapper()
          Default constructor where no target class or identifier are supplied.
StaticMethodWrapper(java.lang.Class clazz, java.lang.String identifier)
          Constructor that takes a class 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 setClazz(java.lang.Class clazz)
          Sets the class on which the method will be resolved and called.
 void setIdentifier(java.lang.String identifier)
          Sets the identifier for the method, possibly overloaded.
 
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


clazz

protected java.lang.Class clazz
The class 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 class

Constructor Detail

StaticMethodWrapper

public StaticMethodWrapper()
Default constructor where no target class or identifier are supplied.


StaticMethodWrapper

public StaticMethodWrapper(java.lang.Class clazz,
                           java.lang.String identifier)
Constructor that takes a class on which the method will be called, and an identifier to resolve to a method.

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

setClazz

public void setClazz(java.lang.Class clazz)
Sets the class on which the method will be resolved and called.

Parameters:
clazz - the class 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