|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.zk.scripting.util.GenericInterpreter
public abstract class GenericInterpreter
A skeletal class for implementing a interpreter (Interpreter) that
support Namespace.
Derive classes usually override exec(java.lang.String) instead of interpret(java.lang.String, org.zkoss.zk.scripting.Namespace);
In addition, don't override getVariable(java.lang.String),
setVariable(java.lang.String, java.lang.Object) and unsetVariable(java.lang.String).
Instead, override get(String), contains(String),
set(String,Object) and unset(String) instead.
If an interpreter doesn't support hierachical scopes,
it can simply implement a global scope, and then use
getFromNamespace(java.lang.String) to
retrieve variables from ZK's hierachical namespaces.
If it supports hierachical scopes
(example: BSHInterpreter), it
can maintain a one-to-one relationship among interpreter's scopes
and ZK's Namespace. Thus, it can retrieve
the correct scope by giving ZK's Namespace, and vice versa.
It also has to implement get(Namespace,String), contains(Namespace,String)
set(Namespace,String,Object) and unset(Namespace,String).
Whether to support hierachical namespaces is optional.
| Field Summary | |
|---|---|
static java.lang.Object |
UNDEFINED
Used by getFromNamespace(java.lang.String) to denote a variable is not defined. |
| Constructor Summary | |
|---|---|
protected |
GenericInterpreter()
|
| Method Summary | |
|---|---|
protected void |
afterExec()
Called after exec(java.lang.String), get(java.lang.String) and many others. |
protected void |
afterInterpret(Namespace ns)
Called after exec(java.lang.String). |
protected void |
beforeExec()
Called before exec(java.lang.String), get(java.lang.String) and many others. |
protected void |
beforeInterpret(Namespace ns)
Called before exec(java.lang.String). |
protected boolean |
contains(Namespace ns,
java.lang.String name)
Tests whether a variable is defined in the interpreter's scope associated with the specified namespace. |
protected boolean |
contains(java.lang.String name)
Tests whether a variable is defined in this interpreter. |
boolean |
containsVariable(Namespace ns,
java.lang.String name)
Tests whether the variable exists by using the specified name as a reference to identify the interpreter's scope. |
boolean |
containsVariable(java.lang.String name)
Tests whether the variable exists. |
void |
destroy()
Reset the owner ( getOwner()) to null. |
protected abstract void |
exec(java.lang.String script)
Executes the specified script. |
protected java.lang.Object |
get(Namespace ns,
java.lang.String name)
Gets the variable from the interpreter's scope associated with the giving namespace. |
protected java.lang.Object |
get(java.lang.String name)
Gets the variable from the interpreter. |
java.lang.Class |
getClass(java.lang.String clsnm)
Returns null since retrieving class is not supported. |
protected Namespace |
getCurrent()
Returns the current namespace, or null if no namespace is allowed. |
protected java.lang.Object |
getFromNamespace(Namespace ns,
java.lang.String name)
Returns the variable through the specified namespaces and variable resolvers, or UNDEFINED if the variable is not
defined. |
protected java.lang.Object |
getFromNamespace(java.lang.String name)
Returns the variable through namespaces and variable resolvers, or UNDEFINED if the variable not defined. |
org.zkoss.xel.Function |
getFunction(Namespace ns,
java.lang.String name,
java.lang.Class[] argTypes)
Returns null since retrieving methods is not supported. |
org.zkoss.xel.Function |
getFunction(java.lang.String name,
java.lang.Class[] argTypes)
Returns null since retrieving methods is not supported. |
java.lang.String |
getLanguage()
Returns the scripting language this interpreter is associated with. |
Page |
getOwner()
Returns the owner of this interpreter. |
java.lang.Object |
getVariable(Namespace ns,
java.lang.String name)
Returns the value of a variable defined in this interpreter's scope identified by the specified namespace. |
java.lang.Object |
getVariable(java.lang.String name)
Retrieve the variable. |
void |
init(Page owner,
java.lang.String zslang)
Initializes the interpreter. |
void |
interpret(java.lang.String script,
Namespace ns)
Handles the namespace and then invoke exec(java.lang.String). |
protected void |
set(Namespace ns,
java.lang.String name,
java.lang.Object value)
Sets the variable to the interpreter's scope associated with the giving namespace. |
protected void |
set(java.lang.String name,
java.lang.Object value)
Sets the variable to the interpreter. |
void |
setVariable(Namespace ns,
java.lang.String name,
java.lang.Object value)
Sets the value of a variable to this interpreter's scope identified by the specified namespace. |
void |
setVariable(java.lang.String name,
java.lang.Object value)
Sets the variable to this interpreter. |
protected void |
unset(Namespace ns,
java.lang.String name)
Removes the variable from the interpreter. |
protected void |
unset(java.lang.String name)
Removes the variable from the interpreter. |
void |
unsetVariable(Namespace ns,
java.lang.String name)
Removes the value of a variable defined in the interpreter's scope identified by the specified namespace. |
void |
unsetVariable(java.lang.String name)
Removes the variable from this interpreter. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.Object UNDEFINED
getFromNamespace(java.lang.String) to denote a variable is not defined.
| Constructor Detail |
|---|
protected GenericInterpreter()
| Method Detail |
|---|
protected abstract void exec(java.lang.String script)
interpret(java.lang.String, org.zkoss.zk.scripting.Namespace).
protected boolean contains(java.lang.String name)
By default, it tests whether get(String) returns non-null.
protected java.lang.Object get(java.lang.String name)
beforeExec() is called first, before this method is invoked.
An empty (and fake) namespace is pushed so getFromNamespace(java.lang.String)
always returns null.
protected void set(java.lang.String name,
java.lang.Object value)
beforeExec() is called first, before this method is invoked.
protected void unset(java.lang.String name)
beforeExec() is called first, before this method is invoked.
protected boolean contains(Namespace ns,
java.lang.String name)
By default, it tests whether get(Namespace, String)
returns non-null.
protected java.lang.Object get(Namespace ns,
java.lang.String name)
This method is implemented only if the interpreter that supports
hierachical scopes (HierachicalAware).
Default: the same as get(String).
beforeExec() is called first, before this method is invoked.
An empty (and fake) namespace is pushed so getFromNamespace(java.lang.String)
always returns null.
protected void set(Namespace ns,
java.lang.String name,
java.lang.Object value)
This method is implemented only if the interpreter that supports
hierachical scopes (HierachicalAware).
Default: the same as set(String, Object).
beforeExec() is called first, before this method is invoked.
protected void unset(Namespace ns,
java.lang.String name)
This method is implemented only if the interpreter that supports
hierachical scopes (HierachicalAware).
Default: the same as unset(String).
beforeExec() is called first, before this method is invoked.
protected void beforeInterpret(Namespace ns)
exec(java.lang.String).
Default: call beforeExec() and push the namespace
as the active one.
protected void afterInterpret(Namespace ns)
exec(java.lang.String).
Default: call afterExec().
protected void beforeExec()
exec(java.lang.String), get(java.lang.String) and many others.
Default: does nothing.
protected void afterExec()
exec(java.lang.String), get(java.lang.String) and many others.
Default: does nothing.
protected java.lang.Object getFromNamespace(java.lang.String name)
UNDEFINED if the variable not defined.
It is usually called to search namespaces and variable resolvers, when the real interpreter failed to find a variable in its own scope.
Note: We use UNDEFINED to denote undefined since 2.4.0,
while null is a valid value.
protected java.lang.Object getFromNamespace(Namespace ns,
java.lang.String name)
UNDEFINED if the variable is not
defined.
It is usually called to search namespaces and variable resolvers, when the real interpreter failed to find a variable in its own scope.
This method is used with the interpreter that supports
hierachical scopes (HierachicalAware).
ns - the namespace to search from (never null).
Note: if getCurrent() returns null, this method simply returns
null (i.e., ignoring ns).
public void init(Page owner,
java.lang.String zslang)
Interpreter
init in interface Interpreterzslang - the language this interpreter is associated withpublic void destroy()
getOwner()) to null.
destroy in interface Interpreterpublic Page getOwner()
Interpreter
getOwner in interface Interpreterpublic java.lang.String getLanguage()
Interpreter
getLanguage in interface Interpreter
public void interpret(java.lang.String script,
Namespace ns)
exec(java.lang.String).
Don't override this method, rather, override exec(java.lang.String).
interpret in interface Interpreterns - the namspace. If null, the current namespace is assumed.
The current namespace is Namespaces.getCurrent(org.zkoss.zk.ui.Page), which
is the event target's namespace, if the thread is processing an event.
The event target is Event.getTarget().
Otherwise, the current namespace is the owner page's namespace
(Interpreter.getOwner().public java.lang.Class getClass(java.lang.String clsnm)
getClass in interface Interpreter
public org.zkoss.xel.Function getFunction(java.lang.String name,
java.lang.Class[] argTypes)
getFunction in interface InterpreterargTypes - the list of argument (aka., parameter) types.
If null, Class[0] is assumed.
public org.zkoss.xel.Function getFunction(Namespace ns,
java.lang.String name,
java.lang.Class[] argTypes)
public boolean containsVariable(java.lang.String name)
Deriving class shall override contains(String), instead of this method.
containsVariable in interface Interpreterpublic java.lang.Object getVariable(java.lang.String name)
Deriving class shall override get(String), instead of this method.
getVariable in interface Interpreter
public final void setVariable(java.lang.String name,
java.lang.Object value)
Deriving class shall override set(String,Object), instead of this method.
setVariable in interface Interpreterpublic final void unsetVariable(java.lang.String name)
Deriving class shall override unset(String), instead of this method.
unsetVariable in interface Interpreter
public boolean containsVariable(Namespace ns,
java.lang.String name)
Deriving class shall override contains(Namespace,String), instead of this method.
public java.lang.Object getVariable(Namespace ns,
java.lang.String name)
Namespace).
Deriving class shall override get(Namespace,String),
instead of this method.
This method is part of HierachicalAware.
It is defined here to simplify the implementation of the
deriving classes, if they support the hierachical scopes.
public final void setVariable(Namespace ns,
java.lang.String name,
java.lang.Object value)
Deriving class shall override set(Namespace,String,Object),
instead of this method.
public final void unsetVariable(Namespace ns,
java.lang.String name)
Deriving class shall override unset(Namespace,String), instead of this method.
protected Namespace getCurrent()
This method will handle Namespaces.getCurrent(org.zkoss.zk.ui.Page) automatically.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||