| java.lang.Object freemarker.ext.jython.JythonWrapper
JythonWrapper | public class JythonWrapper implements ObjectWrapper(Code) | | An object wrapper that wraps Jython objects into FreeMarker template models
and vice versa.
version: $Id: JythonWrapper.java,v 1.23.2.1 2005/10/04 16:18:08 revusky Exp $ author: Attila Szegedi |
Method Summary | |
boolean | isAttributesShadowItems() | public synchronized void | setAttributesShadowItems(boolean attributesShadowItems) Sets whether attributes shadow items in wrapped objects. | public void | setUseCache(boolean useCache) Sets whether this wrapper caches model instances. | public PyObject | unwrap(TemplateModel model) Coerces a template model into a
PyObject .
Parameters: model - the model to coerce the coerced model. | public TemplateModel | wrap(Object obj) Wraps the passed Jython object into a FreeMarker template model. |
JythonWrapper | public JythonWrapper()(Code) | | |
isAttributesShadowItems | boolean isAttributesShadowItems()(Code) | | |
setAttributesShadowItems | public synchronized void setAttributesShadowItems(boolean attributesShadowItems)(Code) | | 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
using
PyObject.__findattr__(java.lang.String) , and only if it
doesn't find the attribute will it call
PyObject.__getitem__(org.python.core.PyObject) .
When set to false, the lookup order is reversed and items
are looked up before attributes.
|
setUseCache | public void setUseCache(boolean useCache)(Code) | | Sets whether this wrapper caches model instances. Default is false.
When set to true, calling
JythonWrapper.wrap(Object) multiple times for
the same object will return the same model.
|
unwrap | public PyObject unwrap(TemplateModel model) throws TemplateModelException(Code) | | Coerces a template model into a
PyObject .
Parameters: model - the model to coerce the coerced model.- AdapterTemplateModels (i.e. freemarker.ext.beans.BeanModel) are marshalledusing the standard Python marshaller Py.java2py(Object) on the result of
getWrappedObject(PyObject.class) s. The native JythonModel instances will just return the underlying PyObject. - All other models that are TemplateScalarModel scalars are marshalled as PyString.
- All other models that are TemplateNumberModel numbers are marshalled using the standard Python marshallerPy.java2py(Object) on their underlying
Number - 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.
|
wrap | public TemplateModel wrap(Object obj)(Code) | | Wraps the passed Jython object into a FreeMarker template model. If
the object is not a Jython object, it is first coerced into one using
Py.java2py(java.lang.Object) .
PyDictionary and
PyStringMap are wrapped into a hash model,
PySequence descendants are wrapped into a sequence model,
PyInteger ,
PyLong , and
PyFloat are wrapped into a number model. All objects
are wrapped into a scalar model (using
Object.toString and a
boolean model (using
PyObject.__nonzero__ . For internal
general-purpose
PyObject s returned from a call to
JythonWrapper.unwrap(TemplateModel) , the template model that was passed to
unwrap is returned.
|
|
|