freemarker.ext.jython
Class JythonHashModel
java.lang.Object
freemarker.ext.jython.JythonModel
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JythonHashModel
public JythonHashModel(org.python.core.PyObject object,
JythonWrapper wrapper)
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