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
NameSource.Listener
Modifier and Type | Field and Description |
---|---|
protected Hashtable |
importedClasses |
static NameSpace |
JAVACODE |
Constructor and Description |
---|
NameSpace(BshClassManager classManager,
String name) |
NameSpace(NameSpace parent,
BshClassManager classManager,
String name) |
NameSpace(NameSpace parent,
String name) |
Modifier and Type | Method and Description |
---|---|
void |
addNameSourceListener(NameSource.Listener listener)
Implements NameSource
Add a listener who is notified upon changes to names in this space.
|
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
|
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.
|
Variable[] |
getDeclaredVariables() |
This |
getGlobal(Interpreter declaringInterpreter)
Get the top level namespace or this namespace if we are the top.
|
protected BshMethod |
getImportedMethod(String name,
Class[] sig) |
protected Variable |
getImportedVar(String name) |
int |
getInvocationLine() |
String |
getInvocationText() |
BshMethod |
getMethod(String name,
Class[] sig) |
BshMethod |
getMethod(String name,
Class[] sig,
boolean declaredOnly)
Get the bsh method matching the specified signature declared in
this name space or a parent.
|
String[] |
getMethodNames()
Get the names of methods declared in this namespace.
|
BshMethod[] |
getMethods()
Get the methods defined in this namespace.
|
String |
getName()
The name of this namespace.
|
NameSpace |
getParent()
Get the parent namespace.
|
This |
getSuper(Interpreter declaringInterpreter)
Get the parent namespace' This reference or this namespace' This
reference 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 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 |
importObject(Object obj)
Import a compiled Java object's methods and variables into this
namespace.
|
void |
importPackage(String name)
subsequent imports override earlier ones
|
void |
importStatic(Class clas) |
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,
bsh.SimpleNode callerInfo)
This method simply delegates to This.invokeMethod();
|
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)
Deprecated.
See #setTypedVariable( String, Class, Object, Modifiers )
|
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(Variable var)
Unwrap a variable to its value.
|
public static final NameSpace JAVACODE
protected Hashtable importedClasses
public NameSpace(BshClassManager classManager, String name)
public NameSpace(NameSpace parent, BshClassManager classManager, String name)
public void setName(String name)
public String getName()
public Object get(String name, Interpreter interpreter) throws UtilEvalError
UtilEvalError
public void setVariable(String name, Object value, boolean strictJava) throws UtilEvalError
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.
strictJava
- specifies whether strict java rules are applied.UtilEvalError
Setting a new variable (which didn't exist before) or removing
a variable causes a namespace change.
public void unsetVariable(String name)
public String[] getVariableNames()
public String[] getMethodNames()
public BshMethod[] getMethods()
public NameSpace getParent()
public This getSuper(Interpreter declaringInterpreter)
public This getGlobal(Interpreter declaringInterpreter)
public BshClassManager getClassManager()
public void prune()
public void setParent(NameSpace parent)
public Object getVariable(String name) throws UtilEvalError
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.
UtilEvalError
Primitive.unwrap( Object )
public Object getVariable(String name, boolean recurse) throws UtilEvalError
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.
UtilEvalError
Primitive.unwrap( Object )
protected Variable getVariableImpl(String name, boolean recurse) throws UtilEvalError
UtilEvalError
public Variable[] getDeclaredVariables()
protected Object unwrapVariable(Variable var) throws UtilEvalError
UtilEvalError
public void setTypedVariable(String name, Class type, Object value, boolean isFinal) throws UtilEvalError
UtilEvalError
public void setTypedVariable(String name, Class type, Object value, Modifiers modifiers) throws UtilEvalError
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.
value
- If value is null, you'll get the default value for the typemodifiers
- may be nullUtilEvalError
Primitive
public void setMethod(String name, BshMethod method) throws UtilEvalError
UtilEvalError
Interpreter.source( String )
,
Interpreter.eval( String )
public BshMethod getMethod(String name, Class[] sig) throws UtilEvalError
UtilEvalError
getMethod( String, Class [], boolean )
,
getMethod( String, Class [] )
public BshMethod getMethod(String name, Class[] sig, boolean declaredOnly) throws UtilEvalError
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.
declaredOnly
- if true then only methods declared directly in this
namespace will be found and no inherited or imported methods will
be visible.UtilEvalError
Primitive
public void importClass(String name)
public void importPackage(String name)
public void importCommands(String name)
public Object getCommand(String name, Class[] argTypes, Interpreter interpreter) throws UtilEvalError
name
- is the name of the desired command methodargTypes
- is the signature of the desired command method.UtilEvalError
- if loadScriptedCommand throws UtilEvalError
i.e. on errors loading a script that was foundprotected BshMethod getImportedMethod(String name, Class[] sig) throws UtilEvalError
UtilEvalError
protected Variable getImportedVar(String name) throws UtilEvalError
UtilEvalError
public Class getClass(String name) throws UtilEvalError
UtilEvalError
public String[] getAllNames()
getAllNames
in interface NameSource
protected void getAllNamesAux(Vector vec)
public void addNameSourceListener(NameSource.Listener listener)
addNameSourceListener
in interface NameSource
public void doSuperImport() throws UtilEvalError
UtilEvalError
public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter) throws EvalError
EvalError
bsh.This.invokeMethod(
String methodName, Object [] args, Interpreter interpreter,
CallStack callstack, SimpleNode callerInfo, boolean )
public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, bsh.SimpleNode callerInfo) throws EvalError
EvalError
bsh.This.invokeMethod(
String methodName, Object [] args, Interpreter interpreter,
CallStack callstack, SimpleNode callerInfo )
public void classLoaderChanged()
classLoaderChanged
in interface BshClassManager.Listener
public void nameSpaceChanged()
public void loadDefaultImports()
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");
public int getInvocationLine()
public String getInvocationText()
public static Class identifierToClass(ClassIdentifier ci)
public void clear()
loadDefaultImports()
public void importObject(Object obj)
public void importStatic(Class clas)
? 2000-2005 pat@pat.net :-)