0N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.script;
0N/A
0N/Aimport java.io.Reader;
0N/Aimport java.util.Map;
0N/Aimport java.util.Set;
0N/A
0N/A/**
0N/A * <code>ScriptEngine</code> is the fundamental interface whose methods must be
0N/A * fully functional in every implementation of this specification.
0N/A * <br><br>
0N/A * These methods provide basic scripting functionality. Applications written to this
0N/A * simple interface are expected to work with minimal modifications in every implementation.
0N/A * It includes methods that execute scripts, and ones that set and get values.
0N/A * <br><br>
0N/A * The values are key/value pairs of two types. The first type of pairs consists of
0N/A * those whose keys are reserved and defined in this specification or by individual
0N/A * implementations. The values in the pairs with reserved keys have specified meanings.
0N/A * <br><br>
0N/A * The other type of pairs consists of those that create Java language Bindings, the values are
0N/A * usually represented in scripts by the corresponding keys or by decorated forms of them.
0N/A *
0N/A * @author Mike Grogan
0N/A * @since 1.6
0N/A */
0N/A
0N/Apublic interface ScriptEngine {
0N/A
0N/A /**
0N/A * Reserved key for a named value that passes
0N/A * an array of positional arguments to a script.
0N/A */
0N/A public static final String ARGV="javax.script.argv";
0N/A
0N/A /**
0N/A * Reserved key for a named value that is
0N/A * the name of the file being executed.
0N/A */
0N/A public static final String FILENAME = "javax.script.filename";
0N/A
0N/A /**
0N/A * Reserved key for a named value that is
0N/A * the name of the <code>ScriptEngine</code> implementation.
0N/A */
0N/A public static final String ENGINE = "javax.script.engine";
0N/A
0N/A /**
0N/A * Reserved key for a named value that identifies
0N/A * the version of the <code>ScriptEngine</code> implementation.
0N/A */
0N/A public static final String ENGINE_VERSION = "javax.script.engine_version";
0N/A
0N/A /**
0N/A * Reserved key for a named value that identifies
0N/A * the short name of the scripting language. The name is used by the
0N/A * <code>ScriptEngineManager</code> to locate a <code>ScriptEngine</code>
0N/A * with a given name in the <code>getEngineByName</code> method.
0N/A */
0N/A public static final String NAME = "javax.script.name";
0N/A
0N/A /**
0N/A * Reserved key for a named value that is
0N/A * the full name of Scripting Language supported by the implementation.
0N/A */
0N/A public static final String LANGUAGE = "javax.script.language";
0N/A
0N/A /**
0N/A * Reserved key for the named value that identifies
0N/A * the version of the scripting language supported by the implementation.
0N/A */
0N/A public static final String LANGUAGE_VERSION ="javax.script.language_version";
0N/A
0N/A
0N/A /**
0N/A * Causes the immediate execution of the script whose source is the String
0N/A * passed as the first argument. The script may be reparsed or recompiled before
0N/A * execution. State left in the engine from previous executions, including
0N/A * variable values and compiled procedures may be visible during this execution.
0N/A *
0N/A * @param script The script to be executed by the script engine.
0N/A *
0N/A * @param context A <code>ScriptContext</code> exposing sets of attributes in
0N/A * different scopes. The meanings of the scopes <code>ScriptContext.GLOBAL_SCOPE</code>,
0N/A * and <code>ScriptContext.ENGINE_SCOPE</code> are defined in the specification.
0N/A * <br><br>
0N/A * The <code>ENGINE_SCOPE</code> <code>Bindings</code> of the <code>ScriptContext</code> contains the
0N/A * bindings of scripting variables to application objects to be used during this
0N/A * script execution.
0N/A *
0N/A *
0N/A * @return The value returned from the execution of the script.
0N/A *
0N/A * @throws ScriptException if an error occurrs in script. ScriptEngines should create and throw
0N/A * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
0N/A * implementations.
0N/A * @throws NullPointerException if either argument is null.
0N/A */
0N/A public Object eval(String script, ScriptContext context) throws ScriptException;
0N/A
0N/A
0N/A /**
0N/A * Same as <code>eval(String, ScriptContext)</code> where the source of the script
0N/A * is read from a <code>Reader</code>.
0N/A *
0N/A * @param reader The source of the script to be executed by the script engine.
0N/A *
0N/A * @param context The <code>ScriptContext</code> passed to the script engine.
0N/A *
0N/A * @return The value returned from the execution of the script.
0N/A *
0N/A * @throws ScriptException if an error occurrs in script.
0N/A * @throws NullPointerException if either argument is null.
0N/A */
0N/A public Object eval(Reader reader , ScriptContext context) throws ScriptException;
0N/A
0N/A /**
0N/A * Executes the specified script. The default <code>ScriptContext</code> for the <code>ScriptEngine</code>
0N/A * is used.
0N/A *
0N/A * @param script The script language source to be executed.
0N/A *
0N/A * @return The value returned from the execution of the script.
0N/A *
0N/A * @throws ScriptException if error occurrs in script.
0N/A * @throws NullPointerException if the argument is null.
0N/A */
0N/A public Object eval(String script) throws ScriptException;
0N/A
0N/A /**
0N/A * Same as <code>eval(String)</code> except that the source of the script is
0N/A * provided as a <code>Reader</code>
0N/A *
0N/A * @param reader The source of the script.
0N/A *
0N/A * @return The value returned by the script.
0N/A *
0N/A * @throws ScriptException if an error occurrs in script.
0N/A * @throws NullPointerException if the argument is null.
0N/A */
0N/A public Object eval(Reader reader) throws ScriptException;
0N/A
0N/A /**
0N/A * Executes the script using the <code>Bindings</code> argument as the <code>ENGINE_SCOPE</code>
0N/A * <code>Bindings</code> of the <code>ScriptEngine</code> during the script execution. The
0N/A * <code>Reader</code>, <code>Writer</code> and non-<code>ENGINE_SCOPE</code> <code>Bindings</code> of the
0N/A * default <code>ScriptContext</code> are used. The <code>ENGINE_SCOPE</code>
0N/A * <code>Bindings</code> of the <code>ScriptEngine</code> is not changed, and its
0N/A * mappings are unaltered by the script execution.
0N/A *
0N/A * @param script The source for the script.
0N/A *
0N/A * @param n The <code>Bindings</code> of attributes to be used for script execution.
0N/A *
0N/A * @return The value returned by the script.
0N/A *
0N/A * @throws ScriptException if an error occurrs in script.
0N/A * @throws NullPointerException if either argument is null.
0N/A */
0N/A public Object eval(String script, Bindings n) throws ScriptException;
0N/A
0N/A /**
0N/A * Same as <code>eval(String, Bindings)</code> except that the source of the script
0N/A * is provided as a <code>Reader</code>.
0N/A *
0N/A * @param reader The source of the script.
0N/A * @param n The <code>Bindings</code> of attributes.
0N/A *
0N/A * @return The value returned by the script.
0N/A *
0N/A * @throws ScriptException if an error occurrs.
0N/A * @throws NullPointerException if either argument is null.
0N/A */
0N/A public Object eval(Reader reader , Bindings n) throws ScriptException;
0N/A
0N/A
0N/A
0N/A /**
0N/A * Sets a key/value pair in the state of the ScriptEngine that may either create
0N/A * a Java Language Binding to be used in the execution of scripts or be used in some
0N/A * other way, depending on whether the key is reserved. Must have the same effect as
0N/A * <code>getBindings(ScriptContext.ENGINE_SCOPE).put</code>.
0N/A *
0N/A * @param key The name of named value to add
0N/A * @param value The value of named value to add.
0N/A *
0N/A * @throws NullPointerException if key is null.
0N/A * @throws IllegalArgumentException if key is empty.
0N/A */
0N/A public void put(String key, Object value);
0N/A
0N/A
0N/A /**
0N/A * Retrieves a value set in the state of this engine. The value might be one
0N/A * which was set using <code>setValue</code> or some other value in the state
0N/A * of the <code>ScriptEngine</code>, depending on the implementation. Must have the same effect
0N/A * as <code>getBindings(ScriptContext.ENGINE_SCOPE).get</code>
0N/A *
0N/A * @param key The key whose value is to be returned
0N/A * @return the value for the given key
0N/A *
0N/A * @throws NullPointerException if key is null.
0N/A * @throws IllegalArgumentException if key is empty.
0N/A */
0N/A public Object get(String key);
0N/A
0N/A
0N/A /**
0N/A * Returns a scope of named values. The possible scopes are:
0N/A * <br><br>
0N/A * <ul>
0N/A * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The set of named values representing global
0N/A * scope. If this <code>ScriptEngine</code> is created by a <code>ScriptEngineManager</code>,
0N/A * then the manager sets global scope bindings. This may be <code>null</code> if no global
0N/A * scope is associated with this <code>ScriptEngine</code></li>
0N/A * <li><code>ScriptContext.ENGINE_SCOPE</code> - The set of named values representing the state of
0N/A * this <code>ScriptEngine</code>. The values are generally visible in scripts using
0N/A * the associated keys as variable names.</li>
0N/A * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
0N/A * </li>
0N/A * </ul>
0N/A * <br><br>
0N/A * The <code>Bindings</code> instances that are returned must be identical to those returned by the
0N/A * <code>getBindings</code> method of <code>ScriptContext</code> called with corresponding arguments on
0N/A * the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
0N/A *
0N/A * @param scope Either <code>ScriptContext.ENGINE_SCOPE</code> or <code>ScriptContext.GLOBAL_SCOPE</code>
0N/A * which specifies the <code>Bindings</code> to return. Implementations of <code>ScriptContext</code>
0N/A * may define additional scopes. If the default <code>ScriptContext</code> of the <code>ScriptEngine</code>
0N/A * defines additional scopes, any of them can be passed to get the corresponding <code>Bindings</code>.
0N/A *
0N/A * @return The <code>Bindings</code> with the specified scope.
0N/A *
0N/A * @throws IllegalArgumentException if specified scope is invalid
0N/A *
0N/A */
0N/A public Bindings getBindings(int scope);
0N/A
0N/A /**
0N/A * Sets a scope of named values to be used by scripts. The possible scopes are:
0N/A *<br><br>
0N/A * <ul>
0N/A * <li><code>ScriptContext.ENGINE_SCOPE</code> - The specified <code>Bindings</code> replaces the
0N/A * engine scope of the <code>ScriptEngine</code>.
0N/A * </li>
0N/A * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The specified <code>Bindings</code> must be visible
0N/A * as the <code>GLOBAL_SCOPE</code>.
0N/A * </li>
0N/A * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
0N/A *</li>
0N/A * </ul>
0N/A * <br><br>
0N/A * The method must have the same effect as calling the <code>setBindings</code> method of
0N/A * <code>ScriptContext</code> with the corresponding value of <code>scope</code> on the default
0N/A * <code>ScriptContext</code> of the <code>ScriptEngine</code>.
0N/A *
0N/A * @param bindings The <code>Bindings</code> for the specified scope.
0N/A * @param scope The specified scope. Either <code>ScriptContext.ENGINE_SCOPE</code>,
0N/A * <code>ScriptContext.GLOBAL_SCOPE</code>, or any other valid value of scope.
0N/A *
0N/A * @throws IllegalArgumentException if the scope is invalid
0N/A * @throws NullPointerException if the bindings is null and the scope is
0N/A * <code>ScriptContext.ENGINE_SCOPE</code>
0N/A */
0N/A public void setBindings(Bindings bindings, int scope);
0N/A
0N/A
0N/A /**
0N/A * Returns an uninitialized <code>Bindings</code>.
0N/A *
0N/A * @return A <code>Bindings</code> that can be used to replace the state of this <code>ScriptEngine</code>.
0N/A **/
0N/A public Bindings createBindings();
0N/A
0N/A
0N/A /**
0N/A * Returns the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
0N/A * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
0N/A *
0N/A * @return The default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
0N/A */
0N/A public ScriptContext getContext();
0N/A
0N/A /**
0N/A * Sets the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
0N/A * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
0N/A *
0N/A * @param context A <code>ScriptContext</code> that will replace the default <code>ScriptContext</code> in
0N/A * the <code>ScriptEngine</code>.
0N/A * @throws NullPointerException if context is null.
0N/A */
0N/A public void setContext(ScriptContext context);
0N/A
0N/A /**
0N/A * Returns a <code>ScriptEngineFactory</code> for the class to which this <code>ScriptEngine</code> belongs.
0N/A *
0N/A * @return The <code>ScriptEngineFactory</code>
0N/A */
0N/A public ScriptEngineFactory getFactory();
0N/A}