- All Implemented Interfaces:
Serializable
,BshClassManager.Listener
,NameSource
- Direct Known Subclasses:
ExternalNameSpace
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
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gjt.sp.jedit.bsh.NameSource
NameSource.Listener
-
Field Summary
-
Constructor Summary
ConstructorDescriptionNameSpace
(BshClassManager classManager, String name) NameSpace
(NameSpace parent, BshClassManager classManager, String name) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommandPath
(String path, Class clas) Adds a URL to the command path.void
addNameSourceListener
(NameSource.Listener listener) Implements NameSource Add a listener who is notified upon changes to names in this space.void
Clear all cached classes and namesvoid
clear()
Clear all variables, methods, and imports from this namespace.void
Perform "import *;" causing the entire classpath to be mapped.get
(String name, Interpreter interpreter) Resolve name to an object through this namespace.String[]
Implements NameSourceprotected void
getAllNamesAux
(Vector vec) Helper for implementing NameSourceLoad a class through this namespace taking into account imports.getCommand
(String name) Looks up a command.getCommand
(String name, Class[] argTypes, Interpreter interpreter) A command is a scripted method or compiled command class implementing a specified method signature.Variable[]
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
Get the bsh method matching the specified signature declared in this name space or a parent.String[]
Get the names of methods declared in this namespace.Get the methods defined in this namespace.getName()
The name of this namespace.Get the parent namespace.getSuper
(Interpreter declaringInterpreter) Get the parent namespace' This reference or this namespace' This reference if we are the top.getVariable
(String name) Get the specified variable in this namespace or a parent namespace.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[]
Get the names of variables defined in this namespace.static Class
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 onesvoid
importStatic
(Class clas) invokeMethod
(String methodName, Object[] args, Interpreter interpreter) Invoke a method in this namespace with the specified args and interpreter reference.invokeMethod
(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, org.gjt.sp.jedit.bsh.SimpleNode callerInfo) This method simply delegates to This.invokeMethod();void
Import standard packages.void
Clear all cached classes and namesvoid
prune()
Used for serializationvoid
removeCommandPath
(String path, Class clas) Remove a URLfrom the command path.void
Note: this is primarily for internal use.void
void
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) void
setVariable
(String name, Object value, boolean strictJava) Set the variable through this namespace.toString()
void
unsetVariable
(String name) Remove the variable from the namespace.protected Object
unwrapVariable
(Variable var) Unwrap a variable to its value.
-
Field Details
-
JAVACODE
-
importedClasses
-
-
Constructor Details
-
NameSpace
- Parameters:
parent
- the parent namespace of this namespace. Child namespaces inherit all variables and methods of their parent and can (of course) override / shadow them.name
- a name
-
NameSpace
-
NameSpace
-
-
Method Details
-
setName
-
getName
The name of this namespace. If the namespace is a method body namespace then this is the name of the method. If it's a class or class instance then it's the name of the class. -
get
Resolve name to an object through this namespace.- Throws:
UtilEvalError
-
setVariable
Set the variable through this namespace. This method obeys the LOCALSCOPING property to determine how variables are set.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.- Throws:
UtilEvalError
- See Also:
-
unsetVariable
Remove the variable from the namespace. -
getVariableNames
Get the names of variables defined in this namespace. (This does not show variables in parent namespaces). -
getMethodNames
Get the names of methods declared in this namespace. (This does not include methods in parent namespaces). -
getMethods
Get the methods defined in this namespace. (This does not show methods in parent namespaces). Note: This will probably be renamed getDeclaredMethods() -
getParent
Get the parent namespace. Note: this isn't quite the same as getSuper(). getSuper() returns 'this' if we are at the root namespace. -
getSuper
Get the parent namespace' This reference or this namespace' This reference if we are the top. -
getGlobal
Get the top level namespace or this namespace if we are the top. Note: this method should probably return type bsh.This to be consistent with getThis(); -
getClassManager
-
prune
public void prune()Used for serialization -
setParent
-
getVariable
Get the specified variable in this namespace or a parent namespace.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.
- Throws:
UtilEvalError
- See Also:
-
getVariable
Get the specified variable in this namespace.- 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.
- Throws:
UtilEvalError
- See Also:
-
getVariableImpl
Locate a variable and return the Variable object with optional recursion through parent name spaces.If this namespace is static, return only static variables.
- Returns:
- the Variable value or null if it is not defined
- Throws:
UtilEvalError
-
getDeclaredVariables
-
unwrapVariable
Unwrap a variable to its value.- Returns:
- return the variable value. A null var is mapped to Primitive.VOID
- Throws:
UtilEvalError
-
setTypedVariable
@Deprecated public void setTypedVariable(String name, Class type, Object value, boolean isFinal) throws UtilEvalError Deprecated.See #setTypedVariable( String, Class, Object, Modifiers )- Throws:
UtilEvalError
-
setTypedVariable
public void setTypedVariable(String name, Class type, Object value, Modifiers modifiers) throws UtilEvalError 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.
- Parameters:
value
- If value is null, you'll get the default value for the typemodifiers
- may be null- Throws:
UtilEvalError
- See Also:
-
setMethod
Note: this is primarily for internal use.- Throws:
UtilEvalError
- See Also:
-
getMethod
- Throws:
UtilEvalError
- See Also:
-
getMethod
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.
- Parameters:
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:
-
importClass
Import a class name. Subsequent imports override earlier ones -
importPackage
subsequent imports override earlier ones -
importCommands
Import scripted or compiled BeanShell commands in the following package in the classpath. You may use either "/" path or "." package notation. e.g. importCommands("/bsh/commands") or importCommands("bsh.commands") are equivalent. If a relative path style specifier is used then it is made into an absolute path by prepending "/". -
getCommand
public Object getCommand(String name, Class[] argTypes, Interpreter interpreter) throws UtilEvalError A command is a scripted method or compiled command class implementing a specified method signature. Commands are loaded from the classpath and may be imported using the importCommands() method.This method searches the imported commands packages for a script or command object corresponding to the name of the method. If it is a script the script is sourced into this namespace and the BshMethod for the requested signature is returned. If it is a compiled class the class is returned. (Compiled command classes implement static invoke() methods).
The imported packages are searched in reverse order, so that later imports take priority. Currently only the first object (script or class) with the appropriate name is checked. If another, overloaded form, is located in another package it will not currently be found. This could be fixed.
- Parameters:
name
- is the name of the desired command methodargTypes
- 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
-
getImportedMethod
- Throws:
UtilEvalError
-
getImportedVar
- Throws:
UtilEvalError
-
getClass
Load a class through this namespace taking into account imports. The class search will proceed through the parent namespaces if necessary.- Returns:
- null if not found.
- Throws:
UtilEvalError
-
getAllNames
Implements NameSource- Specified by:
getAllNames
in interfaceNameSource
- Returns:
- all variable and method names in this and all parent namespaces
-
getAllNamesAux
Helper for implementing NameSource -
addNameSourceListener
Implements NameSource Add a listener who is notified upon changes to names in this space.- Specified by:
addNameSourceListener
in interfaceNameSource
-
doSuperImport
Perform "import *;" causing the entire classpath to be mapped. This can take a while.- Throws:
UtilEvalError
-
toString
-
invokeMethod
public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter) throws EvalError Invoke a method in this namespace with the specified args and interpreter reference. No caller information or call stack is required. The method will appear as if called externally from Java.- Throws:
EvalError
- See Also:
-
invokeMethod
public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, org.gjt.sp.jedit.bsh.SimpleNode callerInfo) throws EvalError This method simply delegates to This.invokeMethod();- Throws:
EvalError
- See Also:
-
classLoaderChanged
public void classLoaderChanged()Clear all cached classes and names- Specified by:
classLoaderChanged
in interfaceBshClassManager.Listener
-
nameSpaceChanged
public void nameSpaceChanged()Clear all cached classes and names -
loadDefaultImports
public void loadDefaultImports()Import standard packages. Currently:importClass("org.gjt.sp.jedit.bsh.EvalError"); importClass("org.gjt.sp.jedit.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"); addCommandPath("/org/gjt/sp/jedit/bsh/commands",getClass());
-
getInvocationLine
public int getInvocationLine() -
getInvocationText
-
identifierToClass
This is a helper method for working inside of bsh scripts and commands. In that context it is impossible to see a ClassIdentifier object for what it is. Attempting to access a method on a ClassIdentifier will look like a static method invocation. This method is in NameSpace for convenience (you don't have to import bsh.ClassIdentifier to use it ); -
clear
public void clear()Clear all variables, methods, and imports from this namespace. If this namespace is the root, it will be reset to the default imports.- See Also:
-
importObject
Import a compiled Java object's methods and variables into this namespace. When no scripted method / command or variable is found locally in this namespace method / fields of the object will be checked. Objects are checked in the order of import with later imports taking precedence. -
importStatic
-
setVariable
- Throws:
UtilEvalError
-
addCommandPath
Adds a URL to the command path. -
removeCommandPath
Remove a URLfrom the command path. -
getCommand
Looks up a command.
-