freemarker.ext.beans

Class EnumerationModel

Implemented Interfaces:
AdapterTemplateModel, TemplateCollectionModel, TemplateHashModel, TemplateHashModelEx, TemplateModel, TemplateModelIterator, WrapperTemplateModel

public class EnumerationModel
extends BeanModel
implements TemplateModelIterator, TemplateCollectionModel

A class that adds TemplateModelIterator functionality to the Enumeration interface implementers.

Using the model as a collection model is NOT thread-safe, as enumerations are inherently not thread-safe. Further, you can iterate over it only once. Attempts to call the iterator() method after it was already driven to the end once will throw an exception.

Version:
$Id: EnumerationModel.java,v 1.24 2003/06/03 13:21:32 szegedia Exp $
Author:
Attila Szegedi

Field Summary

Fields inherited from class freemarker.ext.beans.BeanModel

object, wrapper

Fields inherited from interface freemarker.template.TemplateModel

NOTHING

Constructor Summary

EnumerationModel(Enumeration enumeration, BeansWrapper wrapper)
Creates a new model that wraps the specified enumeration object.

Method Summary

boolean
getAsBoolean()
Returns Enumeration.hasMoreElements().
boolean
hasNext()
Calls underlying Enumeration.nextElement().
TemplateModelIterator
iterator()
This allows the enumeration to be used in a <foreach> block.
TemplateModel
next()
Calls underlying Enumeration.nextElement() and wraps the result.

Methods inherited from class freemarker.ext.beans.BeanModel

get, getAdaptedObject, getWrappedObject, hasPlainGetMethod, invokeGenericGet, isEmpty, keySet, keys, size, toString, unwrap, values, wrap

Constructor Details

EnumerationModel

public EnumerationModel(Enumeration enumeration,
                        BeansWrapper wrapper)
Creates a new model that wraps the specified enumeration object.
Parameters:
enumeration - the enumeration object to wrap into a model.
wrapper - the BeansWrapper associated with this model. Every model has to have an associated BeansWrapper instance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.

Method Details

getAsBoolean

public boolean getAsBoolean()
Returns Enumeration.hasMoreElements(). Therefore, an enumeration that has no more element evaluates to false, and an enumeration that has further elements evaluates to true.

hasNext

public boolean hasNext()
Calls underlying Enumeration.nextElement().
Specified by:
hasNext in interface TemplateModelIterator

iterator

public TemplateModelIterator iterator()
            throws TemplateModelException
This allows the enumeration to be used in a <foreach> block.
Specified by:
iterator in interface TemplateCollectionModel
Returns:
"this"

next

public TemplateModel next()
            throws TemplateModelException
Calls underlying Enumeration.nextElement() and wraps the result.
Specified by:
next in interface TemplateModelIterator