org.szegedi.expose.model
Class ReflectionEnumerationModel

java.lang.Object
  |
  +--org.szegedi.expose.model.ReflectionObjectModelBase
        |
        +--org.szegedi.expose.model.ReflectionObjectModel
              |
              +--org.szegedi.expose.model.ReflectionEnumerationModel
All Implemented Interfaces:
freemarker.template.TemplateHashModel, freemarker.template.TemplateListModel, freemarker.template.TemplateModel, freemarker.template.TemplateScalarModel

public final class ReflectionEnumerationModel
extends ReflectionObjectModel
implements freemarker.template.TemplateListModel

A class that adds TemplateListModel functionality to the Iterator interface implementers. Using the model as a list model is NOT thread-safe, as the enumerations are inherently not thread-safe.

Version:
1.0
Author:
Attila Szegedi, attila@szegedi.org

Fields inherited from class org.szegedi.expose.model.ReflectionObjectModelBase
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
ReflectionEnumerationModel(java.util.Enumeration enumeration)
          Creates a new model that wraps the specified enumeration object.
 
Method Summary
 freemarker.template.TemplateModel get(int index)
          Throws an UnsupportedOperationException as enumeration elements can not be accessed at random.
static ReflectionEnumerationModel 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 hasNext()
          Calls Iterator.hasNext().
 boolean isEmpty()
          Returns enumeration == null || !
 boolean isRewound()
          True if the iterator's next method has not been called since last rewind, or since the object creation.
 freemarker.template.TemplateModel listSize()
          Throws an UnsupportedOperationException as enumeration size is unknown
 freemarker.template.TemplateModel next()
          Calls Iterator.next().
 void rewind()
          Throws an UnsupportedOperationException as enumeration cannot be rewound
 
Methods inherited from class org.szegedi.expose.model.ReflectionObjectModel
get, getInstance
 
Methods inherited from class org.szegedi.expose.model.ReflectionObjectModelBase
getAsString, getInstance, getObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionEnumerationModel

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

getInstance

public static final ReflectionEnumerationModel getInstance(java.util.Enumeration object)
Returns a model wrapping the specified enumeration object. If there is already a cached model instance for this enumeration, returns the cached model instance. Models are cached using WeakReference objects. The caching can be turned off by setting the expose.reflection.nocache system property to true. In this case calling this method is equivalent to constructing a new model.
Parameters:
object - the enumeration to wrap into a model.
Returns:
the model for the enumeration

getType

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

hasNext

public boolean hasNext()
Calls Iterator.hasNext().
Specified by:
hasNext in interface freemarker.template.TemplateListModel

isRewound

public boolean isRewound()
True if the iterator's next method has not been called since last rewind, or since the object creation.
Specified by:
isRewound in interface freemarker.template.TemplateListModel

next

public freemarker.template.TemplateModel next()
Calls Iterator.next().
Specified by:
next in interface freemarker.template.TemplateListModel

rewind

public void rewind()
Throws an UnsupportedOperationException as enumeration cannot be rewound
Specified by:
rewind in interface freemarker.template.TemplateListModel

listSize

public freemarker.template.TemplateModel listSize()
Throws an UnsupportedOperationException as enumeration size is unknown

get

public freemarker.template.TemplateModel get(int index)
Throws an UnsupportedOperationException as enumeration elements can not be accessed at random.

isEmpty

public boolean isEmpty()
Returns enumeration == null || !enumeration.hasMoreElements()
Specified by:
isEmpty in interface freemarker.template.TemplateModel
Overrides:
isEmpty in class ReflectionObjectModelBase