Package bsh
Class ExternalNameSpace
- java.lang.Object
-
- bsh.NameSpace
-
- bsh.ExternalNameSpace
-
- All Implemented Interfaces:
BshClassManager.Listener
,NameSource
,Serializable
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
-
Nested classes/interfaces inherited from interface bsh.NameSource
NameSource.Listener
-
-
Field Summary
-
Fields inherited from class bsh.NameSpace
importedClasses, JAVACODE
-
-
Constructor Summary
Constructors Constructor Description ExternalNameSpace()
ExternalNameSpace(NameSpace parent, String name, Map externalMap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
Helper for implementing NameSourceVariable[]
getDeclaredVariables()
Map
getMap()
Get the map view of this namespace.BshMethod
getMethod(String name, Class[] sig, boolean declaredOnly)
Get the bsh method matching the specified signature declared in this name space or a parent.protected Variable
getVariableImpl(String name, boolean recurse)
Locate a variable and return the Variable object with optional recursion through parent name spaces.String[]
getVariableNames()
Get the names of variables defined in this namespace.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)
Note: this is primarily for internal use.void
setTypedVariable(String name, Class type, Object value, Modifiers modifiers)
Declare a variable in the local scope and set its initial value.void
unsetVariable(String name)
Remove the variable from the namespace.-
Methods inherited from class bsh.NameSpace
addNameSourceListener, classLoaderChanged, doSuperImport, get, getAllNames, getClass, getClassManager, getCommand, getGlobal, getImportedMethod, getImportedVar, getInvocationLine, getInvocationText, getMethod, getMethodNames, getMethods, getName, getParent, getSuper, getVariable, getVariable, identifierToClass, importClass, importCommands, importObject, importPackage, importStatic, invokeMethod, invokeMethod, loadDefaultImports, nameSpaceChanged, prune, setName, setParent, setTypedVariable, setVariable, toString, unwrapVariable
-
-
-
-
Method Detail
-
getMap
public Map getMap()
Get the map view of this namespace.
-
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.
-
unsetVariable
public void unsetVariable(String name)
Description copied from class:NameSpace
Remove the variable from the namespace.- Overrides:
unsetVariable
in classNameSpace
-
getVariableNames
public String[] getVariableNames()
Description copied from class:NameSpace
Get the names of variables defined in this namespace. (This does not show variables in parent namespaces).- Overrides:
getVariableNames
in classNameSpace
-
getVariableImpl
protected Variable getVariableImpl(String name, boolean recurse) throws UtilEvalError
Description copied from class:NameSpace
Locate a variable and return the Variable object with optional recursion through parent name spaces. If this namespace is static, return only static variables.- Overrides:
getVariableImpl
in classNameSpace
- Returns:
- the Variable value or null if it is not defined
- Throws:
UtilEvalError
-
getDeclaredVariables
public Variable[] getDeclaredVariables()
- Overrides:
getDeclaredVariables
in classNameSpace
-
setTypedVariable
public void setTypedVariable(String name, Class type, Object value, Modifiers modifiers) throws UtilEvalError
Description copied from class:NameSpace
Declare a variable in the local scope and set its initial value. Value may be null to indicate that we would like the default value for the variable type. (e.g. 0 for integer types, null for object types). An existing typed variable may only be set to the same type. If an untyped variable of the same name exists it will be overridden with the new typed var. The set will perform a Types.getAssignableForm() on the value if necessary.Note: this method is primarily intended for use internally. If you use this method outside of the bsh package and wish to set variables with primitive values you will have to wrap them using bsh.Primitive.
- Overrides:
setTypedVariable
in classNameSpace
value
- If value is null, you'll get the default value for the typemodifiers
- may be null- Throws:
UtilEvalError
- See Also:
Primitive
-
setMethod
public void setMethod(String name, BshMethod method) throws UtilEvalError
Description copied from class:NameSpace
Note: this is primarily for internal use.- Overrides:
setMethod
in classNameSpace
- Throws:
UtilEvalError
- See Also:
Interpreter.source( String )
,Interpreter.eval( String )
-
getMethod
public BshMethod getMethod(String name, Class[] sig, boolean declaredOnly) throws UtilEvalError
Description copied from class:NameSpace
Get the bsh method matching the specified signature declared in this name space or a parent.Note: this method is primarily intended for use internally. If you use this method outside of the bsh package you will have to be familiar with BeanShell's use of the Primitive wrapper class.
- Overrides:
getMethod
in classNameSpace
declaredOnly
- if true then only methods declared directly in this namespace will be found and no inherited or imported methods will be visible.- Returns:
- the BshMethod or null if not found
- Throws:
UtilEvalError
- See Also:
Primitive
-
getAllNamesAux
protected void getAllNamesAux(Vector vec)
Description copied from class:NameSpace
Helper for implementing NameSource- Overrides:
getAllNamesAux
in classNameSpace
-
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 classNameSpace
- See Also:
NameSpace.loadDefaultImports()
-
-