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
| Modifier and Type | Field and Description |
|---|---|
| pack-priv SimpleNode | callerInfoNode
The node associated with the creation of this namespace. |
| private transient Hashtable | classCache
Local class cache for classes resolved through this namespace using getClass() (taking into account imports). |
| pack-priv Object | |
| private transient BshClassManager | |
| pack-priv Class | |
| protected Hashtable | |
| private Vector | |
| private Vector | |
| private Vector | |
| private Vector | |
| pack-priv boolean | isClass
Note that the namespace is a class body or class instance namespace. |
| pack-priv boolean | isMethod
Note that the namespace is a method body namespace. |
| public static final NameSpace | |
| private Hashtable | |
| private Hashtable | names
Name resolver objects |
| pack-priv Vector | |
| private String | nsName
The name of this namespace. |
| private String | |
| private NameSpace | |
| private This | |
| private Hashtable |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addNameSourceListener(NameSource.
Implements bsh. |
| pack-priv void | |
| private Class | |
| public void | classLoaderChanged()
Implements bsh. |
| public void | |
| protected Variable | |
| protected Variable | |
| protected Variable | |
| public void | |
| private String[] | |
| private BshMethod[] | flattenMethodCollection(Enumeration<E> e)
Flatten the vectors of overloaded methods to a single array. |
| public Object | |
| public String[] | Returns: all variable and method names in this and all parent namespacesImplements bsh. |
| protected void | |
| public Class | |
| private Class | Returns: null if not found.Implementation of getClass() Load a class through this namespace taking into account imports. |
| pack-priv Object | |
| public BshClassManager | |
| public Object | Returns: a BshMethod, Class, or null if no such command is found.is the name of the desired command method name, Class<T>[] is the signature of the desired command method. argTypes, Interpreter interpreter)A command is a scripted method or compiled command class implementing a specified method signature. |
| public Variable[] | |
| public This | getGlobal(Interpreter declaringInterpreter)
Get the top level namespace or this namespace if we are the top. |
| private Class | |
| protected BshMethod | |
| protected Variable | |
| public int | |
| public String | |
| public BshMethod | |
| public BshMethod | Returns: the BshMethod or null if not foundif true then only methods declared directly in this
namespace will be found and no inherited or imported methods will
be visible. declaredOnly)Get the bsh method matching the specified signature declared in this name space or a parent. |
| public String[] | |
| public BshMethod[] | |
| public String | |
| pack-priv Name | getNameResolver(String ambigname)
This is the factory for Name objects which resolve names within this namespace (e.g. toObject(), toClass(), toLHS()). |
| pack-priv SimpleNode | |
| pack-priv String | |
| public NameSpace | |
| public This | getSuper(Interpreter declaringInterpreter)
Get the parent namespace' This reference or this namespace' This reference if we are the top. |
| public This | getThis(Interpreter declaringInterpreter)
A This object is a thin layer over a namespace, comprising a bsh object context. |
| public Object | Returns: The variable value or Primitive.VOID if it is not defined.Get the specified variable in this namespace or a parent namespace. |
| public Object | Returns: The variable value or Primitive.VOID if it is not defined.If recurse is true then we recursively search through
parent namespaces for the variable. recurse)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. Get the specified variable in this namespace. |
| protected Variable | Returns: the Variable value or null if it is not definedLocate a variable and return the Variable object with optional recursion through parent name spaces. |
| public String[] | |
| public static Class | identifierToClass(ClassIdentifier ci)
This is a helper method for working inside of bsh scripts and commands. |
| public void | |
| public void | importCommands(String name)
Import scripted or compiled BeanShell commands in the following package in the classpath. |
| public void | |
| public void | |
| public void | |
| public Object | invokeMethod(String methodName, Object[] args, Interpreter interpreter)
Invoke a method in this namespace with the specified args and interpreter reference. |
| public Object | invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo)
This method simply delegates to This.invokeMethod();
|
| public void | |
| private BshMethod | loadScriptedCommand(InputStream in, String name, Class<T>[] argTypes, String resourcePath, Interpreter interpreter)
Load a command script from the input stream and find the BshMethod in the target namespace. |
| public void | |
| public void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | setLocalVariable(String name, Object value, boolean strictJava)
Set a variable explicitly in the local scope. |
| public void | |
| public void | |
| pack-priv void | |
| pack-priv void | |
| public void | |
| public void | setTypedVariable(String name, Class<T> type, Object value, boolean isFinal)
Deprecated
See #setTypedVariable( String, Class, Object, Modifiers )
|
| public void | setTypedVariable(String name, Class<T> type, Object
If value is null, you'll get the default value for the type value, Modifiers may be null modifiers)Declare a variable in the local scope and set its initial value. |
| public void | setVariable(String name, Object value, boolean
specifies whether strict java rules are applied. strictJava)Set the variable through this namespace. |
| pack-priv void | setVariable(String name, Object value, boolean
specifies whether strict java rules are applied. strictJava, boolean determines whether we will search for the variable in
our parent's scope before assigning locally. recurse)Set the value of a the variable 'name' through this namespace. |
| public String | |
| public void | |
| protected Object | Returns: return the variable value. A null var is mapped to Primitive.VOIDUnwrap a variable to its value. |
| private synchronized void |
| callerInfoNode | back to summary |
|---|---|
| pack-priv SimpleNode callerInfoNode The node associated with the creation of this namespace. This is used support getInvocationLine() and getInvocationText(). | |
| classCache | back to summary |
|---|---|
| private transient Hashtable<K, V> classCache Local class cache for classes resolved through this namespace using getClass() (taking into account imports). Only unqualified class names are cached here (those which might be imported). Qualified names are always absolute and are cached by BshClassManager. | |
| classInstance | back to summary |
|---|---|
| pack-priv Object classInstance | |
| classManager | back to summary |
|---|---|
| private transient BshClassManager classManager | |
| classStatic | back to summary |
|---|---|
| pack-priv Class<T> classStatic | |
| importedClasses | back to summary |
|---|---|
| protected Hashtable<K, V> importedClasses | |
| importedCommands | back to summary |
|---|---|
| private Vector<E> importedCommands | |
| importedObjects | back to summary |
|---|---|
| private Vector<E> importedObjects | |
| importedPackages | back to summary |
|---|---|
| private Vector<E> importedPackages | |
| importedStatic | back to summary |
|---|---|
| private Vector<E> importedStatic | |
| isClass | back to summary |
|---|---|
| pack-priv boolean isClass Note that the namespace is a class body or class instance namespace. This is used for controlling static/object import precedence, etc. | |
| isMethod | back to summary |
|---|---|
| pack-priv boolean isMethod Note that the namespace is a method body namespace. This is used for printing stack traces in exceptions. | |
| JAVACODE | back to summary |
|---|---|
| public static final NameSpace JAVACODE | |
| methods | back to summary |
|---|---|
| private Hashtable<K, V> methods | |
| names | back to summary |
|---|---|
| private Hashtable<K, V> names Name resolver objects | |
| nameSourceListeners | back to summary |
|---|---|
| pack-priv Vector<E> nameSourceListeners | |
| nsName | back to summary |
|---|---|
| private String nsName 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. | |
| packageName | back to summary |
|---|---|
| private String packageName | |
| parent | back to summary |
|---|---|
| private NameSpace parent | |
| thisReference | back to summary |
|---|---|
| private This thisReference | |
| variables | back to summary |
|---|---|
| private Hashtable<K, V> variables | |
| NameSpace | back to summary |
|---|---|
public NameSpace(NameSpace parent, String name)
| |
| NameSpace | back to summary |
|---|---|
| public NameSpace(BshClassManager classManager, String name) | |
| NameSpace | back to summary |
|---|---|
| public NameSpace(NameSpace parent, BshClassManager classManager, String name) | |
| addNameSourceListener | back to summary |
|---|---|
| public void addNameSourceListener(NameSource. Implements bsh. Implements NameSource Add a listener who is notified upon changes to names in this space. | |
| cacheClass | back to summary |
|---|---|
| pack-priv void cacheClass(String name, Class<T> c) Helper that caches class. | |
| classForName | back to summary |
|---|---|
| private Class | |
| classLoaderChanged | back to summary |
|---|---|
| public void classLoaderChanged() Implements bsh. Clear all cached classes and names | |
| clear | back to summary |
|---|---|
| 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.
| |
| createVariable | back to summary |
|---|---|
| protected Variable createVariable(String name, Object value, Modifiers mods) throws UtilEvalError | |
| createVariable | back to summary |
|---|---|
| protected Variable createVariable(String name, Class<T> type, Object value, Modifiers mods) throws UtilEvalError | |
| createVariable | back to summary |
|---|---|
| protected Variable createVariable(String name, Class<T> type, LHS lhs) throws UtilEvalError | |
| doSuperImport | back to summary |
|---|---|
| public void doSuperImport() throws UtilEvalError Perform "import *;" causing the entire classpath to be mapped. This can take a while. | |
| enumerationToStringArray | back to summary |
|---|---|
| private String[] enumerationToStringArray(Enumeration<E> e) | |
| flattenMethodCollection | back to summary |
|---|---|
| private BshMethod[] flattenMethodCollection(Enumeration<E> e) Flatten the vectors of overloaded methods to a single array.
| |
| get | back to summary |
|---|---|
| public Object get(String name, Interpreter interpreter) throws UtilEvalError Resolve name to an object through this namespace. | |
| getAllNames | back to summary |
|---|---|
| public String[] getAllNames() Implements bsh. Implements NameSource
| |
| getAllNamesAux | back to summary |
|---|---|
| protected void getAllNamesAux(Vector<E> vec) Helper for implementing NameSource | |
| getClass | back to summary |
|---|---|
| public Class Load a class through this namespace taking into account imports. The class search will proceed through the parent namespaces if necessary.
| |
| getClassImpl | back to summary |
|---|---|
| private Class Implementation of getClass() Load a class through this namespace taking into account imports. Check the cache first. If an unqualified name look for imported class or package. Else try to load absolute name. This method implements caching of unqualified names (normally imports). Qualified names are cached by the BshClassManager. Unqualified absolute class names (e.g. unpackaged Foo) are cached too so that we don't go searching through the imports for them each time.
| |
| getClassInstance | back to summary |
|---|---|
| pack-priv Object getClassInstance() throws UtilEvalError | |
| getClassManager | back to summary |
|---|---|
| public BshClassManager getClassManager() | |
| getCommand | back to summary |
|---|---|
| public Object getCommand(String name, Class<T>[] 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.
| |
| getDeclaredVariables | back to summary |
|---|---|
| public Variable[] getDeclaredVariables() | |
| getGlobal | back to summary |
|---|---|
| public This getGlobal(Interpreter declaringInterpreter) 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(); | |
| getImportedClassImpl | back to summary |
|---|---|
| private Class Try to make the name into an imported class. This method takes into account only imports (class or package) found directly in this NameSpace (no parent chain). | |
| getImportedMethod | back to summary |
|---|---|
| protected BshMethod getImportedMethod(String name, Class<T>[] sig) throws UtilEvalError | |
| getImportedVar | back to summary |
|---|---|
| protected Variable getImportedVar(String name) throws UtilEvalError | |
| getInvocationLine | back to summary |
|---|---|
| public int getInvocationLine() | |
| getInvocationText | back to summary |
|---|---|
| public String getInvocationText() | |
| getMethod | back to summary |
|---|---|
| public BshMethod getMethod(String name, Class<T>[] sig) throws UtilEvalError | |
| getMethod | back to summary |
|---|---|
| public BshMethod getMethod(String name, Class<T>[] sig, boolean declaredOnly) throws UtilEvalError 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.
| |
| getMethodNames | back to summary |
|---|---|
| public String[] getMethodNames() Get the names of methods declared in this namespace. (This does not include methods in parent namespaces). | |
| getMethods | back to summary |
|---|---|
| public BshMethod[] getMethods() Get the methods defined in this namespace. (This does not show methods in parent namespaces). Note This will probably be renamed getDeclaredMethods() | |
| getName | back to summary |
|---|---|
| public String 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. | |
| getNameResolver | back to summary |
|---|---|
| pack-priv Name getNameResolver(String ambigname) This is the factory for Name objects which resolve names within this namespace (e.g. toObject(), toClass(), toLHS()). This was intended to support name resolver caching, allowing Name objects to cache info about the resolution of names for performance reasons. However this not proven useful yet. We'll leave the caching as it will at least minimize Name object creation. (This method would be called getName() if it weren't already used for the simple name of the NameSpace) This method was public for a time, which was a mistake. Use get() instead. | |
| getNode | back to summary |
|---|---|
| pack-priv SimpleNode getNode() | |
| getPackage | back to summary |
|---|---|
| pack-priv String getPackage() | |
| getParent | back to summary |
|---|---|
| public NameSpace 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 | back to summary |
|---|---|
| public This getSuper(Interpreter declaringInterpreter) Get the parent namespace' This reference or this namespace' This reference if we are the top. | |
| getThis | back to summary |
|---|---|
| public This getThis(Interpreter declaringInterpreter) A This object is a thin layer over a namespace, comprising a bsh object context. It handles things like the interface types the bsh object supports and aspects of method invocation on it. The declaringInterpreter is here to support callbacks from Java through generated proxies. The scripted object "remembers" who created it for things like printing messages and other per-interpreter phenomenon when called externally from Java. | |
| getVariable | back to summary |
|---|---|
| public Object getVariable(String name) throws UtilEvalError 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.
| |
| getVariable | back to summary |
|---|---|
| public Object getVariable(String name, boolean recurse) throws UtilEvalError Get the specified variable in this namespace.
| |
| getVariableImpl | back to summary |
|---|---|
| protected Variable getVariableImpl(String name, boolean recurse) throws UtilEvalError Locate a variable and return the Variable object with optional recursion through parent name spaces. If this namespace is static, return only static variables.
| |
| getVariableNames | back to summary |
|---|---|
| public String[] getVariableNames() Get the names of variables defined in this namespace. (This does not show variables in parent namespaces). | |
| identifierToClass | back to summary |
|---|---|
| public static Class 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 ); | |
| importClass | back to summary |
|---|---|
| public void importClass(String name) Import a class name. Subsequent imports override earlier ones | |
| importCommands | back to summary |
|---|---|
| public void importCommands(String name) 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 "/". | |
| importObject | back to summary |
|---|---|
| public void importObject(Object obj) 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.
| |
| importPackage | back to summary |
|---|---|
| public void importPackage(String name) subsequent imports override earlier ones | |
| importStatic | back to summary |
|---|---|
| public void importStatic(Class<T> clas) | |
| invokeMethod | back to summary |
|---|---|
| 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.
| |
| invokeMethod | back to summary |
|---|---|
| public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo) throws EvalError This method simply delegates to This.invokeMethod();
| |
| loadDefaultImports | back to summary |
|---|---|
| public void loadDefaultImports() Import standard packages. Currently:
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");
| |
| loadScriptedCommand | back to summary |
|---|---|
| private BshMethod loadScriptedCommand(InputStream in, String name, Class<T>[] argTypes, String resourcePath, Interpreter interpreter) throws UtilEvalError Load a command script from the input stream and find the BshMethod in the target namespace.
| |
| nameSpaceChanged | back to summary |
|---|---|
| public void nameSpaceChanged() Clear all cached classes and names | |
| prune | back to summary |
|---|---|
| public void prune() Used for serialization | |
| setClassInstance | back to summary |
|---|---|
| pack-priv void setClassInstance(Object instance) | |
| setClassManager | back to summary |
|---|---|
| pack-priv void setClassManager(BshClassManager classManager) | |
| setClassStatic | back to summary |
|---|---|
| pack-priv void setClassStatic(Class<T> clas) | |
| setLocalVariable | back to summary |
|---|---|
| pack-priv void setLocalVariable(String name, Object value, boolean strictJava) throws UtilEvalError Set a variable explicitly in the local scope. | |
| setMethod | back to summary |
|---|---|
| public void setMethod(String name, BshMethod method) throws UtilEvalError Note this is primarily for internal use. | |
| setName | back to summary |
|---|---|
| public void setName(String name) | |
| setNode | back to summary |
|---|---|
| pack-priv void setNode(SimpleNode node) Set the node associated with the creation of this namespace. This is used in debugging and to support the getInvocationLine() and getInvocationText() methods. | |
| setPackage | back to summary |
|---|---|
| pack-priv void setPackage(String packageName) Set the package name for classes defined in this namespace. Subsequent sets override the package. | |
| setParent | back to summary |
|---|---|
| public void setParent(NameSpace parent) | |
| setTypedVariable | back to summary |
|---|---|
| public void setTypedVariable(String name, Class<T> type, Object value, boolean isFinal) throws UtilEvalError
Deprecated See #setTypedVariable( String, Class, Object, Modifiers ) | |
| setTypedVariable | back to summary |
|---|---|
| public void setTypedVariable(String name, Class<T> 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.
| |
| setVariable | back to summary |
|---|---|
| public void setVariable(String name, Object value, boolean strictJava) throws UtilEvalError 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.
| |
| setVariable | back to summary |
|---|---|
| pack-priv void setVariable(String name, Object value, boolean strictJava, boolean recurse) throws UtilEvalError Set the value of a the variable 'name' through this namespace. The variable may be an existing or non-existing variable. It may live in this namespace or in a parent namespace if recurse is true. Note This method is not public and does *not* know about LOCALSCOPING. Its caller methods must set recurse intelligently in all situations (perhaps based on LOCALSCOPING). 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.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
| |
| unsetVariable | back to summary |
|---|---|
| public void unsetVariable(String name) Remove the variable from the namespace. | |
| unwrapVariable | back to summary |
|---|---|
| protected Object unwrapVariable(Variable var) throws UtilEvalError Unwrap a variable to its value.
| |
| writeObject | back to summary |
|---|---|
| private synchronized void writeObject(ObjectOutputStream s) throws IOException | |