bsh
Class ScriptContextEngineView

java.lang.Object
  extended by bsh.ScriptContextEngineView
All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>

public class ScriptContextEngineView
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.Object>

This class implements an ENGINE_SCOPE centric Map view of the ScriptContext for engine implementations. This class can be used to simplify engine implementations which have the capability to bind their namespaces to Maps or other external interfaces.

Get operations on this view delegate to the ScriptContext inheriting get() method that automatically traverses the binding scopes in order or precedence. Put operations on this view always store values in the ENGINE_SCOPE bindings. Other operations such as size() and contains() are implemented appropriately, but perhaps not as efficiently as possible.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
ScriptContextEngineView(javax.script.ScriptContext context)
           
 
Method Summary
 void clear()
          Removes all mappings from this map (optional operation).
 boolean containsKey(java.lang.Object key)
          Returns true if the key name is bound in any scope in the context.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more keys to the specified value.
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
          Returns a set view of the mappings contained in this map.
 java.lang.Object get(java.lang.Object key)
          Returns the value bound in the most specific (lowest numbered) bindings space for this key.
 boolean isEmpty()
          Returns true if no bindings are present in any scope of the context.
 java.util.Set<java.lang.String> keySet()
          Returns the total key set of all scopes.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
          Set the key, value binding in the ENGINE_SCOPE of the context.
 void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> t)
          Put the bindings into the ENGINE_SCOPE of the context.
 java.lang.Object remove(java.lang.Object okey)
          Removes the mapping from the engine scope.
 int size()
          Returns the number of unique object bindings in all scopes.
 java.util.Collection<java.lang.Object> values()
          Returns the total values set of all scopes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ScriptContextEngineView

public ScriptContextEngineView(javax.script.ScriptContext context)
Method Detail

size

public int size()
Returns the number of unique object bindings in all scopes. (duplicate, shadowed, bindings count as a single binging).

Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>

isEmpty

public boolean isEmpty()
Returns true if no bindings are present in any scope of the context.

Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if the key name is bound in any scope in the context. The key must be a String.

Specified by:
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.
Throws:
java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the key is null and this map does not permit null keys (optional).

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of the Map interface.

Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.
Throws:
java.lang.ClassCastException - if the value is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the value is null and this map does not permit null values (optional).

get

public java.lang.Object get(java.lang.Object key)
Returns the value bound in the most specific (lowest numbered) bindings space for this key. key must be a String.

Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
Throws:
java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the key is null and this map does not permit null keys (optional).
See Also:
containsKey(Object)

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)
Set the key, value binding in the ENGINE_SCOPE of the context.

Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
java.lang.NullPointerException - if this map does not permit null keys or values, and the specified key or value is null.

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> t)
Put the bindings into the ENGINE_SCOPE of the context.

Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
t - Mappings to be stored in this map.
Throws:
java.lang.UnsupportedOperationException - if the putAll method is not supported by this map.
java.lang.ClassCastException - if the class of a key or value in the specified map prevents it from being stored in this map.
java.lang.IllegalArgumentException - some aspect of a key or value in the specified map prevents it from being stored in this map.
java.lang.NullPointerException - if the specified map is null, or if this map does not permit null keys or values, and the specified map contains null keys or values.

remove

public java.lang.Object remove(java.lang.Object okey)
Removes the mapping from the engine scope.

Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. (A null return can also indicate that the map previously associated null with the specified key if the implementation supports null values.) The map will not contain a mapping for the specified key once the call returns.

Specified by:
remove in interface java.util.Map<java.lang.String,java.lang.Object>
Parameters:
okey - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no mapping for key.
Throws:
java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the key is null and this map does not permit null keys (optional).
java.lang.UnsupportedOperationException - if the remove method is not supported by this map.

clear

public void clear()
Removes all mappings from this map (optional operation).

Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>
Throws:
java.lang.UnsupportedOperationException - clear is not supported by this map.

keySet

public java.util.Set<java.lang.String> keySet()
Returns the total key set of all scopes. This method violates the Map contract by returning an unmodifiable set.

Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>
Returns:
a set view of the keys contained in this map.

values

public java.util.Collection<java.lang.Object> values()
Returns the total values set of all scopes. This method violates the Map contract by returning an unmodifiable set.

Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>
Returns:
a collection view of the values contained in this map.

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>
Returns:
a set view of the mappings contained in this map.


? 2000-2005 pat@pat.net :-)