org.szegedi.expose.model
Class ReflectionCollectionModel

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

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

A special case of ReflectionObjectModel that adds implementation for TemplateListModel on collection objects. Using the model as a list model is thread-safe, as it maintains an iterator on a per-thread basis.

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
ReflectionCollectionModel(java.util.Collection collection)
          Creates a new model that wraps the specified collection object.
 
Method Summary
 freemarker.template.TemplateModel get(int index)
          If the contained collection is a list, returns its element by position, wrapped into appropriate template model.
static ReflectionCollectionModel getInstance(java.util.Collection object)
          Returns a model wrapping the specified collection object.
 int getType()
          Returns the type of this object (which is TYPE_COLLECTION)
 boolean hasNext()
          Calls Iterator.hasNext().
 boolean isEmpty()
          Returns true if the underlying collection contains no elements.
 boolean isRewound()
          Always return false to force calling rewind.
 freemarker.template.TemplateModel listSize()
          Returns a Simple scalar with a string containing the decimal representation of the array size.
 freemarker.template.TemplateModel next()
          Calls Iterator.next().
 void rewind()
          Creates a new iterator on the collection that will be used to implement other TemplateListModel methods.
 
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

ReflectionCollectionModel

public ReflectionCollectionModel(java.util.Collection collection)
Creates a new model that wraps the specified collection object.
Parameters:
object - the collection object to wrap into a model.
Method Detail

getInstance

public static final ReflectionCollectionModel getInstance(java.util.Collection object)
Returns a model wrapping the specified collection object. If there is already a cached model instance for this collection, 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 collection to wrap into a model.
Returns:
the model for the collection

getType

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

hasNext

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

isRewound

public boolean isRewound()
Always return false to force calling rewind.
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()
Creates a new iterator on the collection that will be used to implement other TemplateListModel methods.
Specified by:
rewind in interface freemarker.template.TemplateListModel

get

public freemarker.template.TemplateModel get(int index)
If the contained collection is a list, returns its element by position, wrapped into appropriate template model. Otherwise, an UnsupportedOperationException is thrown.

listSize

public freemarker.template.TemplateModel listSize()
Returns a Simple scalar with a string containing the decimal representation of the array size.

isEmpty

public boolean isEmpty()
Returns true if the underlying collection contains no elements.
Specified by:
isEmpty in interface freemarker.template.TemplateModel
Overrides:
isEmpty in class ReflectionObjectModelBase