freemarker.ext.beans2
Class ConvertToArray

java.lang.Object
  extended by freemarker.ext.beans2.ConvertToArray
All Implemented Interfaces:
Converter

public class ConvertToArray
extends java.lang.Object
implements Converter

Returns an array of the specified type for a given list model.

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

Constructor Summary
ConvertToArray(java.lang.Class<?> clazz)
          Constructor that takes the target class for items in the array.
 
Method Summary
 java.lang.Object convert(TemplateModel model)
          Convert the given template model into the target object type represented by this converter.
 boolean converts(TemplateModel model, java.lang.Class<?> target)
          Determines whether this converter can convert from the given template model into an instance of the given class target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConvertToArray

public ConvertToArray(java.lang.Class<?> clazz)
Constructor that takes the target class for items in the array.

Parameters:
clazz - the target class for each item in the array
Method Detail

convert

public java.lang.Object convert(TemplateModel model)
                         throws java.lang.ClassCastException,
                                java.lang.NullPointerException,
                                TemplateModelException
Description copied from interface: Converter
Convert the given template model into the target object type represented by this converter. Callers of this method should first call Converter.converts(freemarker.template.TemplateModel, java.lang.Class) to determine whether this converter can perform the requested conversion.

Specified by:
convert in interface Converter
Parameters:
model - the template model to be converted
Returns:
the converted template model to the target object type represented by this converter
Throws:
java.lang.NullPointerException - the template model is null
TemplateModelException - there was an error while retrieving a value from the template model
java.lang.ClassCastException

converts

public boolean converts(TemplateModel model,
                        java.lang.Class<?> target)
Description copied from interface: Converter
Determines whether this converter can convert from the given template model into an instance of the given class target. The specified target may be a superclass or superinterface of the object ultimately returned.

Specified by:
converts in interface Converter
Parameters:
model - the template model to be converted
target - the target class for the conversion
Returns:
true if this converter can convert the given template model to an instance of the target class, otherwise false