freemarker.ext.beans2
Class ListWrapper<T extends java.util.List>

java.lang.Object
  extended by freemarker.ext.beans2.BeanWrapper<T>
      extended by freemarker.ext.beans2.IterableWrapper<T>
          extended by freemarker.ext.beans2.CollectionWrapper<T>
              extended by freemarker.ext.beans2.ListWrapper<T>
All Implemented Interfaces:
ObjectWrapper, TemplateHashModel, TemplateIndexedModel, TemplateListModel2, TemplateMethodModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel, TemplateWriteableHashModel, TemplateWriteableIndexedModel, java.io.Serializable, java.lang.Cloneable

public class ListWrapper<T extends java.util.List>
extends CollectionWrapper<T>
implements TemplateIndexedModel, TemplateWriteableIndexedModel, java.io.Serializable

Wraps a List object by extending the Collection wrapper to provide an indexed model.

Since:
1.9
Version:
$Id: ListWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Field Summary
 
Fields inherited from class freemarker.ext.beans2.BeanWrapper
emptyParams, object
 
Constructor Summary
ListWrapper()
          Default constructor where an object is not provided initially.
ListWrapper(T object)
          Constructor that takes a List object to be wrapped.
 
Method Summary
 TemplateModel getAtIndex(long index)
          Get the value corresponding to the given index.
 void putAtIndex(long index, TemplateModel model)
          Set the value corresponding to the given index.
 TemplateIteratorModel templateIterator()
          Retrieves an iterator to iterate over this collection.
 
Methods inherited from class freemarker.ext.beans2.CollectionWrapper
exec
 
Methods inherited from class freemarker.ext.beans2.IterableWrapper
releaseIterator
 
Methods inherited from class freemarker.ext.beans2.BeanWrapper
clone, get, getAsObject, getAsString, isEmpty, put, setObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemarker.template.TemplateModel
isEmpty
 
Methods inherited from interface freemarker.template.TemplateListModel2
releaseIterator
 

Constructor Detail

ListWrapper

public ListWrapper()
Default constructor where an object is not provided initially. This allows the wrapper to be used as a prototype.


ListWrapper

public ListWrapper(T object)
Constructor that takes a List object to be wrapped.

Parameters:
object - the list object to be wrapped
Method Detail

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Retrieves an iterator to iterate over this collection.

Specified by:
templateIterator in interface TemplateListModel2
Overrides:
templateIterator in class IterableWrapper<T extends java.util.List>
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.

getAtIndex

public TemplateModel getAtIndex(long index)
                         throws TemplateModelException
Get the value corresponding to the given index. This corresponds correspond to an index into an List such as a java.util.Vector.

Specified by:
getAtIndex in interface TemplateIndexedModel
Parameters:
index - the index of the underlying value we're interested in
Returns:
a TemplateModel representing the value for the given index
Throws:
TemplateModelException - the value could not be determined, possibly due to an index out-of-bounds, or an otherwise undefined value

putAtIndex

public void putAtIndex(long index,
                       TemplateModel model)
                throws TemplateModelException
Set the value corresponding to the given index. Traditionally this would correspond to an index into an array, or similar structure, such as a java.util.Vector.

Specified by:
putAtIndex in interface TemplateWriteableIndexedModel
Parameters:
index - the index of the underlying value we're interested in
model - the model to be added to the list
Throws:
TemplateModelException - the value could not be determined, possibly due to an index out-of-bounds, or an otherwise undefined value