freemarker.ext.beans
Class MapModel

java.lang.Object
  |
  +--freemarker.ext.beans.ObjectModelBase
        |
        +--freemarker.ext.beans.ObjectModel
              |
              +--freemarker.ext.beans.MapModel
All Implemented Interfaces:
TemplateHashModel, TemplateMethodModel2, TemplateModel, TemplateObjectModel, TemplateScalarModel

public class MapModel
extends ObjectModel
implements TemplateMethodModel2

A special case of ObjectModel that adds implementation for TemplateMethodModel2 on map objects that is a shortcut for the Map.get() method.

You can use map.entrySet, map.keySet, or map.values to obtain TemplateListModel2 instances for various aspects of the map.

Version:
$Id: MapModel.java,v 1.4 2003/10/20 13:49:02 run2000 Exp $
Author:
Attila Szegedi, attila@szegedi.org

Fields inherited from class freemarker.ext.beans.ObjectModelBase
TYPE_ARRAY, TYPE_COLLECTION, TYPE_ENUMERATION, TYPE_ITERATOR, TYPE_LIST, TYPE_MAP, TYPE_OBJECT, TYPE_OBJECT_BASE, TYPE_RESOURCE_BUNDLE
 
Constructor Summary
MapModel(java.util.Map map)
          Creates a new model that wraps the specified map object.
 
Method Summary
 TemplateModel exec(java.util.List arguments)
          The first argument is used as a key to call the map's get method.
static MapModel getInstance(java.util.Map object)
          Returns a model wrapping the specified map object.
 int getType()
          Returns the type of this object (which is TYPE_MAP)
 boolean isEmpty()
          Returns true if the underlying map is empty.
 
Methods inherited from class freemarker.ext.beans.ObjectModel
get, getInstance
 
Methods inherited from class freemarker.ext.beans.ObjectModelBase
getAsObject, getAsString, getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapModel

public MapModel(java.util.Map map)
Creates a new model that wraps the specified map object.
Parameters:
map - the map object to wrap into a model.
Method Detail

getInstance

public static final MapModel getInstance(java.util.Map object)
Returns a model wrapping the specified map object. If there is already a cached model instance for this map, returns the cached model instance. Models are cached using WeakReference objects. The caching can be turned off by setting the expose.reflection.nocache system property to true. In this case calling this method is equivalent to constructing a new model.
Parameters:
object - the map to wrap into a model.
Returns:
the model for the map

getType

public int getType()
Returns the type of this object (which is TYPE_MAP)
Overrides:
getType in class ObjectModel

exec

public TemplateModel exec(java.util.List arguments)
                   throws TemplateModelException
The first argument is used as a key to call the map's get method.
Specified by:
exec in interface TemplateMethodModel2
Following copied from interface: freemarker.template.TemplateMethodModel2
Parameters:
arguments - a List of TemplateModel objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.

isEmpty

public boolean isEmpty()
Returns true if the underlying map is empty.
Specified by:
isEmpty in interface TemplateModel
Overrides:
isEmpty in class ObjectModelBase
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty, otherwise false