org.szegedi.expose.model
Class ReflectionIteratorModel

java.lang.Object
  |
  +--org.szegedi.expose.model.ReflectionObjectModelBase
        |
        +--org.szegedi.expose.model.ReflectionObjectModel
              |
              +--org.szegedi.expose.model.ReflectionIteratorModel
All Implemented Interfaces:
freemarker.template.TemplateHashModel, freemarker.template.TemplateListModel, freemarker.template.TemplateModel, freemarker.template.TemplateScalarModel

public final class ReflectionIteratorModel
extends ReflectionObjectModel
implements freemarker.template.TemplateListModel

A class that adds TemplateListModel 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:
1.0
Author:
Attila Szegedi, attila@szegedi.org

Fields inherited from class org.szegedi.expose.model.ReflectionObjectModelBase
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
ReflectionIteratorModel(java.util.Iterator iterator)
          Creates a new model that wraps the specified iterator object.
 
Method Summary
 freemarker.template.TemplateModel get(int index)
          Throws an UnsupportedOperationException as iterator elements can not be accessed at random.
static ReflectionIteratorModel 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 hasNext()
          Calls Iterator.hasNext().
 boolean isEmpty()
          Returns iterator == null || !
 boolean isRewound()
          True if the iterator's next method has not been called since last rewind, or since the object creation.
 freemarker.template.TemplateModel listSize()
          Throws an UnsupportedOperationException as iterator size is unknown
 freemarker.template.TemplateModel next()
          Calls Iterator.next().
 void rewind()
          If the iterator is a ListIterator, rewinds it to the first position.
 
Methods inherited from class org.szegedi.expose.model.ReflectionObjectModel
get, getInstance
 
Methods inherited from class org.szegedi.expose.model.ReflectionObjectModelBase
getAsString, getInstance, getObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionIteratorModel

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

getInstance

public static final ReflectionIteratorModel getInstance(java.util.Iterator object)
Returns a model wrapping the specified iterator object. If there is already a cached model instance for this iterator, returns the cached model instance. Models are cached using WeakReference objects. The caching can be turned off by setting the expose.reflection.nocache system property to true. In this case calling this method is equivalent to constructing a new model.
Parameters:
object - the iterator to wrap into a model.
Returns:
the model for the iterator

getType

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

hasNext

public boolean hasNext()
Calls Iterator.hasNext().
Specified by:
hasNext in interface freemarker.template.TemplateListModel

isRewound

public boolean isRewound()
True if the iterator's next method has not been called since last rewind, or since the object creation.
Specified by:
isRewound in interface freemarker.template.TemplateListModel

next

public freemarker.template.TemplateModel next()
Calls Iterator.next().
Specified by:
next in interface freemarker.template.TemplateListModel

rewind

public void rewind()
            throws freemarker.template.TemplateModelException
If the iterator is a ListIterator, rewinds it to the first position.
Specified by:
rewind in interface freemarker.template.TemplateListModel
Throws:
freemarker.template.TemplateModelException - if the iterator is not a list iterator (and thus cannot be rewound).

isEmpty

public boolean isEmpty()
Returns iterator == null || !iterator.hasNext()
Specified by:
isEmpty in interface freemarker.template.TemplateModel
Overrides:
isEmpty in class ReflectionObjectModelBase

listSize

public freemarker.template.TemplateModel listSize()
Throws an UnsupportedOperationException as iterator size is unknown

get

public freemarker.template.TemplateModel get(int index)
Throws an UnsupportedOperationException as iterator elements can not be accessed at random.