Package 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
andPyStringMap
). Note that the basicJythonModel
already provides access to thePyObject.__finditem__(String)
method. This class only addsTemplateHashModelEx
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 theget()
method works for attributes as well. However, in practice when you ask fordict?keys
inside a template, you'll really want to retrieve only items, not attributes so this is considered OK.
-
-
Field Summary
-
Fields inherited from class freemarker.ext.jython.JythonModel
object, wrapper
-
Fields inherited from interface freemarker.template.TemplateBooleanModel
FALSE, TRUE
-
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Fields inherited from interface freemarker.template.TemplateScalarModel
EMPTY_STRING
-
-
Constructor Summary
Constructors Constructor Description JythonHashModel(org.python.core.PyObject object, JythonWrapper wrapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TemplateCollectionModel
keys()
Returns eitherobject.__findattr__("keys").__call__()
orobject.__findattr__("keySet").__call__()
.int
size()
ReturnsPyObject.__len__()
.TemplateCollectionModel
values()
Returnsobject.__findattr__("values").__call__()
.-
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
ReturnsPyObject.__len__()
.- Specified by:
size
in interfaceTemplateHashModelEx
- Returns:
- the number of key/value mappings in the hash.
- Throws:
TemplateModelException
-
keys
public TemplateCollectionModel keys() throws TemplateModelException
Returns eitherobject.__findattr__("keys").__call__()
orobject.__findattr__("keySet").__call__()
.- Specified by:
keys
in interfaceTemplateHashModelEx
- 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
Returnsobject.__findattr__("values").__call__()
.- Specified by:
values
in interfaceTemplateHashModelEx
- Returns:
- a collection containing the values in the hash. The elements of the
returned collection can be any kind of
TemplateModel
-s. - Throws:
TemplateModelException
-
-