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.IterableWrapper<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 IterableWrapper<T>
implements TemplateListModel2, TemplateMethodModel2, java.io.Serializable

Wraps Collection objects by providing additional methods to support list models and method support for getting and setting values. Also a base class for ListWrapper.

Since:
1.9
Version:
$Id: CollectionWrapper.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
CollectionWrapper()
          Default constructor where an object is not provided initially.
CollectionWrapper(T object)
          Constructor that takes a Collection object to be wrapped.
 
Method Summary
 TemplateModel exec(java.util.List<TemplateModel> arguments)
          Tests or sets an object in a Collection.
 
Methods inherited from class freemarker.ext.beans2.IterableWrapper
releaseIterator, templateIterator
 
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.TemplateListModel2
releaseIterator, templateIterator
 
Methods inherited from interface freemarker.template.TemplateModel
isEmpty
 

Constructor Detail

CollectionWrapper

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


CollectionWrapper

public CollectionWrapper(T object)
Constructor that takes a Collection object to be wrapped.

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

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