freemarker.ext.beans
Class ArrayModel

java.lang.Object
  extended by freemarker.ext.beans.ObjectModelBase
      extended by freemarker.ext.beans.ArrayModel
All Implemented Interfaces:
TemplateHashModel, TemplateIndexedModel, TemplateListModel2, TemplateMethodModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel, java.io.Serializable

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

public final class ArrayModel
extends ObjectModelBase
implements TemplateHashModel, TemplateMethodModel2, TemplateIndexedModel, TemplateListModel2

A class that will wrap an arbitrary array into TemplateHashModel, TemplateMethodModel2, TemplateIndexedModel and TemplateListModel2 interfaces.

The models are cached (meaning requesting a model for same object twice will return the same model instance) unless the system property expose.reflection.nocache is set to true.

Apart from supporting retrieval through array[index] syntax and array("index") syntax, it also supports the array.length syntax for retrieving the length of the array. A template can iterate over the array directly using the <list> or <foreach> syntax.

The array.iterator syntax for retrieving a TemplateListModel2 interface backed by this array is supported for backward compatibility with earlier releases.

Using the model as a list model is thread-safe, as it maintains the list position on a per-iterator basis using the new TemplateListModel2 interface.

Version:
$Id: ArrayModel.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
ArrayModel(java.lang.Object array)
          Deprecated. Creates a new model that wraps the specified array object.
 
Method Summary
 TemplateModel exec(java.util.List<TemplateModel> arguments)
          Deprecated. The first argument of the list is interpreted as an array index (it can be either a Number, or a String containing parseable integer).
 TemplateModel get(java.lang.String key)
          Deprecated. If the key can be parsed by the java.lang.Integer#parseInt(java.lang.String) method into an array index, the array element at the parsed index is returned.
 TemplateModel getAtIndex(long index)
          Deprecated. Retrive the object at the specified index.
static ArrayModel getInstance(java.lang.Object object)
          Deprecated. Returns a model wrapping the specified array object.
 freemarker.ext.beans.ObjectModelBase.ModelType getType()
          Deprecated. Returns the type of this object (which is TYPE_ARRAY)
 boolean isEmpty()
          Deprecated. Returns true if the wrapped array is null, or its length is 0.
 void releaseIterator(TemplateIteratorModel iterator)
          Deprecated. Return the iterator to the object pool, if any.
 TemplateIteratorModel templateIterator()
          Deprecated. Retrieve an iterator over this array.
 
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

ArrayModel

public ArrayModel(java.lang.Object array)
Deprecated. 
Creates a new model that wraps the specified array object.

Parameters:
array - the array object to wrap into a model.
Throws:
java.lang.IllegalArgumentException - if the passed object is not a Java array.
Method Detail

getInstance

public static final ArrayModel getInstance(java.lang.Object object)
Deprecated. 
Returns a model wrapping the specified array object. If there is already a cached model instance for this array, 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 array to wrap into a model.
Returns:
the model for the array
Throws:
java.lang.IllegalArgumentException - if the passed object is not a Java array.

getType

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

Overrides:
getType in class ObjectModelBase

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Deprecated. 
If the key can be parsed by the java.lang.Integer#parseInt(java.lang.String) method into an array index, the array element at the parsed index is returned. If the key is named "length", the length of the array is returned.

Specified by:
get in interface TemplateHashModel
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 - there was a problem getting the value for the given key

exec

public TemplateModel exec(java.util.List<TemplateModel> arguments)
                   throws TemplateModelException
Deprecated. 
The first argument of the list is interpreted as an array index (it can be either a Number, or a String containing parseable integer). The element at the specified index is returned.

Specified by:
exec in interface TemplateMethodModel2
Parameters:
arguments - a List of TemplateModel objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException

getAtIndex

public TemplateModel getAtIndex(long index)
                         throws TemplateModelException
Deprecated. 
Retrive the object at the specified index.

Specified by:
getAtIndex in interface TemplateIndexedModel
Parameters:
index - the index of the object to be retrieved
Returns:
a TemplateModel wrapping the underlying value of the object
Throws:
TemplateModelException - the value could not be determined, possibly due to an index out-of-bounds, or an otherwise undefined value

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Deprecated. 
Retrieve an iterator over this array.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
an iterator over the array, or null if the array is empty
Throws:
TemplateModelException

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Deprecated. 
Return the iterator to the object pool, if any.

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

isEmpty

public boolean isEmpty()
Deprecated. 
Returns true if the wrapped array is null, or its length is 0.

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