Class AbstractScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
- All Implemented Interfaces:
- ScriptEngine
Provides a standard implementation for several of the variants of the 
eval
method.
eval(Reader)eval(String)
eval(String, Bindings)
eval(Reader, Bindings)
 are implemented using the abstract methods
eval(Reader,ScriptContext) or
eval(String, ScriptContext)
with a SimpleScriptContext.
A SimpleScriptContext is used as the default ScriptContext
of the AbstractScriptEngine..
- Since:
- 1.6
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ScriptContextThe defaultScriptContextof thisAbstractScriptEngine.Fields declared in interface ScriptEngineARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new instance of AbstractScriptEngine using aSimpleScriptContextas its defaultScriptContext.Creates a new instance using the specifiedBindingsas theENGINE_SCOPEBindingsin the protectedcontextfield.
- 
Method SummaryModifier and TypeMethodDescriptioneval(Reader)calls the abstracteval(Reader, ScriptContext)passing the value of thecontextfield.eval(Reader, Bindings)calls the abstracteval(Reader, ScriptContext)method, passing it aScriptContextwhose Reader, Writers and Bindings for scopes other thatENGINE_SCOPEare identical to those members of the protectedcontextfield.Same aseval(Reader)except that the abstracteval(String, ScriptContext)is used.Same aseval(Reader, Bindings)except that the abstracteval(String, ScriptContext)is used.Gets the value for the specified key in theENGINE_SCOPEof the protectedcontextfield.getBindings(int scope) Returns theBindingswith the specified scope value in the protectedcontextfield.Returns the value of the protectedcontextfield.protected ScriptContextReturns aSimpleScriptContext.voidSets the specified value with the specified key in theENGINE_SCOPEBindingsof the protectedcontextfield.voidsetBindings(Bindings bindings, int scope) Sets theBindingswith the corresponding scope value in thecontextfield.voidsetContext(ScriptContext ctxt) Sets the value of the protectedcontextfield to the specifiedScriptContext.Methods declared in class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface ScriptEnginecreateBindings, eval, eval, getFactory
- 
Field Details- 
contextThe defaultScriptContextof thisAbstractScriptEngine.
 
- 
- 
Constructor Details- 
AbstractScriptEnginepublic AbstractScriptEngine()Creates a new instance of AbstractScriptEngine using aSimpleScriptContextas its defaultScriptContext.
- 
AbstractScriptEngineCreates a new instance using the specifiedBindingsas theENGINE_SCOPEBindingsin the protectedcontextfield.- Parameters:
- n- The specified- Bindings.
- Throws:
- NullPointerException- if n is null.
 
 
- 
- 
Method Details- 
setContextSets the value of the protectedcontextfield to the specifiedScriptContext.- Specified by:
- setContextin interface- ScriptEngine
- Parameters:
- ctxt- The specified- ScriptContext.
- Throws:
- NullPointerException- if ctxt is null.
 
- 
getContextReturns the value of the protectedcontextfield.- Specified by:
- getContextin interface- ScriptEngine
- Returns:
- The value of the protected contextfield.
 
- 
getBindingsReturns theBindingswith the specified scope value in the protectedcontextfield.- Specified by:
- getBindingsin interface- ScriptEngine
- Parameters:
- scope- The specified scope
- Returns:
- The corresponding Bindings.
- Throws:
- IllegalArgumentException- if the value of scope is invalid for the type the protected- contextfield.
 
- 
setBindingsSets theBindingswith the corresponding scope value in thecontextfield.- Specified by:
- setBindingsin interface- ScriptEngine
- Parameters:
- bindings- The specified- Bindings.
- scope- The specified scope.
- Throws:
- IllegalArgumentException- if the value of scope is invalid for the type the- contextfield.
- NullPointerException- if the bindings is null and the scope is- ScriptContext.ENGINE_SCOPE
 
- 
putSets the specified value with the specified key in theENGINE_SCOPEBindingsof the protectedcontextfield.- Specified by:
- putin interface- ScriptEngine
- Parameters:
- key- The specified key.
- value- The specified value.
- Throws:
- NullPointerException- if key is null.
- IllegalArgumentException- if key is empty.
 
- 
getGets the value for the specified key in theENGINE_SCOPEof the protectedcontextfield.- Specified by:
- getin interface- ScriptEngine
- Parameters:
- key- The key whose value is to be returned
- Returns:
- The value for the specified key.
- Throws:
- NullPointerException- if key is null.
- IllegalArgumentException- if key is empty.
 
- 
evaleval(Reader, Bindings)calls the abstracteval(Reader, ScriptContext)method, passing it aScriptContextwhose Reader, Writers and Bindings for scopes other thatENGINE_SCOPEare identical to those members of the protectedcontextfield. The specifiedBindingsis used instead of theENGINE_SCOPEBindingsof thecontextfield.- Specified by:
- evalin interface- ScriptEngine
- Parameters:
- reader- A- Readercontaining the source of the script.
- bindings- A- Bindingsto use for the- ENGINE_SCOPEwhile the script executes.
- Returns:
- The return value from eval(Reader, ScriptContext)
- Throws:
- ScriptException- if an error occurs in script.
- NullPointerException- if any of the parameters is null.
 
- 
evalSame aseval(Reader, Bindings)except that the abstracteval(String, ScriptContext)is used.- Specified by:
- evalin interface- ScriptEngine
- Parameters:
- script- A- Stringcontaining the source of the script.
- bindings- A- Bindingsto use as the- ENGINE_SCOPEwhile the script executes.
- Returns:
- The return value from eval(String, ScriptContext)
- Throws:
- ScriptException- if an error occurs in script.
- NullPointerException- if any of the parameters is null.
 
- 
evaleval(Reader)calls the abstracteval(Reader, ScriptContext)passing the value of thecontextfield.- Specified by:
- evalin interface- ScriptEngine
- Parameters:
- reader- A- Readercontaining the source of the script.
- Returns:
- The return value from eval(Reader, ScriptContext)
- Throws:
- ScriptException- if an error occurs in script.
- NullPointerException- if any of the parameters is null.
 
- 
evalSame aseval(Reader)except that the abstracteval(String, ScriptContext)is used.- Specified by:
- evalin interface- ScriptEngine
- Parameters:
- script- A- Stringcontaining the source of the script.
- Returns:
- The return value from eval(String, ScriptContext)
- Throws:
- ScriptException- if an error occurs in script.
- NullPointerException- if any of the parameters is null.
 
- 
getScriptContextReturns aSimpleScriptContext. TheSimpleScriptContext:
 - Uses the specified Bindingsfor itsENGINE_SCOPE
- Uses the Bindingsreturned by the abstractgetGlobalScopemethod as itsGLOBAL_SCOPE
- Uses the Reader and Writer in the default ScriptContextof thisScriptEngine
 
 ASimpleScriptContextreturned by this method is used to implement eval methods using the abstracteval(Reader,Bindings)andeval(String,Bindings)versions.- Parameters:
- nn- Bindings to use for the- ENGINE_SCOPE
- Returns:
- The SimpleScriptContext
 
- Uses the specified 
 
-