freemarker.template

Class WrappingTemplateModel

Known Direct Subclasses:
SimpleCollection, SimpleHash, SimpleMapModel, SimpleSequence

public abstract class WrappingTemplateModel
extends java.lang.Object

A base class for containers that wrap arbitrary Java objects into TemplateModel instances.
Version:
$Id: WrappingTemplateModel.java,v 1.18.2.1 2005/12/07 00:41:23 revusky Exp $

Constructor Summary

WrappingTemplateModel()
Protected constructor that creates a new wrapping template model using the default object wrapper.
WrappingTemplateModel(ObjectWrapper objectWrapper)
Protected constructor that creates a new wrapping template model using the specified object wrapper.

Method Summary

static ObjectWrapper
getDefaultObjectWrapper()
Returns the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper.
ObjectWrapper
getObjectWrapper()
Returns the object wrapper instance used by this wrapping template model.
static void
setDefaultObjectWrapper(ObjectWrapper objectWrapper)
Sets the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper.
void
setObjectWrapper(ObjectWrapper objectWrapper)
protected TemplateModel
wrap(Object obj)
Wraps the passed object into a template model using this object's object wrapper.

Constructor Details

WrappingTemplateModel

protected WrappingTemplateModel()
Protected constructor that creates a new wrapping template model using the default object wrapper.

WrappingTemplateModel

protected WrappingTemplateModel(ObjectWrapper objectWrapper)
Protected constructor that creates a new wrapping template model using the specified object wrapper.
Parameters:
objectWrapper - the wrapper to use. If null is passed, the default object wrapper is used.

Method Details

getDefaultObjectWrapper

public static ObjectWrapper getDefaultObjectWrapper()
Returns the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper. Note that Configuration.setSharedVariable(String,Object) and Template.process(Object, java.io.Writer) don't use this setting, they rather use whatever object wrapper their Configuration.getObjectWrapper() method returns.

getObjectWrapper

public ObjectWrapper getObjectWrapper()
Returns the object wrapper instance used by this wrapping template model.

setDefaultObjectWrapper

public static void setDefaultObjectWrapper(ObjectWrapper objectWrapper)
Sets the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper. The default value is ObjectWrapper.SIMPLE_WRAPPER. Note that Configuration.setSharedVariable(String,Object) and Template.process(Object, java.io.Writer) don't use this setting, they rather use whatever object wrapper their Configuration.getObjectWrapper() method returns.

setObjectWrapper

public void setObjectWrapper(ObjectWrapper objectWrapper)

wrap

protected final TemplateModel wrap(Object obj)
            throws TemplateModelException
Wraps the passed object into a template model using this object's object wrapper.
Parameters:
obj - the object to wrap
Returns:
the template model that wraps the object
Throws:
TemplateModelException - if the wrapper does not know how to wrap the passed object.