History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/script/ScriptContext.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/script/ScriptContext.java+206−0
@@ -0,0 +1,206 @@
1/*
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.script;
27import java.util.List;
28import java.io.Writer;
29import java.io.Reader;
30
31/**
32 * The interface whose implementing classes are used to connect Script Engines
33 * with objects, such as scoped Bindings, in hosting applications. Each scope is a set
34 * of named attributes whose values can be set and retrieved using the
35 * <code>ScriptContext</code> methods. ScriptContexts also expose Readers and Writers
36 * that can be used by the ScriptEngines for input and output.
37 *
38 * @author Mike Grogan
39 * @since 1.6
40 */
41public interface ScriptContext {
42
43
44 /**
45 * EngineScope attributes are visible during the lifetime of a single
46 * <code>ScriptEngine</code> and a set of attributes is maintained for each
47 * engine.
48 */
49 public static final int ENGINE_SCOPE = 100;
50
51 /**
52 * GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
53 */
54 public static final int GLOBAL_SCOPE = 200;
55
56
57 /**
58 * Associates a <code>Bindings</code> instance with a particular scope in this
59 * <code>ScriptContext</code>. Calls to the <code>getAttribute</code> and
60 * <code>setAttribute</code> methods must map to the <code>get</code> and
61 * <code>put</code> methods of the <code>Bindings</code> for the specified scope.
62 *
63 * @param bindings The <code>Bindings</code> to associate with the given scope
64 * @param scope The scope
65 *
66 * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
67 * specified scope value in ScriptContexts of this type.
68 * @throws NullPointerException if value of scope is <code>ENGINE_SCOPE</code> and
69 * the specified <code>Bindings</code> is null.
70 *
71 */
72 public void setBindings(Bindings bindings, int scope);
73
74 /**
75 * Gets the <code>Bindings</code> associated with the given scope in this
76 * <code>ScriptContext</code>.
77 *
78 * @return The associated <code>Bindings</code>. Returns <code>null</code> if it has not
79 * been set.
80 *
81 * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the
82 * specified scope value in <code>ScriptContext</code> of this type.
83 */
84 public Bindings getBindings(int scope);
85
86 /**
87 * Sets the value of an attribute in a given scope.
88 *
89 * @param name The name of the attribute to set
90 * @param value The value of the attribute
91 * @param scope The scope in which to set the attribute
92 *
93 * @throws IllegalArgumentException
94 * if the name is empty or if the scope is invalid.
95 * @throws NullPointerException if the name is null.
96 */
97 public void setAttribute(String name, Object value, int scope);
98
99 /**
100 * Gets the value of an attribute in a given scope.
101 *
102 * @param name The name of the attribute to retrieve.
103 * @param scope The scope in which to retrieve the attribute.
104 * @return The value of the attribute. Returns <code>null</code> is the name
105 * does not exist in the given scope.
106 *
107 * @throws IllegalArgumentException
108 * if the name is empty or if the value of scope is invalid.
109 * @throws NullPointerException if the name is null.
110 */
111 public Object getAttribute(String name, int scope);
112
113 /**
114 * Remove an attribute in a given scope.
115 *
116 * @param name The name of the attribute to remove
117 * @param scope The scope in which to remove the attribute
118 *
119 * @return The removed value.
120 * @throws IllegalArgumentException
121 * if the name is empty or if the scope is invalid.
122 * @throws NullPointerException if the name is null.
123 */
124 public Object removeAttribute(String name, int scope);
125
126 /**
127 * Retrieves the value of the attribute with the given name in
128 * the scope occurring earliest in the search order. The order
129 * is determined by the numeric value of the scope parameter (lowest
130 * scope values first.)
131 *
132 * @param name The name of the the attribute to retrieve.
133 * @return The value of the attribute in the lowest scope for
134 * which an attribute with the given name is defined. Returns
135 * null if no attribute with the name exists in any scope.
136 * @throws NullPointerException if the name is null.
137 * @throws IllegalArgumentException if the name is empty.
138 */
139 public Object getAttribute(String name);
140
141
142 /**
143 * Get the lowest scope in which an attribute is defined.
144 * @param name Name of the attribute
145 * .
146 * @return The lowest scope. Returns -1 if no attribute with the given
147 * name is defined in any scope.
148 * @throws NullPointerException if name is null.
149 * @throws IllegalArgumentException if name is empty.
150 */
151 public int getAttributesScope(String name);
152
153 /**
154 * Returns the <code>Writer</code> for scripts to use when displaying output.
155 *
156 * @return The <code>Writer</code>.
157 */
158 public Writer getWriter();
159
160
161 /**
162 * Returns the <code>Writer</code> used to display error output.
163 *
164 * @return The <code>Writer</code>
165 */
166 public Writer getErrorWriter();
167
168 /**
169 * Sets the <code>Writer</code> for scripts to use when displaying output.
170 *
171 * @param writer The new <code>Writer</code>.
172 */
173 public void setWriter(Writer writer);
174
175
176 /**
177 * Sets the <code>Writer</code> used to display error output.
178 *
179 * @param writer The <code>Writer</code>.
180 */
181 public void setErrorWriter(Writer writer);
182
183 /**
184 * Returns a <code>Reader</code> to be used by the script to read
185 * input.
186 *
187 * @return The <code>Reader</code>.
188 */
189 public Reader getReader();
190
191
192 /**
193 * Sets the <code>Reader</code> for scripts to read input
194 * .
195 * @param reader The new <code>Reader</code>.
196 */
197 public void setReader(Reader reader);
198
199 /**
200 * Returns immutable <code>List</code> of all the valid values for
201 * scope in the ScriptContext.
202 *
203 * @return list of scope values
204 */
205 public List<Integer> getScopes();
206}