Package freemarker.ext.beans
Class EnumerationModel
- java.lang.Object
-
- freemarker.ext.beans.BeanModel
-
- freemarker.ext.beans.EnumerationModel
-
- All Implemented Interfaces:
WrapperTemplateModel
,AdapterTemplateModel
,TemplateCollectionModel
,TemplateHashModel
,TemplateHashModelEx
,TemplateModel
,TemplateModelIterator
,TemplateModelWithAPISupport
public class EnumerationModel extends BeanModel implements TemplateModelIterator, TemplateCollectionModel
A class that adds
TemplateModelIterator
functionality to theEnumeration
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.
-
-
Field Summary
-
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
-
Constructor Summary
Constructors Constructor Description EnumerationModel(Enumeration enumeration, BeansWrapper wrapper)
Creates a new model that wraps the specified enumeration object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
getAsBoolean()
ReturnsEnumeration.hasMoreElements()
.boolean
hasNext()
Calls underlyingEnumeration.nextElement()
.TemplateModelIterator
iterator()
This allows the enumeration to be used in a <#list> block.TemplateModel
next()
Calls underlyingEnumeration.nextElement()
and wraps the result.-
Methods inherited from class freemarker.ext.beans.BeanModel
get, getAdaptedObject, getAPI, getWrappedObject, hasPlainGetMethod, invokeGenericGet, isEmpty, keys, keySet, size, toString, unwrap, values, wrap
-
-
-
-
Constructor Detail
-
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
- theBeansWrapper
associated with this model. Every model has to have an associatedBeansWrapper
instance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.
-
-
Method Detail
-
iterator
public TemplateModelIterator iterator() throws TemplateModelException
This allows the enumeration to be used in a <#list> block.- Specified by:
iterator
in interfaceTemplateCollectionModel
- Returns:
- "this"
- Throws:
TemplateModelException
-
hasNext
public boolean hasNext()
Calls underlyingEnumeration.nextElement()
.- Specified by:
hasNext
in interfaceTemplateModelIterator
- Returns:
- whether there are any more items to iterate over.
-
next
public TemplateModel next() throws TemplateModelException
Calls underlyingEnumeration.nextElement()
and wraps the result.- Specified by:
next
in interfaceTemplateModelIterator
- Throws:
TemplateModelException
- if the next model can not be retrieved (i.e. because the iterator is exhausted).
-
getAsBoolean
public boolean getAsBoolean()
ReturnsEnumeration.hasMoreElements()
. Therefore, an enumeration that has no more element evaluates to false, and an enumeration that has further elements evaluates to true.
-
-