jdk/src/java.scripting/share/classes/javax/script/ScriptContext.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 28059 e576535359cc
child 41554 fc6a35a87a52
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Sets the value of an attribute in a given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param name The name of the attribute to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param value The value of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param scope The scope in which to set the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *         if the name is empty or if the scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public void setAttribute(String name, Object value, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Gets the value of an attribute in a given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param name The name of the attribute to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param scope The scope in which to retrieve the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return The value of the attribute. Returns <code>null</code> is the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * does not exist in the given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *         if the name is empty or if the value of scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public Object getAttribute(String name, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Remove an attribute in a given scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param name The name of the attribute to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param scope The scope in which to remove the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return The removed value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *         if the name is empty or if the scope is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public Object removeAttribute(String name, int scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Retrieves the value of the attribute with the given name in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * the scope occurring earliest in the search order.  The order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * is determined by the numeric value of the scope parameter (lowest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * scope values first.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   133
     * @param name The name of the attribute to retrieve.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return The value of the attribute in the lowest scope for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * which an attribute with the given name is defined.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * null if no attribute with the name exists in any scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws IllegalArgumentException if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public Object getAttribute(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Get the lowest scope in which an attribute is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param name Name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return The lowest scope.  Returns -1 if no attribute with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * name is defined in any scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @throws NullPointerException if name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @throws IllegalArgumentException if name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public int getAttributesScope(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Returns the <code>Writer</code> for scripts to use when displaying output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return The <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public Writer getWriter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns the <code>Writer</code> used to display error output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return The <code>Writer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public Writer getErrorWriter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Sets the <code>Writer</code> for scripts to use when displaying output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param writer The new <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void setWriter(Writer writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Sets the <code>Writer</code> used to display error output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param writer The <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void setErrorWriter(Writer writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns a <code>Reader</code> to be used by the script to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return The <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public Reader getReader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Sets the <code>Reader</code> for scripts to read input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param reader The new <code>Reader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void setReader(Reader reader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Returns immutable <code>List</code> of all the valid values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * scope in the ScriptContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return list of scope values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public List<Integer> getScopes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}