0N/A/*
3909N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.script;
0N/A
0N/Aimport java.util.Map;
0N/A
0N/A/**
0N/A * Extended by classes that store results of compilations. State
0N/A * might be stored in the form of Java classes, Java class files or scripting
0N/A * language opcodes. The script may be executed repeatedly
0N/A * without reparsing.
0N/A * <br><br>
0N/A * Each <code>CompiledScript</code> is associated with a <code>ScriptEngine</code> -- A call to an <code>eval</code>
0N/A * method of the <code>CompiledScript</code> causes the execution of the script by the
0N/A * <code>ScriptEngine</code>. Changes in the state of the <code>ScriptEngine</code> caused by execution
0N/A * of tne <code>CompiledScript</code> may visible during subsequent executions of scripts by the engine.
0N/A *
0N/A * @author Mike Grogan
0N/A * @since 1.6
0N/A */
0N/Apublic abstract class CompiledScript {
0N/A
0N/A /**
0N/A * Executes the program stored in this <code>CompiledScript</code> object.
0N/A *
0N/A * @param context A <code>ScriptContext</code> that is used in the same way as
0N/A * the <code>ScriptContext</code> passed to the <code>eval</code> methods of
0N/A * <code>ScriptEngine</code>.
0N/A *
0N/A * @return The value returned by the script execution, if any. Should return <code>null</code>
0N/A * if no value is returned by the script execution.
0N/A *
0N/A * @throws ScriptException if an error occurs.
0N/A * @throws NullPointerException if context is null.
0N/A */
0N/A
0N/A public abstract Object eval(ScriptContext context) throws ScriptException;
0N/A
0N/A /**
0N/A * Executes the program stored in the <code>CompiledScript</code> object using
0N/A * the supplied <code>Bindings</code> of attributes as the <code>ENGINE_SCOPE</code> of the
0N/A * associated <code>ScriptEngine</code> during script execution. If bindings is null,
0N/A * then the effect of calling this method is same as that of eval(getEngine().getContext()).
0N/A * <p>.
0N/A * The <code>GLOBAL_SCOPE</code> <code>Bindings</code>, <code>Reader</code> and <code>Writer</code>
0N/A * associated with the default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> are used.
0N/A *
0N/A * @param bindings The bindings of attributes used for the <code>ENGINE_SCOPE</code>.
0N/A *
0N/A * @return The return value from the script execution
0N/A *
0N/A * @throws ScriptException if an error occurs.
0N/A */
0N/A public Object eval(Bindings bindings) throws ScriptException {
0N/A
0N/A ScriptContext ctxt = getEngine().getContext();
0N/A
0N/A if (bindings != null) {
0N/A SimpleScriptContext tempctxt = new SimpleScriptContext();
0N/A tempctxt.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
0N/A tempctxt.setBindings(ctxt.getBindings(ScriptContext.GLOBAL_SCOPE),
0N/A ScriptContext.GLOBAL_SCOPE);
0N/A tempctxt.setWriter(ctxt.getWriter());
0N/A tempctxt.setReader(ctxt.getReader());
0N/A tempctxt.setErrorWriter(ctxt.getErrorWriter());
0N/A ctxt = tempctxt;
0N/A }
0N/A
0N/A return eval(ctxt);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Executes the program stored in the <code>CompiledScript</code> object. The
0N/A * default <code>ScriptContext</code> of the associated <code>ScriptEngine</code> is used.
0N/A * The effect of calling this method is same as that of eval(getEngine().getContext()).
0N/A *
0N/A * @return The return value from the script execution
0N/A *
0N/A * @throws ScriptException if an error occurs.
0N/A */
0N/A public Object eval() throws ScriptException {
0N/A return eval(getEngine().getContext());
0N/A }
0N/A
0N/A /**
3402N/A * Returns the <code>ScriptEngine</code> whose <code>compile</code> method created this <code>CompiledScript</code>.
0N/A * The <code>CompiledScript</code> will execute in this engine.
0N/A *
0N/A * @return The <code>ScriptEngine</code> that created this <code>CompiledScript</code>
0N/A */
0N/A public abstract ScriptEngine getEngine();
0N/A
0N/A}