src/java.scripting/share/classes/javax/script/ScriptContext.java
author michaelm
Wed, 29 Nov 2017 16:59:38 +0000
branchhttp-client-branch
changeset 55912 dfa9489d1cb1
parent 47216 71c04702a3d5
permissions -rw-r--r--
http-client-branch: fixed Http2TestServerConnection problem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
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
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Writer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * The interface whose implementing classes are used to connect Script Engines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * with objects, such as scoped Bindings, in hosting applications.  Each scope is a set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of named attributes whose values can be set and retrieved using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>ScriptContext</code> methods. ScriptContexts also expose Readers and Writers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * that can be used by the ScriptEngines for input and output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Mike Grogan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public interface ScriptContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * EngineScope attributes are visible during the lifetime of a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * <code>ScriptEngine</code> and a set of attributes is maintained for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final int ENGINE_SCOPE = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int GLOBAL_SCOPE = 200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Associates a <code>Bindings</code> instance with a particular scope in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <code>ScriptContext</code>.  Calls to the <code>getAttribute</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <code>setAttribute</code> methods must map to the <code>get</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <code>put</code> methods of the <code>Bindings</code> for the specified scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param  bindings The <code>Bindings</code> to associate with the given scope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param scope The scope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * specified scope value in ScriptContexts of this type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @throws NullPointerException if value of scope is <code>ENGINE_SCOPE</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * the specified <code>Bindings</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void setBindings(Bindings bindings, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Gets the <code>Bindings</code>  associated with the given scope in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <code>ScriptContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return The associated <code>Bindings</code>.  Returns <code>null</code> if it has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
18567
35b36d452864 8019320: Fix doclint issues in javax.script
darcy
parents: 5506
diff changeset
    81
     * @param scope The scope
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * specified scope value in <code>ScriptContext</code> of this type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public Bindings getBindings(int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
41554
fc6a35a87a52 8071678: javax.script.ScriptContext setAttribute method should clarify behavior when GLOBAL_SCOPE is used and global scope object is null
sundar
parents: 28059
diff changeset
    88
     * Sets the value of an attribute in a given scope. If the scope is <code>GLOBAL_SCOPE</code>
fc6a35a87a52 8071678: javax.script.ScriptContext setAttribute method should clarify behavior when GLOBAL_SCOPE is used and global scope object is null
sundar
parents: 28059
diff changeset
    89
     * and no Bindings is set for <code>GLOBAL_SCOPE</code>, then setAttribute call is a no-op.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param name The name of the attribute to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param value The value of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param scope The scope in which to set the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *         if the name is empty or if the scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void setAttribute(String name, Object value, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Gets the value of an attribute in a given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param name The name of the attribute to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param scope The scope in which to retrieve the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @return The value of the attribute. Returns <code>null</code> is the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * does not exist in the given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *         if the name is empty or if the value of scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public Object getAttribute(String name, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Remove an attribute in a given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param name The name of the attribute to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param scope The scope in which to remove the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return The removed value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         if the name is empty or if the scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public Object removeAttribute(String name, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Retrieves the value of the attribute with the given name in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * the scope occurring earliest in the search order.  The order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * is determined by the numeric value of the scope parameter (lowest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * scope values first.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   134
     * @param name The name of the attribute to retrieve.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return The value of the attribute in the lowest scope for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * which an attribute with the given name is defined.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * null if no attribute with the name exists in any scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @throws IllegalArgumentException if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public Object getAttribute(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Get the lowest scope in which an attribute is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param name Name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return The lowest scope.  Returns -1 if no attribute with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * name is defined in any scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @throws NullPointerException if name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @throws IllegalArgumentException if name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public int getAttributesScope(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Returns the <code>Writer</code> for scripts to use when displaying output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return The <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Writer getWriter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Returns the <code>Writer</code> used to display error output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @return The <code>Writer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public Writer getErrorWriter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Sets the <code>Writer</code> for scripts to use when displaying output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param writer The new <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void setWriter(Writer writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Sets the <code>Writer</code> used to display error output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param writer The <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void setErrorWriter(Writer writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns a <code>Reader</code> to be used by the script to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return The <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public Reader getReader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Sets the <code>Reader</code> for scripts to read input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param reader The new <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public void setReader(Reader reader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns immutable <code>List</code> of all the valid values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * scope in the ScriptContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return list of scope values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public List<Integer> getScopes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}