freemarker.template
Class WrappingTemplateModel

java.lang.Object
  extended by freemarker.template.WrappingTemplateModel
Direct Known 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
protected WrappingTemplateModel()
          Protected constructor that creates a new wrapping template model using the default object wrapper.
protected 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(java.lang.Object obj)
          Wraps the passed object into a template model using this object's object wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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 Configurable.getObjectWrapper() method returns.


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 Configurable.getObjectWrapper() method returns.


getObjectWrapper

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


setObjectWrapper

public void setObjectWrapper(ObjectWrapper objectWrapper)

wrap

protected final TemplateModel wrap(java.lang.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.