freemarker.template
Class SimpleList

java.lang.Object
  |
  +--freemarker.template.SimpleList
All Implemented Interfaces:
java.io.Serializable, TemplateListModel, TemplateModel

public class SimpleList
extends java.lang.Object
implements TemplateListModel, java.io.Serializable

A simple implementation of the TemplateListModel interface, using a LinkedList.

A SimpleList can act as a cache for another TemplateListModel, e.g. one that gets data from a database. When passed another TemplateListModel as an argument to its constructor or to its copy method, the SimpleList immediately copies all the elements and discards the TemplateListModel.

A SimpleList can also be given a shelf life; it then keeps track of the time elapsed since the last time it copied another TemplateListModel, or the last time its shelf life was set. Its owner can check whether it has become stale, and refresh it if necessary by copying data into it again.

All the public methods in this implementation are synchronized.

See Also:
Serialized Form

Constructor Summary
SimpleList()
          Constructs an empty SimpleList with an indefinite shelf life.
SimpleList(java.util.LinkedList list)
          Constructs a SimpleList from the given LinkedList with an idenfinite shelf life.
SimpleList(TemplateListModel listToCopy)
          Constructs a SimpleList, copying into it the values from another TemplateListModel.
SimpleList(TemplateModel[] list)
          Constructs a SimpleList from the given Array of TemplateModels
 
Method Summary
 void add(boolean b)
          Adds a boolean to the end of this SimpleList, by first wrapping the boolean in a SimpleScalar.
 void add(java.lang.String s)
          Adds a string to the end of this SimpleList, by first wrapping the string in a SimpleScalar.
 void add(TemplateModel element)
          Adds a TemplateModel to the end of this SimpleList.
 void clear()
          Removes all the elements from this SimpleList.
 void copy(TemplateListModel listToCopy)
          Discards the contents of this SimpleList, and copies into it the values from another TemplateListModel.
 TemplateModel get(int i)
           
 int getShelfLife()
           
 boolean hasNext()
           
 boolean isEmpty()
           
 boolean isPermanent()
           
 boolean isRewound()
           
 boolean isStale()
           
 TemplateModel listSize()
           
 TemplateModel next()
           
 void rewind()
          Resets the cursor to the beginning of the list.
 void setPermanent()
          Gives this SimpleList an indefinite shelf life.
 void setShelfLife(int minutes)
          Sets the amount of time before this SimpleList will become stale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleList

public SimpleList()
Constructs an empty SimpleList with an indefinite shelf life.

SimpleList

public SimpleList(java.util.LinkedList list)
Constructs a SimpleList from the given LinkedList with an idenfinite shelf life.

SimpleList

public SimpleList(TemplateModel[] list)
Constructs a SimpleList from the given Array of TemplateModels

SimpleList

public SimpleList(TemplateListModel listToCopy)
Constructs a SimpleList, copying into it the values from another TemplateListModel. If the latter throws an exception, this SimpleList saves the exception, and throws it when its own next() method is called.
Parameters:
listToCopy - the list to be copied into this one.
Method Detail

clear

public void clear()
Removes all the elements from this SimpleList.

setShelfLife

public void setShelfLife(int minutes)
Sets the amount of time before this SimpleList will become stale.
Parameters:
minutes - the number of minutes before this SimpleList will become stale.

getShelfLife

public int getShelfLife()
Returns:
this SimpleList's shelf life in minutes.

setPermanent

public void setPermanent()
Gives this SimpleList an indefinite shelf life.

isPermanent

public boolean isPermanent()
Returns:
true if this SimpleList has an indefinite shelf life.

isStale

public boolean isStale()
Returns:
true if this SimpleList has become stale.

copy

public void copy(TemplateListModel listToCopy)
Discards the contents of this SimpleList, and copies into it the values from another TemplateListModel. If the latter throws an exception, this SimpleList saves the exception, and throws it when its own next() method is called.
Parameters:
listToCopy - the list to be copied into this one.

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Specified by:
isEmpty in interface TemplateModel
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty.

isRewound

public boolean isRewound()
                  throws TemplateModelException
Specified by:
isRewound in interface TemplateListModel
Following copied from interface: freemarker.template.TemplateListModel
Returns:
true if the cursor is at the beginning of the list.

add

public void add(TemplateModel element)
Adds a TemplateModel to the end of this SimpleList. Also moves the cursor to the beginning of the list.
Parameters:
element - the TemplateModel to be added.

add

public void add(java.lang.String s)
Adds a string to the end of this SimpleList, by first wrapping the string in a SimpleScalar. Also moves the cursor to the beginning of the list.
Parameters:
element - the string to be added.

add

public void add(boolean b)
Adds a boolean to the end of this SimpleList, by first wrapping the boolean in a SimpleScalar. Also moves the cursor to the beginning of the list.
Parameters:
element - the boolean to be added.

hasNext

public boolean hasNext()
                throws TemplateModelException
Specified by:
hasNext in interface TemplateListModel
Following copied from interface: freemarker.template.TemplateListModel
Returns:
true if there is a next element.

next

public TemplateModel next()
                   throws TemplateModelException
Specified by:
next in interface TemplateListModel
Following copied from interface: freemarker.template.TemplateListModel
Returns:
the next element in the list.

rewind

public void rewind()
            throws TemplateModelException
Description copied from interface: TemplateListModel
Resets the cursor to the beginning of the list.
Specified by:
rewind in interface TemplateListModel

listSize

public TemplateModel listSize()
                       throws TemplateModelException

get

public TemplateModel get(int i)
                  throws TemplateModelException
Specified by:
get in interface TemplateListModel
Following copied from interface: freemarker.template.TemplateListModel
Returns:
the specified index in the list