freemarker.ext.beans2
Class IndexedPropertyWrapper

java.lang.Object
  extended by freemarker.ext.beans2.IndexedPropertyWrapper
All Implemented Interfaces:
TemplateHashModel, TemplateIndexedModel, TemplateListModel2, TemplateModel, TemplateObjectModel, TemplateWriteableIndexedModel

public class IndexedPropertyWrapper
extends java.lang.Object
implements TemplateListModel2, TemplateWriteableIndexedModel, TemplateHashModel, TemplateObjectModel

Wrapper for an indexed property of a JavaBean.

Since:
1.9
Version:
$Id: IndexedPropertyWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull

Constructor Summary
IndexedPropertyWrapper(java.lang.Object object, java.beans.IndexedPropertyDescriptor ipd)
          Constructor that takes an indexed property descriptor and a target object on which it will be invoked.
 
Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 java.lang.Object getAsObject()
          Return the underlying object to the reflection mechanism.
 TemplateModel getAtIndex(long index)
          Get the value corresponding to the given index.
 boolean isEmpty()
          Is the object empty?
 void putAtIndex(long index, TemplateModel model)
          Set the value corresponding to the given index.
 void releaseIterator(TemplateIteratorModel iterator)
          Returns the used iterator to the list model.
 TemplateIteratorModel templateIterator()
          Retrieves an iterator to iterate over this list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexedPropertyWrapper

public IndexedPropertyWrapper(java.lang.Object object,
                              java.beans.IndexedPropertyDescriptor ipd)
Constructor that takes an indexed property descriptor and a target object on which it will be invoked.

Parameters:
object - the object on which the indexed property will be called
ipd - the descriptor for the indexed property
Method Detail

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

getAtIndex

public TemplateModel getAtIndex(long index)
                         throws TemplateModelException
Description copied from interface: TemplateIndexedModel
Get the value corresponding to the given index. Traditionally this would correspond to an index into an array, or similar structure, such as a java.util.Vector.

Specified by:
getAtIndex in interface TemplateIndexedModel
Parameters:
index - the index of the underlying value we're interested in
Returns:
a TemplateModel representing the value for the given index
Throws:
TemplateModelException - the value could not be determined, possibly due to an index out-of-bounds, or an otherwise undefined value

putAtIndex

public void putAtIndex(long index,
                       TemplateModel model)
                throws TemplateModelException
Description copied from interface: TemplateWriteableIndexedModel
Set the value corresponding to the given index. Traditionally this would correspond to an index into an array, or similar structure, such as a java.util.Vector.

Specified by:
putAtIndex in interface TemplateWriteableIndexedModel
Parameters:
index - the index of the underlying value we're interested in
model - the TemplateModel to be added to the list for the given index
Throws:
TemplateModelException - the value could not be set, possibly due to an index out-of-bounds, or some other error

templateIterator

public TemplateIteratorModel templateIterator()
                                       throws TemplateModelException
Description copied from interface: TemplateListModel2
Retrieves an iterator to iterate over this list. Can choose to return null if there are no elements in the list.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
an iterator to iterate over the current list.
Throws:
TemplateModelException - the next item in the list can't be retrieved, or no next item exists.

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Description copied from interface: TemplateListModel2

Returns the used iterator to the list model. Implement this method when you want to use an object pool of TemplateIterator objects. Otherwise, leave the implementation of this method blank.

Note that if the iterator returned in TemplateListModel2.templateIterator() is null, this method will not be called for the null iterator.

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator to be returned to the object pool, if any

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Gets a TemplateModel from the hash.

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

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Return the underlying object to the reflection mechanism. Any variables, methods or properties can be called directly via reflection.

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
the underlying object for this template model
Throws:
TemplateModelException - the object could not be returned