Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.scripting/share/classes/javax/script/CompiledScript.java
41153 views
1
/*
2
* Copyright (c) 2005, 2020, 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
26
package javax.script;
27
28
import java.util.Map;
29
30
/**
31
* Extended by classes that store results of compilations. State
32
* might be stored in the form of Java classes, Java class files or scripting
33
* language opcodes. The script may be executed repeatedly
34
* without reparsing.
35
* <br><br>
36
* Each <code>CompiledScript</code> is associated with a <code>ScriptEngine</code> -- A call to an <code>eval</code>
37
* method of the <code>CompiledScript</code> causes the execution of the script by the
38
* <code>ScriptEngine</code>. Changes in the state of the <code>ScriptEngine</code> caused by execution
39
* of the <code>CompiledScript</code> may visible during subsequent executions of scripts by the engine.
40
*
41
* @author Mike Grogan
42
* @since 1.6
43
*/
44
public abstract class CompiledScript {
45
/**
46
* Constructor for subclasses to call.
47
*/
48
public CompiledScript() {}
49
50
/**
51
* Executes the program stored in this <code>CompiledScript</code> object.
52
*
53
* @param context A <code>ScriptContext</code> that is used in the same way as
54
* the <code>ScriptContext</code> passed to the <code>eval</code> methods of
55
* <code>ScriptEngine</code>.
56
*
57
* @return The value returned by the script execution, if any. Should return <code>null</code>
58
* if no value is returned by the script execution.
59
*
60
* @throws ScriptException if an error occurs.
61
* @throws NullPointerException if context is null.
62
*/
63
64
public abstract Object eval(ScriptContext context) throws ScriptException;
65
66
/**
67
* Executes the program stored in the <code>CompiledScript</code> object using
68
* the supplied <code>Bindings</code> of attributes as the <code>ENGINE_SCOPE</code> of the
69
* associated <code>ScriptEngine</code> during script execution. If bindings is null,
70
* then the effect of calling this method is same as that of eval(getEngine().getContext()).
71
* <p>.
72
* The <code>GLOBAL_SCOPE</code> <code>Bindings</code>, <code>Reader</code> and <code>Writer</code>
73
* associated with the default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> are used.
74
*
75
* @param bindings The bindings of attributes used for the <code>ENGINE_SCOPE</code>.
76
*
77
* @return The return value from the script execution
78
*
79
* @throws ScriptException if an error occurs.
80
*/
81
public Object eval(Bindings bindings) throws ScriptException {
82
83
ScriptContext ctxt = getEngine().getContext();
84
85
if (bindings != null) {
86
SimpleScriptContext tempctxt = new SimpleScriptContext(ctxt.getReader(), ctxt.getWriter(), ctxt.getErrorWriter());
87
tempctxt.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
88
tempctxt.setBindings(ctxt.getBindings(ScriptContext.GLOBAL_SCOPE),
89
ScriptContext.GLOBAL_SCOPE);
90
ctxt = tempctxt;
91
}
92
93
return eval(ctxt);
94
}
95
96
97
/**
98
* Executes the program stored in the <code>CompiledScript</code> object. The
99
* default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> is used.
100
* The effect of calling this method is same as that of eval(getEngine().getContext()).
101
*
102
* @return The return value from the script execution
103
*
104
* @throws ScriptException if an error occurs.
105
*/
106
public Object eval() throws ScriptException {
107
return eval(getEngine().getContext());
108
}
109
110
/**
111
* Returns the <code>ScriptEngine</code> whose <code>compile</code> method created this <code>CompiledScript</code>.
112
* The <code>CompiledScript</code> will execute in this engine.
113
*
114
* @return The <code>ScriptEngine</code> that created this <code>CompiledScript</code>
115
*/
116
public abstract ScriptEngine getEngine();
117
118
}
119
120