public class RhinoScriptableModel extends java.lang.Object implements TemplateHashModelEx, TemplateSequenceModel, AdapterTemplateModel, TemplateScalarModel, TemplateBooleanModel, TemplateNumberModel
NOTHING
EMPTY_STRING
FALSE, TRUE
Constructor and Description |
---|
RhinoScriptableModel(org.mozilla.javascript.Scriptable scriptable,
BeansWrapper wrapper) |
Modifier and Type | Method and Description |
---|---|
TemplateModel |
get(int index)
Retrieves the i-th template model in this sequence.
|
TemplateModel |
get(java.lang.String key)
Gets a TemplateModel from the hash.
|
java.lang.Object |
getAdaptedObject(java.lang.Class hint)
Retrieves the underlying object, or some other object semantically
equivalent to its value narrowed by the class hint.
|
boolean |
getAsBoolean() |
java.lang.Number |
getAsNumber()
Returns the numeric value.
|
java.lang.String |
getAsString()
Returns the string representation of this model.
|
boolean |
isEmpty() |
TemplateCollectionModel |
keys() |
int |
size() |
TemplateCollectionModel |
values() |
public RhinoScriptableModel(org.mozilla.javascript.Scriptable scriptable, BeansWrapper wrapper)
public TemplateModel get(java.lang.String key) throws TemplateModelException
TemplateHashModel
get
in interface TemplateHashModel
key
- the name by which the TemplateModel
is identified in the template.TemplateModelException
public TemplateModel get(int index) throws TemplateModelException
TemplateSequenceModel
get
in interface TemplateSequenceModel
null
if
the index is out of bounds. Note that a null
value is
interpreted by FreeMarker as "variable does not exist", and accessing
a missing variables is usually considered as an error in the FreeMarker
Template Language, so the usage of a bad index will not remain hidden.TemplateModelException
public boolean isEmpty()
isEmpty
in interface TemplateHashModel
public TemplateCollectionModel keys() throws TemplateModelException
keys
in interface TemplateHashModelEx
TemplateScalarModel
(as the keys of hashes are always strings).TemplateModelException
public int size()
size
in interface TemplateHashModelEx
size
in interface TemplateSequenceModel
public TemplateCollectionModel values() throws TemplateModelException
values
in interface TemplateHashModelEx
TemplateModel
-s.TemplateModelException
public boolean getAsBoolean()
getAsBoolean
in interface TemplateBooleanModel
public java.lang.Number getAsNumber()
TemplateNumberModel
getAsNumber
in interface TemplateNumberModel
Number
instance associated with this number model.public java.lang.String getAsString()
TemplateScalarModel
null
, as that will cause exception.
(In classic-compatible mode the engine will convert null
into empty string, though.)getAsString
in interface TemplateScalarModel
public java.lang.Object getAdaptedObject(java.lang.Class hint)
AdapterTemplateModel
getAdaptedObject
in interface AdapterTemplateModel
hint
- the desired class of the returned value. An implementation
should make reasonable effort to retrieve an object of the requested
class, but if that is impossible, it must at least return the underlying
object as-is. As a minimal requirement, an implementation must always
return the exact underlying object when
hint.isInstance(underlyingObject) == true holds. When called
with java.lang.Object.class, it should return a generic Java
object (i.e. if the model is wrapping a scripting language object that is
further wrapping a Java object, the deepest underlying Java object should
be returned).