freemarker.ext.beans2
Interface Converter

All Known Implementing Classes:
ConvertToArray, ConvertToArrayList, ConvertToBigDecimal, ConvertToBigInteger, ConvertToBool, ConvertToBoolArray, ConvertToByte, ConvertToDouble, ConvertToFloat, ConvertToHashSet, ConvertToIntArray, ConvertToInteger, ConvertToLinkedList, ConvertToLong, ConvertToObject, ConvertToObjectArray, ConvertToShort, ConvertToString, ConvertToTreeSet, ConvertToVector

public interface Converter

An interface for classes implementing a conversion from a given TemplateModel to a known Java object. Conversions should be context free, and implementing classes should be flywheel classes, ie. not carrying any internal state between calls. They may also be singletons.

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

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.
 

Method Detail

convert

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

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.IllegalArgumentException - the template model was of the wrong type for this converter
java.lang.NullPointerException - the template model is null
TemplateModelException - there was an error while retrieving a value from the template model

converts

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. The specified target may be a superclass or superinterface of the object ultimately returned.

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