freemarker.ext.beans
Class CollectionModel

java.lang.Object
  extended by freemarker.ext.beans.ObjectModelBase
      extended by freemarker.ext.beans.ObjectModel
          extended by freemarker.ext.beans.CollectionModel
All Implemented Interfaces:
TemplateHashModel, TemplateListModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel, java.io.Serializable
Direct Known Subclasses:
ListModel

Deprecated. this class is deprecated in favour of the classes in the freemarker.ext.beans2 package

public class CollectionModel
extends ObjectModel
implements TemplateListModel2

A special case of ObjectModel that supports the collection.iterator syntax to obtain a TemplateListModel2 instance backed by this collection.

The class itself also implements TemplateListModel2 directly, since this model preserves thread safety.

Version:
$Id: CollectionModel.java 1101 2013-04-01 04:17:32Z run2000 $
Author:
Attila Szegedi, attila@szegedi.org
See Also:
Serialized Form

Field Summary
 
Fields inherited from class freemarker.ext.beans.ObjectModelBase
object
 
Constructor Summary
CollectionModel(java.util.Collection collection)
          Deprecated. Creates a new model that wraps the specified collection object.
 
Method Summary
 TemplateModel get(java.lang.String key)
          Deprecated. Uses Beans introspection to locate a property or method with name matching the key name.
static CollectionModel getInstance(java.util.Collection object)
          Deprecated. Returns a model wrapping the specified collection object.
 freemarker.ext.beans.ObjectModelBase.ModelType getType()
          Deprecated. Returns the type of this object (which is TYPE_COLLECTION)
 boolean isEmpty()
          Deprecated. Returns true if the underlying collection contains no elements.
 void releaseIterator(TemplateIteratorModel iterator)
          Deprecated. Release the iterator once we've finished with it
 TemplateIteratorModel templateIterator()
          Deprecated. Retrive an iterator for this Collection.
 
Methods inherited from class freemarker.ext.beans.ObjectModel
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

CollectionModel

public CollectionModel(java.util.Collection collection)
Deprecated. 
Creates a new model that wraps the specified collection object.

Parameters:
collection - the collection object to wrap into a model.
Method Detail

getInstance

public static final CollectionModel getInstance(java.util.Collection object)
Deprecated. 
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

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Deprecated. 
Description copied from class: ObjectModel
Uses Beans introspection to locate a property or method with name matching the key name. If a method or property is found, it is wrapped into MethodModel or ScalarModel instance and returned. Models for various properties and methods are cached on a per-class basis, so the costly introspection is performed only once per property or method of a class. (Sidenote: this also implies that any class whose method has been called will be strongly referred to by the framework and will not become unloadable until this class has been unloaded first. Normally this is not an issue, but can be in a rare scenario where you create many classes on the fly. Also, as the cache grows with new classes and methods introduced to the framework, it may appear as if it were leaking memory.) If no method or propery matching the key is found, the framework will try to invoke methods with signature get(java.lang.String), then get(java.lang.Object).

Specified by:
get in interface TemplateHashModel
Overrides:
get in class ObjectModel
Parameters:
key - the name by which the TemplateModel is identified in the template.
Returns:
the TemplateModel referred to by the key, or null if not found.
Throws:
TemplateModelException - if there was no property nor method nor a generic get method to invoke.

getType

public freemarker.ext.beans.ObjectModelBase.ModelType getType()
Deprecated. 
Returns the type of this object (which is TYPE_COLLECTION)

Overrides:
getType in class ObjectModel

isEmpty

public boolean isEmpty()
Deprecated. 
Returns true if the underlying collection contains no elements.

Specified by:
isEmpty in interface TemplateModel
Overrides:
isEmpty in class ObjectModelBase
Returns:
true if this object is empty, otherwise false

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Deprecated. 
Retrive an iterator for this Collection.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
a TemplateIteratorModel wrapping the underlying java.util.Iterator implementation
Throws:
TemplateModelException - the next item in the list can't be retrieved, or no next item exists.

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Deprecated. 
Release the iterator once we've finished with it

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator model to be released