The interface whose implementing classes are used to connect Script Engines with objects, such as scoped Bindings, in hosting applications. Each scope is a set of named attributes whose values can be set and retrieved using the ScriptContext methods. ScriptContexts also expose Readers
| 22 | * @since 1.6 |
| 23 | */ |
| 24 | public interface ScriptContext { |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * EngineScope attributes are visible during the lifetime of a single |
| 29 | * <code>ScriptEngine</code> and a set of attributes is maintained for each |
| 30 | * engine. |
| 31 | */ |
| 32 | public static final int ENGINE_SCOPE = 100; |
| 33 | |
| 34 | /** |
| 35 | * GlobalScope attributes are visible to all engines created by same ScriptEngineFactory. |
| 36 | */ |
| 37 | public static final int GLOBAL_SCOPE = 200; |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Associates a <code>Bindings</code> instance with a particular scope in this |
| 42 | * <code>ScriptContext</code>. Calls to the <code>getAttribute</code> and |
| 43 | * <code>setAttribute</code> methods must map to the <code>put</code> and |
| 44 | * <code>get</code> methods of the <code>Bindings</code> for the specified scope. |
| 45 | * |
| 46 | * @param bindings The <code>Bindings</code> to associate with the given scope |
| 47 | * @param scope The scope |
| 48 | * |
| 49 | * @throws <code>IllegalArgumentException</code> If no <code>Bindings</code> is defined for the |
| 50 | * specified scope value in ScriptContexts of this type. |
| 51 | * @throws <code>NullPointerException</code> if value of scope is <code>ENGINE_SCOPE</code> and |
| 52 | * the specified <code>Bindings</code> is null. |
| 53 | * |
| 54 | */ |
| 55 | public void setBindings(Bindings bindings, int scope); |
| 56 | |
| 57 | /** |
| 58 | * Gets the <code>Bindings</code> associated with the given scope in this |
| 59 | * <code>ScriptContext</code>. |
| 60 | * |
| 61 | * @return The associated <code>Bindings</code>. Returns <code>null</code> if it has not |
| 62 | * been set. |
| 63 | * |
| 64 | * @throws IllegalArgumentException If no <code>Bindings</code> is defined for the |
| 65 | * specified scope value in <code>ScriptContext</code> of this type. |
| 66 | */ |
| 67 | public Bindings getBindings(int scope); |
| 68 | |
| 69 | /** |
| 70 | * Sets the value of an attribute in a given scope. |
| 71 | * |
| 72 | * @param name The name of the attribute to set. |
| 73 | * @param scope The scope in which to set the attribute |
| 74 | * |
| 75 | * @throws <code>IllegalArgumentException</code> if the scope |
| 76 | * is invalid. |
| 77 | * @throws <code>NullPointerException</code> if the name is null. |
| 78 | * @throws <code>ClassCastException</code> if the name is not a String. |
| 79 | */ |
| 80 | public void setAttribute(String name, Object value, int scope); |
| 81 |
no outgoing calls
no test coverage detected