Class BSHInterpreter

  • All Implemented Interfaces:
    HierarchicalAware, Interpreter, SerializableAware

    public class BSHInterpreter
    extends GenericInterpreter
    implements SerializableAware, HierarchicalAware
    The interpreter that uses BeanShell to interpret zscript codes.

    Unlike many other implementations, it supports the hierarchical scopes (HierarchicalAware). That is, it uses an independent BeanShell NameSpace (a.k.a. interpreter's scope) to store the variables/classes/methods defined in BeanShell script for each ZK scope (Scope). Since one-to-one relationship between BeanShell's scope and ZK scope, the invocation of BeanShell methods can execute correctly without knowing what scope it is. However, if you want your codes portable across different interpreters, you had better to call Scopes.beforeInterpret(org.zkoss.zk.ui.ext.Scope) to prepare the proper scope, before calling any method defined in zscript.

    How serialization work?

    First, all NameSpace objects have to serialize. Second, the top-level namespace (GlobalNS) is wrapped with NSWrap, which is not serializable. It is serialized when SerializableAware.write(java.io.ObjectOutputStream, org.zkoss.zk.scripting.SerializableAware.Filter) is called (triggered by PageImpl's write).

    On the other hand, all non-top-level namespaces (NS) are wrapped with NSWrapSR which is serializable, so they are serialized with the attributes of a ID space owner being serialized.

    Author:
    tomyeh