freemarker.ext.jython
Class JythonHashModel

java.lang.Object
  extended by freemarker.ext.jython.JythonModel
      extended by freemarker.ext.jython.JythonHashModel
All Implemented Interfaces:
WrapperTemplateModel, AdapterTemplateModel, TemplateBooleanModel, TemplateHashModel, TemplateHashModelEx, TemplateMethodModel, TemplateMethodModelEx, TemplateModel, TemplateScalarModel

public class JythonHashModel
extends JythonModel
implements TemplateHashModelEx

Model for Jython dictionaries (PyDictionary and PyStringMap). Note that the basic JythonModel already provides access to the PyObject.__finditem__(String) method. This class only adds TemplateHashModelEx functionality in a somewhat skewed way. One could say it even violates TemplateHashModelEx semantics, as both the returned keys and values are only those from the item mapping, while the get() method works for attributes as well. However, in practice when you ask for dict?keys inside a template, you'll really want to retrieve only items, not attributes so this is considered OK.

Version:
$Id: JythonHashModel.java,v 1.14 2003/11/12 21:53:40 ddekany Exp $
Author:
Attila Szegedi

Field Summary
 
Fields inherited from class freemarker.ext.jython.JythonModel
object, wrapper
 
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
 
Fields inherited from interface freemarker.template.TemplateBooleanModel
FALSE, TRUE
 
Fields inherited from interface freemarker.template.TemplateScalarModel
EMPTY_STRING
 
Constructor Summary
JythonHashModel(org.python.core.PyObject object, JythonWrapper wrapper)
           
 
Method Summary
 TemplateCollectionModel keys()
          Returns either object.
 int size()
          Returns PyObject.__len__().
 TemplateCollectionModel values()
          Returns object.
 
Methods inherited from class freemarker.ext.jython.JythonModel
exec, get, getAdaptedObject, getAsBoolean, getAsString, getWrappedObject, isEmpty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemarker.template.TemplateHashModel
get, isEmpty
 

Constructor Detail

JythonHashModel

public JythonHashModel(org.python.core.PyObject object,
                       JythonWrapper wrapper)
Method Detail

size

public int size()
         throws TemplateModelException
Returns PyObject.__len__().

Specified by:
size in interface TemplateHashModelEx
Returns:
the number of key/value mappings in the hash.
Throws:
TemplateModelException

keys

public TemplateCollectionModel keys()
                             throws TemplateModelException
Returns either object.__findattr__("keys").__call__() or object.__findattr__("keySet").__call__().

Specified by:
keys in interface TemplateHashModelEx
Returns:
a collection containing the keys in the hash. Every element of the returned collection must implement the TemplateScalarModel (as the keys of hashes are always strings).
Throws:
TemplateModelException

values

public TemplateCollectionModel values()
                               throws TemplateModelException
Returns object.__findattr__("values").__call__().

Specified by:
values in interface TemplateHashModelEx
Returns:
a collection containing the values in the hash.
Throws:
TemplateModelException