freemarker.ext.beans2
Class IteratorMethodWrapper

java.lang.Object
  extended by freemarker.ext.beans2.IteratorMethodWrapper
All Implemented Interfaces:
TemplateListModel2, TemplateModel

public class IteratorMethodWrapper
extends java.lang.Object
implements TemplateListModel2

Wraps a method that returns an iterator. The iterator is then wrapped in an IteratorWrapper or ListIteratorWrapper.

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

Field Summary
protected  java.lang.reflect.Method method
          The method returning the Iterator
protected  java.lang.Object object
          The target object for the Method
protected  java.lang.Object[] paramValues
          Any parameters to be passed to the Method
 
Constructor Summary
IteratorMethodWrapper()
          Default constructor where an iterator method is not provided initially.
IteratorMethodWrapper(java.lang.reflect.Method method, java.lang.Object[] paramValues)
          Constructor that takes a method and object parameters to be provided to the method call.
IteratorMethodWrapper(java.lang.reflect.Method method, java.lang.Object[] paramValues, java.lang.Object object)
          Constructor that takes a method, the object target for the method, and object parameters to be provided to the method call.
 
Method Summary
 boolean isEmpty()
          Is the object empty?
 void releaseIterator(TemplateIteratorModel iterator)
          Returns the used iterator to the list model.
 void setMethod(java.lang.reflect.Method method)
          Sets the method to be called by this iterator method wrapper.
 void setObject(java.lang.Object object)
          Sets the object target for the method to be called.
 void setParamValues(java.lang.Object[] paramValues)
          Sets the object values to be passed as parameters to the method call.
 TemplateIteratorModel templateIterator()
          Retrieves an iterator to iterate over this list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

object

protected java.lang.Object object
The target object for the Method


method

protected java.lang.reflect.Method method
The method returning the Iterator


paramValues

protected java.lang.Object[] paramValues
Any parameters to be passed to the Method

Constructor Detail

IteratorMethodWrapper

public IteratorMethodWrapper()
Default constructor where an iterator method is not provided initially.


IteratorMethodWrapper

public IteratorMethodWrapper(java.lang.reflect.Method method,
                             java.lang.Object[] paramValues)
Constructor that takes a method and object parameters to be provided to the method call.

Parameters:
method - the Method to be called
paramValues - parameters to be supplied to the method

IteratorMethodWrapper

public IteratorMethodWrapper(java.lang.reflect.Method method,
                             java.lang.Object[] paramValues,
                             java.lang.Object object)
Constructor that takes a method, the object target for the method, and object parameters to be provided to the method call.

Parameters:
method - the Method to be called
paramValues - parameters to be supplied to the method
object - the object that is the target of the method
Method Detail

setObject

public void setObject(java.lang.Object object)
Sets the object target for the method to be called.

Parameters:
object - the object target for the method

setMethod

public void setMethod(java.lang.reflect.Method method)
Sets the method to be called by this iterator method wrapper.

Parameters:
method - the method to be called

setParamValues

public void setParamValues(java.lang.Object[] paramValues)
Sets the object values to be passed as parameters to the method call.

Parameters:
paramValues - the values to be passed to 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

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Retrieves an iterator to iterate over this list. Can choose to return null if there are no elements in the list.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
an iterator to iterate over the current list.
Throws:
TemplateModelException - the next item in the list can't be retrieved, or no next item exists.

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)

Returns the used iterator to the list model. Implement this method when you want to use an object pool of TemplateIterator objects. Otherwise, leave the implementation of this method blank.

Note that if the iterator returned in templateIterator() is null, this method will not be called for the null iterator.

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator to be returned to the object pool, if any