freemarker.template
Class SimpleList

java.lang.Object
  |
  +--freemarker.template.SimpleList

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(TemplateListModel listToCopy)
          Constructs a SimpleList, copying into it the values from another TemplateListModel.
 
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.
 int getShelfLife()
           
 boolean hasNext()
           
 boolean isEmpty()
           
 boolean isPermanent()
           
 boolean isRewound()
           
 boolean isStale()
           
 TemplateModel next()
           
 void rewind()
           
 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(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

isRewound

public boolean isRewound()
                  throws TemplateModelException
Specified by:
isRewound in interface TemplateListModel

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

next

public TemplateModel next()
                   throws TemplateModelException
Specified by:
next in interface TemplateListModel

rewind

public void rewind()
            throws TemplateModelException
Specified by:
rewind in interface TemplateListModel