001: /* Interpreter.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Jun 1 14:51:22 2006, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zk.scripting;
020:
021: import org.zkoss.xel.Function;
022: import org.zkoss.zk.ui.Page;
023:
024: /**
025: * Represents an interpter that can interpret the scripting codes.
026: *
027: * <p>It is easier to implement by extending
028: * from {@link org.zkoss.zk.scripting.util.GenericInterpreter}.
029: *
030: * @author tomyeh
031: */
032: public interface Interpreter {
033: /** Initializes the interpreter.
034: * It is called once when the new instance of interpreter is constructed.
035: *
036: * @param zslang the language this interpreter is associated with
037: */
038: public void init(Page owner, String zslang);
039:
040: /** Called when the interpreter is about to be destroyed.
041: * After called, this interpreter cannot be used again.
042: */
043: public void destroy();
044:
045: /** Returns the owner of this interpreter.
046: */
047: public Page getOwner();
048:
049: /** Returns the scripting language this interpreter is associated with.
050: */
051: public String getLanguage();
052:
053: /** Returns the native interpreter, or null if not available.
054: * The native interpreter depends on the implementation of an interpreter.
055: *
056: * @since 3.0.2
057: */
058: public Object getNativeInterpreter();
059:
060: /** Evaluates the script against the specified namespace.
061: *
062: * <p>Implementation Note:
063: * <ol>
064: * <li>The implementation has to concatenate
065: * the string returned by
066: * {@link org.zkoss.zk.ui.metainfo.LanguageDefinition#getEachTimeScript}
067: * if not null.</li>
068: * <li>The implementation must use {@link Namespaces#getCurrent}
069: * to retrieve the current namesace if the ns argument is null.
070: *
071: * @param ns the namspace. If null, the current namespace is assumed.
072: * The current namespace is {@link Namespaces#getCurrent}, which
073: * is the event target's namespace, if the thread is processing an event.
074: * The event target is {@link org.zkoss.zk.ui.event.Event#getTarget}.
075: * Otherwise, the current namespace is the owner page's namespace
076: * ({@link #getOwner}.
077: */
078: public void interpret(String script, Namespace ns);
079:
080: /** Returns the class defined in this interpreter, or null if not found.
081: */
082: public Class getClass(String clsnm);
083:
084: /** Returns the method of the specified name defined in this interpreter,
085: * or null if not defined.
086: *
087: * @param argTypes the list of argument (aka., parameter) types.
088: * If null, Class[0] is assumed.
089: * @since 3.0.0
090: */
091: public Function getFunction(String name, Class[] argTypes);
092:
093: /** Tests whether the variable is defined in this interpreter.
094: * Note: it doesn't search the namespace ({@link Namespace}).
095: *
096: * @since 2.4.0
097: */
098: public boolean containsVariable(String name);
099:
100: /** Returns the value of a variable defined in this interpreter.
101: * Note: it doesn't search the namespace ({@link Namespace}).
102: */
103: public Object getVariable(String name);
104:
105: /** Sets the value of a variable to this interpreter, as if
106: * they are defined in the interpreter.
107: *
108: * <p>Note: it is not part of any namespace and it has higher prioerty
109: * if its name conflicts with any variable defined in the namespaces.
110: */
111: public void setVariable(String name, Object value);
112:
113: /** Removes the value of a variable defined in this interpreter.
114: */
115: public void unsetVariable(String name);
116: }
|