freemarker.ext.beans2
Class Unwrapper

java.lang.Object
  extended by freemarker.ext.beans2.Unwrapper

public class Unwrapper
extends java.lang.Object

Unwraps a given FM-Classic template model back into a plain old Java object. If a target class is supplied, try to convert the model using the most appropriate conversion available. Otherwise, perform a default conversion into a Java object.

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

Method Summary
static java.lang.Object defaultUnwrap(TemplateModel model)
          Convert the supplied template model into a plain old Java object.
static
<T> T
unwrap(TemplateModel model, java.lang.Class<T> target)
          Convert the supplied template model into a plain old Java object of the given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

defaultUnwrap

public static java.lang.Object defaultUnwrap(TemplateModel model)
                                      throws TemplateModelException,
                                             java.lang.ClassCastException,
                                             java.lang.NullPointerException
Convert the supplied template model into a plain old Java object. If the template model is a TemplateObjectModel, unwrap the object back to the underlying object. Otherwise, perform a default conversion to the nearest equivalent Java object.

Parameters:
model - the model to be unwrapped
Returns:
a plain old Java object equivalent to the template model
Throws:
TemplateModelException - there was a problem unwrapping the template model
java.lang.ClassCastException
java.lang.NullPointerException

unwrap

public static <T> T unwrap(TemplateModel model,
                           java.lang.Class<T> target)
                throws TemplateModelException,
                       java.lang.ClassCastException,
                       java.lang.NullPointerException
Convert the supplied template model into a plain old Java object of the given class. Attempt to convert the model to the target class using the best available conversion. The specified target may be a superclass or superinterface of the object ultimately returned.

Parameters:
model - the template model to be unwrapped
target - the target class for the unwrapping
Returns:
a plain old Java object of the given class, equivalent to the template model
Throws:
TemplateModelException - the model could not be converted to the target class
java.lang.ClassCastException
java.lang.NullPointerException