SimpleScriptContext (Java SE 12 & JDK 12 ) (original) (raw)
- javax.script.SimpleScriptContext
All Implemented Interfaces:
[ScriptContext](ScriptContext.html "interface in javax.script")
public class SimpleScriptContext
extends Object
implements ScriptContext
Simple implementation of ScriptContext.
Since:
1.6
Field Summary
Fields
Modifier and Type Field Description protected Bindings engineScope This is the engine scope bindings. protected Writer errorWriter This is the writer to be used to output errors from scripts. protected Bindings globalScope This is the global scope bindings. protected Reader reader This is the reader to be used for input from scripts. protected Writer writer This is the writer to be used to output from scripts. * ### Fields declared in interface javax.script.[ScriptContext](ScriptContext.html "interface in javax.script") `[ENGINE_SCOPE](ScriptContext.html#ENGINE%5FSCOPE), [GLOBAL_SCOPE](ScriptContext.html#GLOBAL%5FSCOPE)`
Constructor Summary
Constructors
Constructor Description SimpleScriptContext() Create a SimpleScriptContext. Method Summary
Modifier and Type Method Description Object getAttribute(String name) Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order. Object getAttribute(String name, int scope) Gets the value of an attribute in a given scope. int getAttributesScope(String name) Get the lowest scope in which an attribute is defined. Bindings getBindings(int scope) Returns the value of the engineScope field if specified scope isENGINE_SCOPE. Object removeAttribute(String name, int scope) Remove an attribute in a given scope. void setAttribute(String name,Object value, int scope) Sets the value of an attribute in a given scope. void setBindings(Bindings bindings, int scope) Sets a Bindings of attributes for the given scope. * ### Methods declared in class java.lang.[Object](../../../java.base/java/lang/Object.html "class in java.lang") `[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)` * ### Methods declared in interface javax.script.[ScriptContext](ScriptContext.html "interface in javax.script") `[getErrorWriter](ScriptContext.html#getErrorWriter%28%29), [getReader](ScriptContext.html#getReader%28%29), [getScopes](ScriptContext.html#getScopes%28%29), [getWriter](ScriptContext.html#getWriter%28%29), [setErrorWriter](ScriptContext.html#setErrorWriter%28java.io.Writer%29), [setReader](ScriptContext.html#setReader%28java.io.Reader%29), [setWriter](ScriptContext.html#setWriter%28java.io.Writer%29)`
Field Detail
* #### writer protected [Writer](../../../java.base/java/io/Writer.html "class in java.io") writer This is the writer to be used to output from scripts. By default, a `PrintWriter` based on `System.out` is used. Accessor methods getWriter, setWriter are used to manage this field. See Also: [System.out](../../../java.base/java/lang/System.html#out), [PrintWriter](../../../java.base/java/io/PrintWriter.html "class in java.io") * #### errorWriter protected [Writer](../../../java.base/java/io/Writer.html "class in java.io") errorWriter This is the writer to be used to output errors from scripts. By default, a `PrintWriter` based on `System.err` is used. Accessor methods getErrorWriter, setErrorWriter are used to manage this field. See Also: [System.err](../../../java.base/java/lang/System.html#err), [PrintWriter](../../../java.base/java/io/PrintWriter.html "class in java.io") * #### reader protected [Reader](../../../java.base/java/io/Reader.html "class in java.io") reader This is the reader to be used for input from scripts. By default, a `InputStreamReader` based on `System.in` is used and default charset is used by this reader. Accessor methods getReader, setReader are used to manage this field. See Also: [System.in](../../../java.base/java/lang/System.html#in), [InputStreamReader](../../../java.base/java/io/InputStreamReader.html "class in java.io") * #### engineScope protected [Bindings](Bindings.html "interface in javax.script") engineScope This is the engine scope bindings. By default, a `SimpleBindings` is used. Accessor methods setBindings, getBindings are used to manage this field. See Also: [SimpleBindings](SimpleBindings.html "class in javax.script") * #### globalScope protected [Bindings](Bindings.html "interface in javax.script") globalScope This is the global scope bindings. By default, a null value (which means no global scope) is used. Accessor methods setBindings, getBindings are used to manage this field.
Constructor Detail
* #### SimpleScriptContext public SimpleScriptContext() Create a `SimpleScriptContext`.
Method Detail
* #### setBindings public void setBindings([Bindings](Bindings.html "interface in javax.script") bindings, int scope) Sets a `Bindings` of attributes for the given scope. If the value of scope is `ENGINE_SCOPE` the given `Bindings` replaces the`engineScope` field. If the value of scope is `GLOBAL_SCOPE` the given `Bindings` replaces the`globalScope` field. Specified by: `[setBindings](ScriptContext.html#setBindings%28javax.script.Bindings,int%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `bindings` \- The `Bindings` of attributes to set. `scope` \- The value of the scope in which the attributes are set. Throws: `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if scope is invalid. `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if the value of scope is `ENGINE_SCOPE` and the specified `Bindings` is null. * #### getAttribute public [Object](../../../java.base/java/lang/Object.html "class in java.lang") getAttribute([String](../../../java.base/java/lang/String.html "class in java.lang") name) Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order. The order is determined by the numeric value of the scope parameter (lowest scope values first.) Specified by: `[getAttribute](ScriptContext.html#getAttribute%28java.lang.String%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `name` \- The name of the attribute to retrieve. Returns: The value of the attribute in the lowest scope for which an attribute with the given name is defined. Returns null if no attribute with the name exists in any scope. Throws: `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if the name is null. `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if the name is empty. * #### getAttribute public [Object](../../../java.base/java/lang/Object.html "class in java.lang") getAttribute([String](../../../java.base/java/lang/String.html "class in java.lang") name, int scope) Gets the value of an attribute in a given scope. Specified by: `[getAttribute](ScriptContext.html#getAttribute%28java.lang.String,int%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `name` \- The name of the attribute to retrieve. `scope` \- The scope in which to retrieve the attribute. Returns: The value of the attribute. Returns `null` is the name does not exist in the given scope. Throws: `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if the name is empty or if the value of scope is invalid. `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if the name is null. * #### removeAttribute public [Object](../../../java.base/java/lang/Object.html "class in java.lang") removeAttribute([String](../../../java.base/java/lang/String.html "class in java.lang") name, int scope) Remove an attribute in a given scope. Specified by: `[removeAttribute](ScriptContext.html#removeAttribute%28java.lang.String,int%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `name` \- The name of the attribute to remove `scope` \- The scope in which to remove the attribute Returns: The removed value. Throws: `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if the name is empty or if the scope is invalid. `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if the name is null. * #### setAttribute public void setAttribute([String](../../../java.base/java/lang/String.html "class in java.lang") name, [Object](../../../java.base/java/lang/Object.html "class in java.lang") value, int scope) Sets the value of an attribute in a given scope. If the scope is `GLOBAL_SCOPE` and no Bindings is set for `GLOBAL_SCOPE`, then setAttribute call is a no-op. Specified by: `[setAttribute](ScriptContext.html#setAttribute%28java.lang.String,java.lang.Object,int%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `name` \- The name of the attribute to set `value` \- The value of the attribute `scope` \- The scope in which to set the attribute Throws: `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if the name is empty or if the scope is invalid. `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if the name is null. * #### getAttributesScope public int getAttributesScope([String](../../../java.base/java/lang/String.html "class in java.lang") name) Get the lowest scope in which an attribute is defined. Specified by: `[getAttributesScope](ScriptContext.html#getAttributesScope%28java.lang.String%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `name` \- Name of the attribute . Returns: The lowest scope. Returns -1 if no attribute with the given name is defined in any scope. Throws: `[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if name is null. `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if name is empty. * #### getBindings public [Bindings](Bindings.html "interface in javax.script") getBindings(int scope) Returns the value of the `engineScope` field if specified scope is`ENGINE_SCOPE`. Returns the value of the `globalScope` field if the specified scope is`GLOBAL_SCOPE`. Specified by: `[getBindings](ScriptContext.html#getBindings%28int%29)` in interface `[ScriptContext](ScriptContext.html "interface in javax.script")` Parameters: `scope` \- The specified scope Returns: The value of either the `engineScope` or `globalScope` field. Throws: `[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")` \- if the value of scope is invalid.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2019, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.