freemarker.ext.beans2
Class CollectionWrapper<T extends java.util.Collection>

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

public class CollectionWrapper<T extends java.util.Collection>
extends BeanWrapper<T>
implements TemplateListModel2, TemplateMethodModel2, java.io.Serializable

Since:
1.9
Version:
$Id: CollectionWrapper.java 1164 2005-10-09 11:57:04Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Field Summary
 
Fields inherited from class freemarker.ext.beans2.BeanWrapper
emptyParams, object
 
Constructor Summary
CollectionWrapper()
           
CollectionWrapper(T object)
           
 
Method Summary
 TemplateModel exec(java.util.List<TemplateModel> arguments)
          Tests or sets an object in a Collection.
 void releaseIterator(TemplateIteratorModel iterator)
          Returns the used iterator to the list model.
 TemplateIteratorModel templateIterator()
          Retrieves an iterator to iterate over this collection.
 
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.TemplateModel
isEmpty
 

Constructor Detail

CollectionWrapper

public CollectionWrapper()

CollectionWrapper

public CollectionWrapper(T object)
Method Detail

templateIterator

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

Specified by:
templateIterator in interface TemplateListModel2
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.

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Returns the used iterator to the list model.

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator to be returned

exec

public TemplateModel exec(java.util.List<TemplateModel> arguments)
                   throws TemplateModelException
Tests or sets an object in a Collection. If the number of arguments is one, then a test for object existance is assumed, and we return a FastBoolean for the default unwrapped value of the first argument.

Otherwise, if the second argument is either empty or the boolean value "false", then the object is removed from the collection.

Finally, if the second argument is any other value, then add the object to the collection.

Specified by:
exec in interface TemplateMethodModel2
Parameters:
arguments - a List of TemplateModel objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException