freemarker.ext.beans
Class EnumerationModel

java.lang.Object
  |
  +--freemarker.ext.beans.ObjectModelBase
        |
        +--freemarker.ext.beans.ObjectModel
              |
              +--freemarker.ext.beans.EnumerationModel
All Implemented Interfaces:
TemplateHashModel, TemplateListModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel

public final class EnumerationModel
extends ObjectModel
implements TemplateListModel2

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

Using the model as a list model is NOT thread-safe, as enumerations are inherently not thread-safe.

Version:
$Id: EnumerationModel.java,v 1.5 2003/11/26 05:53:48 run2000 Exp $
Author:
Attila Szegedi, attila@szegedi.org

Fields inherited from class freemarker.ext.beans.ObjectModelBase
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_LIST, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
EnumerationModel(java.util.Enumeration enumeration)
          Creates a new model that wraps the specified enumeration object.
 
Method Summary
static EnumerationModel getInstance(java.util.Enumeration object)
          Returns a model wrapping the specified enumeration object.
 int getType()
          Returns the type of this object (which is TYPE_ENUMERATION).
 boolean isEmpty()
          Returns true if the enumeration is null or the enumeration has no more elements, otherwise false.
 void releaseIterator(TemplateIteratorModel iterator)
          Release the underlying enumerator, so that we don't try to walk over it again
 TemplateIteratorModel templateIterator()
          Retrieve a TemplateIteratorModel for this enumeration.
 
Methods inherited from class freemarker.ext.beans.ObjectModel
get, getInstance
 
Methods inherited from class freemarker.ext.beans.ObjectModelBase
getAsObject, getAsString, getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumerationModel

public EnumerationModel(java.util.Enumeration enumeration)
Creates a new model that wraps the specified enumeration object.
Parameters:
enumeration - the enumeration object to wrap into a model.
Method Detail

isEmpty

public boolean isEmpty()
Returns true if the enumeration is null or the enumeration has no more elements, otherwise false.
Specified by:
isEmpty in interface TemplateModel
Overrides:
isEmpty in class ObjectModelBase
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty, otherwise false

getInstance

public static final EnumerationModel getInstance(java.util.Enumeration object)
Returns a model wrapping the specified enumeration object. It always returns a new object, as Enumerations are considered short-lived and caching them would make little sense.
Returns:
the model for the enumeration

getType

public int getType()
Returns the type of this object (which is TYPE_ENUMERATION).
Overrides:
getType in class ObjectModel

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Retrieve a TemplateIteratorModel for this enumeration.
Specified by:
templateIterator in interface TemplateListModel2
Returns:
the iterator model for walking over this enumeration
Throws:
TemplateModelException - the enumeration has already been spent

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Release the underlying enumerator, so that we don't try to walk over it again
Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator that just walked over the enumeration