bsh
public class NameSpace extends Object implements Serializable, BshClassManager.Listener, NameSource
A bsh.This object is a thin layer over a NameSpace that associates it with an Interpreter instance. Together they comprise a Bsh scripted object context.
Note: I'd really like to use collections here, but we have to keep this compatible with JDK1.1
Field Summary | |
---|---|
static NameSpace | JAVACODE |
String | nsName
The name of this namespace. |
Constructor Summary | |
---|---|
NameSpace(NameSpace parent, String name) | |
NameSpace(BshClassManager classManager, String name) | |
NameSpace(NameSpace parent, BshClassManager classManager, String name) |
Method Summary | |
---|---|
void | addNameSourceListener(NameSource.Listener listener)
Implements NameSource
Add a listener who is notified upon changes to names in this space. |
protected void | checkMethodModifiers(BshMethod method) |
protected void | checkVariableModifiers(String name, Modifiers modifiers)
Dissallow static vars outside of a class |
void | classLoaderChanged()
Clear all cached classes and names |
void | clear()
Clear all variables, methods, and imports from this namespace.
|
void | doSuperImport()
Perform "import *;" causing the entire classpath to be mapped.
|
Object | get(String name, Interpreter interpreter)
Resolve name to an object through this namespace. |
String[] | getAllNames()
Implements NameSource |
protected void | getAllNamesAux(Vector vec)
Helper for implementing NameSource |
static Object | getAssignableForm(Object rhs, Class lhsType)
Determine if the RHS object can be assigned to the LHS type:
1) As in a legal Java assignment (as determined by
Reflect.isJavaAssignable()) through widening or promotion
2) Via special BeanShell extensions like interface generation or
(gag) numeric-style promotion of primitive wrappers
(e.g. |
Class | getClass(String name)
Load a class through this namespace taking into account imports.
|
BshClassManager | getClassManager() |
Object | getCommand(String name, Class[] argTypes, Interpreter interpreter)
A command is a scripted method or compiled command class implementing a
specified method signature. |
NameSpace | getGlobal()
Get the top level namespace or this namespace if we are the top.
|
int | getInvocationLine() |
String | getInvocationText() |
BshMethod | getMethod(String name, Class[] sig)
Get the bsh method matching the specified signature declared in
this name space or a parent.
|
String[] | getMethodNames()
Get the names of methods defined in this namespace.
|
BshMethod[] | getMethods()
Get the methods defined in this namespace.
|
String | getName() |
NameSpace | getParent()
Get the parent namespace.
|
NameSpace | getSuper()
Get the parent namespace or this namespace if we are the top.
|
Object | getVariable(String name)
Get the specified variable in this namespace or a parent namespace.
|
Object | getVariable(String name, boolean recurse)
Get the specified variable in this namespace. |
protected NameSpace.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.
|
static Class | identifierToClass(ClassIdentifier ci)
This is a helper method for working inside of bsh scripts and commands.
|
void | importClass(String name)
Import a class name.
|
void | importCommands(String name)
Import scripted or compiled BeanShell commands in the following package
in the classpath. |
void | importPackage(String name)
subsequent imports override earlier ones |
Object | invokeMethod(String methodName, Object[] args, Interpreter interpreter)
Invoke a method in this namespace with the specified args and
interpreter reference. |
Object | invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo)
This method simply delegates to This.invokeMethod();
|
protected boolean | isVisible(NameSpace.Variable var)
This is a hook to allow ClassNameSpace to add functionality here. |
protected boolean | isVisible(BshMethod method)
This is a hook to allow ClassNameSpace to add functionality to
getMethod() |
void | loadDefaultImports()
Import standard packages. |
void | nameSpaceChanged()
Clear all cached classes and names |
void | prune()
Used for serialization |
void | setMethod(String name, BshMethod method)
Note: this is primarily for internal use. |
void | setName(String name) |
void | setParent(NameSpace parent) |
void | setTypedVariable(String name, Class type, Object value, boolean isFinal) |
void | setTypedVariable(String name, Class type, Object value, Modifiers modifiers)
Declare a variable in the local scope and set its initial value.
|
void | setVariable(String name, Object value, boolean strictJava)
Set the variable through this namespace.
|
String | toString() |
void | unsetVariable(String name)
Remove the variable from the namespace. |
protected Object | unwrapVariable(NameSpace.Variable var)
Unwrap a variable to its value. |
UNKNOWN: the parent namespace of this namespace. Child namespaces inherit all variables and methods of their parent and can (of course) override / shadow them.
Parameters: name is here just to allow the error message to use it
See Also: loadDefaultImports
Returns: all variable and method names in this and all parent namespaces
The primary purpose of the "returning the assignable form" abstraction is to allow non-standard Java assignment conversions. e.g. wrapper conversion for boxing and unboxing. Some of this will be considered standard in Java 1.5.
Parameters: lhsType lhsType is a real Java class type or Java primitive TYPE rhs is a value, bsh.Primitive wrapper, or Primitive.NULL. If it is a Primitive wrapper it will be unwrapped and compared using Reflect.isJavaAssignableFrom(). If it is Primtive.VOID an error will occur.
Returns: an assignable form of the rhs, usually the original rhs if assignable. If the rhs was a Primitive and it was assignable the Primitive will be returned. If the Primitive needed to be auto-boxed to a wrapper type, the wrapper type will be returned.
Throws: UtilEvalError if the assignment cannot be made legally UtilEvalError on rhs of Primitive.VOID (void assignment)
See Also: BSHCastExpression
Returns: null if not found.
Parameters: name is the name of the desired command method argTypes is the signature of the desired command method.
Returns: a BshMethod, Class, or null if no such command is found.
Throws: UtilEvalError if loadScriptedCommand throws UtilEvalError i.e. on errors loading a script that was found
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.
Returns: the BshMethod or null if not found
See Also: Primitive
Note: this method is primarily intended for use internally. If you use this method outside of the bsh package you will have to use Primitive.unwrap() to get primitive values.
Returns: The variable value or Primitive.VOID if it is not defined.
See Also: Primitive
Parameters: recurse If recurse is true then we recursively search through
parent namespaces for the variable.
Note: this method is primarily intended for use internally. If you use
this method outside of the bsh package you will have to use
Primitive.unwrap() to get primitive values.
Returns: The variable value or Primitive.VOID if it is not defined.
See Also: Primitive
Returns: the Variable value or null if it is not defined
See Also: bsh.This.invokeMethod(
String methodName, Object [] args, Interpreter interpreter,
CallStack callstack, SimpleNode callerInfo )
See Also: bsh.This.invokeMethod(
String methodName, Object [] args, Interpreter interpreter,
CallStack callstack, SimpleNode callerInfo )
importClass("bsh.EvalError"); importClass("bsh.Interpreter"); importPackage("javax.swing.event"); importPackage("javax.swing"); importPackage("java.awt.event"); importPackage("java.awt"); importPackage("java.net"); importPackage("java.util"); importPackage("java.io"); importPackage("java.lang"); importCommands("/bsh/commands");
See Also: Interpreter Interpreter
Deprecated: See #setTypedVariable( String, Class, Object, Modifiers )
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.
Parameters: value If value is null, you'll get the default value for the type modifiers may be null
See Also: Primitive
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.
Parameters: strictJava specifies whether strict java rules are applied.
See Also:
Setting a new variable (which didn't exist before) or removing
a variable causes a namespace change.
Returns: return the variable value. A null var is mapped to Primitive.VOID