FileDocCategorySizeDatePackage
CompiledScript.javaAPI DocJava SE 6 API4064Tue Jun 10 00:26:26 BST 2008javax.script

CompiledScript

public abstract class CompiledScript extends Object
Extended by classes that store results of compilations. State might be stored in the form of Java classes, Java class files or scripting language opcodes. The script may be executed repeatedly without reparsing.

Each CompiledScript is associated with a ScriptEngine -- A call to an eval method of the CompiledScript causes the execution of the script by the ScriptEngine. Changes in the state of the ScriptEngine caused by execution of tne CompiledScript may visible during subsequent executions of scripts by the engine.
author
Mike Grogan
version
1.0
since
1.6

Fields Summary
Constructors Summary
Methods Summary
public abstract java.lang.Objecteval(javax.script.ScriptContext context)
Executes the program stored in this CompiledScript object.

param
context A ScriptContext that is used in the same way as the ScriptContext passed to the eval methods of ScriptEngine.
return
The value returned by the script execution, if any. Should return null if no value is returned by the script execution.
throws
ScriptException if an error occurs.
throws
NullPointerException if context is null.

public java.lang.Objecteval(javax.script.Bindings bindings)
Executes the program stored in the CompiledScript object using the supplied Bindings of attributes as the ENGINE_SCOPE of the associated ScriptEngine during script execution. If bindings is null, then the effect of calling this method is same as that of eval(getEngine().getContext()).

. The GLOBAL_SCOPE Bindings, Reader and Writer associated with the default ScriptContext of the associated ScriptEngine are used.

param
bindings The bindings of attributes used for the ENGINE_SCOPE.
return
The return value from the script execution
throws
ScriptException if an error occurs.

        
        ScriptContext ctxt = getEngine().getContext();
        
        if (bindings != null) {
            SimpleScriptContext tempctxt = new SimpleScriptContext();
            tempctxt.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
            tempctxt.setBindings(ctxt.getBindings(ScriptContext.GLOBAL_SCOPE),
                    ScriptContext.GLOBAL_SCOPE);
            tempctxt.setWriter(ctxt.getWriter());
            tempctxt.setReader(ctxt.getReader());
            tempctxt.setErrorWriter(ctxt.getErrorWriter());
            ctxt = tempctxt;
        }
        
        return eval(ctxt);
    
public java.lang.Objecteval()
Executes the program stored in the CompiledScript object. The default ScriptContext of the associated ScriptEngine is used. The effect of calling this method is same as that of eval(getEngine().getContext()).

return
The return value from the script execution
throws
ScriptException if an error occurs.

        return eval(getEngine().getContext());
    
public abstract javax.script.ScriptEnginegetEngine()
Returns the ScriptEngine wbose compile method created this CompiledScript. The CompiledScript will execute in this engine.

return
The ScriptEngine that created this CompiledScript