src/java.scripting/share/classes/javax/script/ScriptEngine.java
author chegar
Fri, 18 Oct 2019 21:25:01 +0100
branchdatagramsocketimpl-branch
changeset 58697 e3ff12d14d43
parent 47216 71c04702a3d5
permissions -rw-r--r--
datagramsocketimpl-branch: minor refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.script;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>ScriptEngine</code> is the fundamental interface whose methods must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * fully functional in every implementation of this specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * These methods provide basic scripting functionality.  Applications written to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * simple interface are expected to work with minimal modifications in every implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * It includes methods that execute scripts, and ones that set and get values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The values are key/value pairs of two types.  The first type of pairs consists of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * those whose keys are reserved and defined in this specification or  by individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * implementations.  The values in the pairs with reserved keys have specified meanings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The other type of pairs consists of those that create Java language Bindings, the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * usually represented in scripts by the corresponding keys or by decorated forms of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Mike Grogan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public interface ScriptEngine  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Reserved key for a named value that passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * an array of positional arguments to a script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static final String ARGV="javax.script.argv";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Reserved key for a named value that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * the name of the file being executed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final String FILENAME = "javax.script.filename";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Reserved key for a named value that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * the name of the <code>ScriptEngine</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final String ENGINE = "javax.script.engine";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Reserved key for a named value that identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * the version of the <code>ScriptEngine</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final String ENGINE_VERSION = "javax.script.engine_version";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Reserved key for a named value that identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * the short name of the scripting language.  The name is used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <code>ScriptEngineManager</code> to locate a <code>ScriptEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * with a given name in the <code>getEngineByName</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final String NAME = "javax.script.name";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Reserved key for a named value that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the full name of Scripting Language supported by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final String LANGUAGE = "javax.script.language";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Reserved key for the named value that identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the version of the scripting language supported by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final String LANGUAGE_VERSION ="javax.script.language_version";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Causes the immediate execution of the script whose source is the String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * passed as the first argument.  The script may be reparsed or recompiled before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * execution.  State left in the engine from previous executions, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * variable values and compiled procedures may be visible during this execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param script The script to be executed by the script engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param context A <code>ScriptContext</code> exposing sets of attributes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * different scopes.  The meanings of the scopes <code>ScriptContext.GLOBAL_SCOPE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * and <code>ScriptContext.ENGINE_SCOPE</code> are defined in the specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The <code>ENGINE_SCOPE</code> <code>Bindings</code> of the <code>ScriptContext</code> contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * bindings of scripting variables to application objects to be used during this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * script execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return The value returned from the execution of the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   117
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws NullPointerException if either argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public Object eval(String script, ScriptContext context) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Same as <code>eval(String, ScriptContext)</code> where the source of the script
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * is read from a <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param reader The source of the script to be executed by the script engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param context The <code>ScriptContext</code> passed to the script engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return The value returned from the execution of the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
30793
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   135
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   136
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   137
     * implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws NullPointerException if either argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public Object eval(Reader reader , ScriptContext context) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Executes the specified script.  The default <code>ScriptContext</code> for the <code>ScriptEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param script The script language source to be executed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return The value returned from the execution of the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
30793
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   150
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   151
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   152
     * implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @throws NullPointerException if the argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public Object eval(String script) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Same as <code>eval(String)</code> except that the source of the script is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * provided as a <code>Reader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param reader The source of the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return The value returned by the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
30793
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   165
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   166
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   167
     * implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @throws NullPointerException if the argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public Object eval(Reader reader) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Executes the script using the <code>Bindings</code> argument as the <code>ENGINE_SCOPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <code>Bindings</code> of the <code>ScriptEngine</code> during the script execution.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <code>Reader</code>, <code>Writer</code> and non-<code>ENGINE_SCOPE</code> <code>Bindings</code> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * default <code>ScriptContext</code> are used. The <code>ENGINE_SCOPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <code>Bindings</code> of the <code>ScriptEngine</code> is not changed, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * mappings are unaltered by the script execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param script The source for the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param n The <code>Bindings</code> of attributes to be used for script execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return The value returned by the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
30793
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   186
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   187
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   188
     * implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws NullPointerException if either argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public Object eval(String script, Bindings n) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Same as <code>eval(String, Bindings)</code> except that the source of the script
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * is provided as a <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param reader The source of the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param n The <code>Bindings</code> of attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return The value returned by the script.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
30793
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   202
     * @throws ScriptException if an error occurs in script. ScriptEngines should create and throw
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   203
     * <code>ScriptException</code> wrappers for checked Exceptions thrown by underlying scripting
bd544d22247f 8068978: All versions of javax.script.ScriptEngine.eval(...) method may clarify ScriptException throwing
sundar
parents: 25859
diff changeset
   204
     * implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @throws NullPointerException if either argument is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public Object eval(Reader reader , Bindings n) throws ScriptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Sets a key/value pair in the state of the ScriptEngine that may either create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * a Java Language Binding to be used in the execution of scripts or be used in some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * other way, depending on whether the key is reserved.  Must have the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <code>getBindings(ScriptContext.ENGINE_SCOPE).put</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param key The name of named value to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param value The value of named value to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws NullPointerException if key is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @throws IllegalArgumentException if key is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public void put(String key, Object value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Retrieves a value set in the state of this engine.  The value might be one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * which was set using <code>setValue</code> or some other value in the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * of the <code>ScriptEngine</code>, depending on the implementation.  Must have the same effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * as <code>getBindings(ScriptContext.ENGINE_SCOPE).get</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param key The key whose value is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return the value for the given key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @throws NullPointerException if key is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @throws IllegalArgumentException if key is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Object get(String key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns a scope of named values.  The possible scopes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The set of named values representing global
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * scope. If this <code>ScriptEngine</code> is created by a <code>ScriptEngineManager</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * then the manager sets global scope bindings. This may be <code>null</code> if no global
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * scope is associated with this <code>ScriptEngine</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <li><code>ScriptContext.ENGINE_SCOPE</code> - The set of named values representing the state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * this <code>ScriptEngine</code>.  The values are generally visible in scripts using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * the associated keys as variable names.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * The <code>Bindings</code> instances that are returned must be identical to those returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <code>getBindings</code> method of <code>ScriptContext</code> called with corresponding arguments on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param scope Either <code>ScriptContext.ENGINE_SCOPE</code> or <code>ScriptContext.GLOBAL_SCOPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * which specifies the <code>Bindings</code> to return.  Implementations of <code>ScriptContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * may define additional scopes.  If the default <code>ScriptContext</code> of the <code>ScriptEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * defines additional scopes, any of them can be passed to get the corresponding <code>Bindings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return The <code>Bindings</code> with the specified scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @throws IllegalArgumentException if specified scope is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public Bindings getBindings(int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Sets a scope of named values to be used by scripts.  The possible scopes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *<br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <li><code>ScriptContext.ENGINE_SCOPE</code> - The specified <code>Bindings</code> replaces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * engine scope of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <li><code>ScriptContext.GLOBAL_SCOPE</code> - The specified <code>Bindings</code> must be visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * as the <code>GLOBAL_SCOPE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <li>Any other value of scope defined in the default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <br><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * The method must have the same effect as calling the <code>setBindings</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <code>ScriptContext</code> with the corresponding value of <code>scope</code> on the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <code>ScriptContext</code> of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param bindings The <code>Bindings</code> for the specified scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param scope The specified scope.  Either <code>ScriptContext.ENGINE_SCOPE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>ScriptContext.GLOBAL_SCOPE</code>, or any other valid value of scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @throws IllegalArgumentException if the scope is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @throws NullPointerException if the bindings is null and the scope is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <code>ScriptContext.ENGINE_SCOPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void setBindings(Bindings bindings, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Returns an uninitialized <code>Bindings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return A <code>Bindings</code> that can be used to replace the state of this <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public Bindings createBindings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @return The default <code>ScriptContext</code> of the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public ScriptContext getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Sets the default <code>ScriptContext</code> of the <code>ScriptEngine</code> whose Bindings, Reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * and Writers are used for script executions when no <code>ScriptContext</code> is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param context A <code>ScriptContext</code> that will replace the default <code>ScriptContext</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the <code>ScriptEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @throws NullPointerException if context is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public void setContext(ScriptContext context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns a <code>ScriptEngineFactory</code> for the class to which this <code>ScriptEngine</code> belongs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return The <code>ScriptEngineFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public ScriptEngineFactory getFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}