freemarker.ext.beans
Class IteratorModel

java.lang.Object
  |
  +--freemarker.ext.beans.ObjectModelBase
        |
        +--freemarker.ext.beans.ObjectModel
              |
              +--freemarker.ext.beans.IteratorModel
All Implemented Interfaces:
TemplateHashModel, TemplateListModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel

public final class IteratorModel
extends ObjectModel
implements TemplateListModel2

A class that adds TemplateListModel2 functionality to the Iterator interface implementers.

Using the model as a list model is NOT thread-safe, as iterators are inherently not thread-safe.

Version:
$Id: IteratorModel.java,v 1.5 2003/11/26 05:53:48 run2000 Exp $
Author:
Attila Szegedi, attila@szegedi.org

Fields inherited from class freemarker.ext.beans.ObjectModelBase
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_LIST, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
IteratorModel(java.util.Iterator iterator)
          Creates a new model that wraps the specified iterator object.
 
Method Summary
static IteratorModel getInstance(java.util.Iterator object)
          Returns a model wrapping the specified iterator object.
 int getType()
          Returns the type of this object (which is TYPE_ITERATOR)
 boolean isEmpty()
          Returns true if the iterator is null or the iterator has no elements remaining, otherwise false.
 void releaseIterator(TemplateIteratorModel iterator)
          Release the underlying iterator.
 TemplateIteratorModel templateIterator()
          Retrive an iterator for this object.
 
Methods inherited from class freemarker.ext.beans.ObjectModel
get, getInstance
 
Methods inherited from class freemarker.ext.beans.ObjectModelBase
getAsObject, getAsString, getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorModel

public IteratorModel(java.util.Iterator iterator)
Creates a new model that wraps the specified iterator object.
Parameters:
iterator - the iterator object to wrap into a model.
Method Detail

getInstance

public static final IteratorModel getInstance(java.util.Iterator object)
Returns a model wrapping the specified iterator object. It always returns a new object, as Iterators are considered short-lived and caching them would have little sense.
Returns:
the model for the iterator

getType

public int getType()
Returns the type of this object (which is TYPE_ITERATOR)
Overrides:
getType in class ObjectModel

isEmpty

public boolean isEmpty()
Returns true if the iterator is null or the iterator has no elements remaining, otherwise false.
Specified by:
isEmpty in interface TemplateModel
Overrides:
isEmpty in class ObjectModelBase
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty, otherwise false

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Retrive an iterator for this object.
Specified by:
templateIterator in interface TemplateListModel2
Returns:
a TemplateIteratorModel wrapping the underlying java.util.Iterator implementation

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Release the underlying iterator. The iterator can only be called once.
Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the wrapper for the iterator to be released