Package org.zkoss.zk.scripting
Interface Interpreter
- All Known Implementing Classes:
BSHInterpreter,GenericInterpreter,GroovyInterpreter,JythonInterpreter,RhinoInterpreter
public interface Interpreter
Represents an interpreter that can interpret the scripting codes.
It is easier to implement by extending
from GenericInterpreter.
- Author:
- tomyeh
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsVariable(String name) Tests whether the variable is defined in this interpreter.voiddestroy()Called when the interpreter is about to be destroyed.Class<?>Returns the class defined in this interpreter, or null if not found.org.zkoss.xel.FunctiongetFunction(String name, Class[] argTypes) Returns the method of the specified name defined in this interpreter, or null if not defined.Returns the scripting language this interpreter is associated with.Returns the native interpreter, or null if not available.getOwner()Returns the owner of this interpreter.getVariable(String name) Returns the value of a variable defined in this interpreter.voidInitializes the interpreter.voidEvaluates the script against the specified scope.voidsetVariable(String name, Object value) Sets the value of a variable to this interpreter, as if they are defined in the interpreter.voidunsetVariable(String name) Removes the value of a variable defined in this interpreter.
-
Method Details
-
init
Initializes the interpreter. It is called once when the new instance of interpreter is constructed.- Parameters:
zslang- the language this interpreter is associated with
-
destroy
void destroy()Called when the interpreter is about to be destroyed. After called, this interpreter cannot be used again. -
getOwner
Page getOwner()Returns the owner of this interpreter. -
getLanguage
String getLanguage()Returns the scripting language this interpreter is associated with. -
getNativeInterpreter
Object getNativeInterpreter()Returns the native interpreter, or null if not available. The native interpreter depends on the implementation of an interpreter.- Since:
- 3.0.2
-
interpret
Evaluates the script against the specified scope.Implementation Note:
- The implementation has to concatenate
the string returned by
LanguageDefinition.getEachTimeScript(java.lang.String)if not null. - The implementation must use
Scopes.getCurrent(org.zkoss.zk.ui.Page)to retrieve the current namespace if the comp argument is null.
- Parameters:
scope- the scope as the context to interpret the script. If null, the current scope is assumed. The current scope isScopes.getCurrent(org.zkoss.zk.ui.Page), which is the event target's scope, if the thread is processing an event. The event target isEvent.getTarget(). Otherwise, the current scope is the owner page (getOwner().- Since:
- 5.0.0
- The implementation has to concatenate
the string returned by
-
getClass
Returns the class defined in this interpreter, or null if not found. -
getFunction
Returns the method of the specified name defined in this interpreter, or null if not defined.- Parameters:
argTypes- the list of argument (a.k.a., parameter) types. If null, Class[0] is assumed.- Since:
- 3.0.0
-
containsVariable
Tests whether the variable is defined in this interpreter. Note: it doesn't search the attributes (Scope).- Since:
- 2.4.0
-
getVariable
Returns the value of a variable defined in this interpreter. Note: it doesn't search the scope (Scope). -
setVariable
Sets the value of a variable to this interpreter, as if they are defined in the interpreter.Note: it is not part of any namespace and it has higher priority if its name conflicts with any variable defined in the namespaces.
-
unsetVariable
Removes the value of a variable defined in this interpreter.
-