Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
freemarker.ext.jython.JythonWrapper
Field Summary | |
static JythonWrapper |
Fields inherited from interface freemarker.template.ObjectWrapper | |
BEANS_WRAPPER , DEFAULT_WRAPPER , SIMPLE_WRAPPER |
Constructor Summary | |
Method Summary | |
void |
|
void |
|
PyObject |
|
TemplateModel |
|
public void setAttributesShadowItems(boolean attributesShadowItems)
Sets whether attributes shadow items in wrapped objects. When true (this is the default value),${object.name}
will first try to locate a python attribute with the specified name on the object usingPyObject.__findattr__(java.lang.String)
, and only if it doesn't find the attribute will it callPyObject.__getitem__(org.python.core.PyObject)
. When set to false, the lookup order is reversed and items are looked up before attributes.
public void setUseCache(boolean useCache)
Sets whether this wrapper caches model instances. Default is false. When set to true, callingwrap(Object)
multiple times for the same object will return the same model.
public PyObject unwrap(TemplateModel model) throws TemplateModelException
Coerces a template model into aPyObject
.
- Parameters:
model
- the model to coerce
- Returns:
- the coerced model.
AdapterTemplateModel
s (i.e.BeanModel
) are marshalled using the standard Python marshallerPy.java2py(Object)
on the result ofgetWrappedObject(PyObject.class)
s. The native JythonModel instances will just return the underlying PyObject.- All other models that are
scalars
are marshalled asPyString
.- All other models that are
numbers
are marshalled using the standard Python marshallerPy.java2py(Object)
on their underlyingNumber
- All other models are marshalled to a generic internal
PyObject
subclass that'll correctly pass__finditem__
,__len__
,__nonzero__
, and__call__
invocations to appropriate hash, sequence, and method models.
public TemplateModel wrap(Object obj)
Wraps the passed Jython object into a FreeMarker template model. If the object is not a Jython object, it is first coerced into one usingPy.java2py(java.lang.Object)
.PyDictionary
andPyStringMap
are wrapped into a hash model,PySequence
descendants are wrapped into a sequence model,PyInteger
,PyLong
, andPyFloat
are wrapped into a number model. All objects are wrapped into a scalar model (usingObject.toString()
and a boolean model (usingPyObject.__nonzero__()
. For internal general-purposePyObject
s returned from a call tounwrap(TemplateModel)
, the template model that was passed tounwrap
is returned.
- Specified by:
- wrap in interface ObjectWrapper