bsh

Class ExternalNameSpace

Implemented Interfaces:
java.io.Serializable, BshClassManager.Listener, NameSource

public class ExternalNameSpace
extends NameSpace

A namespace which maintains an external map of values held in variables in its scope. This mechanism provides a standard collections based interface to the namespace as well as a convenient way to export and view values of the namespace without the ordinary BeanShell wrappers. Variables are maintained internally in the normal fashion to support meta-information (such as variable type and visibility modifiers), but exported and imported in a synchronized way. Variables are exported each time they are written by BeanShell. Imported variables from the map appear in the BeanShell namespace as untyped variables with no modifiers and shadow any previously defined variables in the scope.

Note: this class is inherentely dependent on Java 1.2, however it is not used directly by the core as other than type NameSpace, so no dependency is introduced.

See Also:
Serialized Form

Nested Class Summary

Field Summary

Fields inherited from class bsh.NameSpace

JAVACODE, importedClasses

Constructor Summary

ExternalNameSpace()
ExternalNameSpace(NameSpace parent, String name, Map externalMap)

Method Summary

void
clear()
Clear all variables, methods, and imports from this namespace and clear all values from the external map (via Map clear()).
protected void
getAllNamesAux(Vector vec)
Variable[]
getDeclaredVariables()
Map
getMap()
Get the map view of this namespace.
BshMethod
getMethod(String name, Class[] sig, boolean declaredOnly)
protected Variable
getVariableImpl(String name, boolean recurse)
String[]
getVariableNames()
protected void
putExternalMap(String name, Object value)
Place an unwrapped value in the external map.
void
setMap(Map map)
Set the external Map which to which this namespace synchronizes.
void
setMethod(String name, BshMethod method)
void
setTypedVariable(String name, Class type, Object value, Modifiers modifiers)
void
unsetVariable(String name)

Methods inherited from class bsh.NameSpace

addNameSourceListener, classLoaderChanged, clear, doSuperImport, get, getAllNames, getAllNamesAux, getClass, getClassManager, getCommand, getDeclaredVariables, getGlobal, getImportedMethod, getImportedVar, getInvocationLine, getInvocationText, getMethod, getMethod, getMethodNames, getMethods, getName, getParent, getSuper, getVariable, getVariable, getVariableImpl, getVariableNames, identifierToClass, importClass, importCommands, importObject, importPackage, importStatic, invokeMethod, invokeMethod, loadDefaultImports, nameSpaceChanged, prune, setMethod, setName, setParent, setTypedVariable, setTypedVariable, setVariable, toString, unsetVariable, unwrapVariable

Constructor Details

ExternalNameSpace

public ExternalNameSpace()


ExternalNameSpace

public ExternalNameSpace(NameSpace parent,
                         String name,
                         Map externalMap)

Method Details

clear

public void clear()
Clear all variables, methods, and imports from this namespace and clear all values from the external map (via Map clear()).
Overrides:
clear in interface NameSpace


getAllNamesAux

protected void getAllNamesAux(Vector vec)
Overrides:
getAllNamesAux in interface NameSpace


getDeclaredVariables

public Variable[] getDeclaredVariables()
Overrides:
getDeclaredVariables in interface NameSpace


getMap

public Map getMap()
Get the map view of this namespace.


getMethod

public BshMethod getMethod(String name,
                           Class[] sig,
                           boolean declaredOnly)
            throws UtilEvalError
Overrides:
getMethod in interface NameSpace


getVariableImpl

protected Variable getVariableImpl(String name,
                                   boolean recurse)
            throws UtilEvalError
Overrides:
getVariableImpl in interface NameSpace


getVariableNames

public String[] getVariableNames()
Overrides:
getVariableNames in interface NameSpace


putExternalMap

protected void putExternalMap(String name,
                              Object value)
Place an unwrapped value in the external map. BeanShell primitive types are represented by their object wrappers, so it is not possible to differentiate between wrapper types and primitive types via the external Map.


setMap

public void setMap(Map map)
Set the external Map which to which this namespace synchronizes. The previous external map is detached from this namespace. Previous map values are retained in the external map, but are removed from the BeanShell namespace.


setMethod

public void setMethod(String name,
                      BshMethod method)
            throws UtilEvalError
Overrides:
setMethod in interface NameSpace


setTypedVariable

public void setTypedVariable(String name,
                             Class type,
                             Object value,
                             Modifiers modifiers)
            throws UtilEvalError
Overrides:
setTypedVariable in interface NameSpace


unsetVariable

public void unsetVariable(String name)
Overrides:
unsetVariable in interface NameSpace


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