org.zkoss.zk.scripting
Class Namespaces

java.lang.Object
  extended by org.zkoss.zk.scripting.Namespaces

public class Namespaces
extends java.lang.Object

Namespace relevant utilities.

Author:
tomyeh

Constructor Summary
Namespaces()
           
 
Method Summary
static void afterInterpret(java.util.Map backup, Namespace ns, boolean popNS)
          Used with beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean) to clean up builtin variables.
static void backupVariable(java.util.Map backup, Namespace ns, java.lang.String name)
          Backup the specfied variable, such that it can be restored with afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean).
static Namespace beforeInterpret(java.util.Map backup, Component comp, boolean pushNS)
          Prepares builtin variable before calling Page.interpret(java.lang.String, java.lang.String, org.zkoss.zk.scripting.Namespace).
static Namespace beforeInterpret(java.util.Map backup, Page page, boolean pushNS)
          Prepares builtin variable before calling Page.interpret(java.lang.String, java.lang.String, org.zkoss.zk.scripting.Namespace) or a method that might be implemented with zscript.
static Namespace getCurrent(Page page)
          Returns the current namespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Namespaces

public Namespaces()
Method Detail

beforeInterpret

public static final Namespace beforeInterpret(java.util.Map backup,
                                              Component comp,
                                              boolean pushNS)
Prepares builtin variable before calling Page.interpret(java.lang.String, java.lang.String, org.zkoss.zk.scripting.Namespace).

Typical use:


final Map backup = new HashMap();
final Namespace ns = Namespaces.beforeInterpret(backup, comp, false);
try {
  Namespaces.backupVariable(backup, ns, "some");
  page.interpret(zslang, zscript, ns); //it will push ns as the current namespace
} finally {
  Namespaces.afterInterpret(backup, ns, false);
}

Another example:


final Map backup = new HashMap();
final Namespace ns = Namespaces.beforeInterpret(backup, comp, true);
try {
  Namespaces.backupVariable(backup, ns, "some");
  constr.validate(comp); //if constr might be an instance of a class implemented in zscript
} finally {
  Namespaces.afterInterpret(backup, ns, true);
}

If you need to backup some variables, you can invoke backupVariable(java.util.Map, org.zkoss.zk.scripting.Namespace, java.lang.String) between beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean) and afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean).

Parameters:
backup - the map to hold the backup variables. Never null.
comp - the component, never null.
pushNS - whether to make the namespace being returned as the current namespace (getCurrent(org.zkoss.zk.ui.Page)). Note: its value must be the same as the popNS argument of afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean).
Returns:
the namespace that owns the specified component

beforeInterpret

public static final Namespace beforeInterpret(java.util.Map backup,
                                              Page page,
                                              boolean pushNS)
Prepares builtin variable before calling Page.interpret(java.lang.String, java.lang.String, org.zkoss.zk.scripting.Namespace) or a method that might be implemented with zscript.

Parameters:
backup - the map to hold the backup variables. Never null.
page - the page, never null.
pushNS - whether to make the namespace being returned as the current namespace (getCurrent(org.zkoss.zk.ui.Page)). Note: its value must be the same as the popNS argument of afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean).
Returns:
the namespace that owns the specified page
See Also:
beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean)

afterInterpret

public static final void afterInterpret(java.util.Map backup,
                                        Namespace ns,
                                        boolean popNS)
Used with beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean) to clean up builtin variables.

Parameters:
backup - the map to hold the backup variables. Never null. It must be the same as the backup argument of beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean).
ns - the namespace returned by beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean)
popNS - whether to pop out the current namespace. Its value must be the same as the pushNS argument of beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean).

backupVariable

public static final void backupVariable(java.util.Map backup,
                                        Namespace ns,
                                        java.lang.String name)
Backup the specfied variable, such that it can be restored with afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean).

Note: you have to invoke beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean) before calling this method. Then, backup-ed variables will be restored together when afterInterpret(java.util.Map, org.zkoss.zk.scripting.Namespace, boolean) is called.

Parameters:
backup - the map to hold the backup variables. Never null. It must be the same as the backup argument of beforeInterpret(java.util.Map, org.zkoss.zk.ui.Component, boolean).
name - the variable to backup.

getCurrent

public static final Namespace getCurrent(Page page)
Returns the current namespace. The current namespace is the event target's namespace if this thread is processing an event (Event.getTarget(). Otherwise, the namespace of the page specified is assumed.

This method is used only to implement Interpreter. You rarely need to access it other than implementing an interpreter.



Copyright © 2005-2007 Potix Corporation. All Rights Reserved.