Top Description Fields Constructors Methods
bsh

public Class This

extends Object
implements Serializable, Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable, java.io.Serializable
Known Direct Subclasses
bsh.JThis, bsh.XThis
Imports
java.io.IOException

'This' is the type of bsh scripted objects. A 'This' object is a bsh scripted object context. It holds a namespace reference and implements event listeners and various other interfaces. This holds a reference to the declaring interpreter for callbacks from outside of bsh.

Field Summary

Modifier and TypeField and Description
pack-priv transient Interpreter
declaringInterpreter

This is the interpreter running when the This ref was created.

pack-priv NameSpace
namespace

The namespace that this This reference wraps.

Constructor Summary

AccessConstructor and Description
protected
This(NameSpace namespace, Interpreter declaringInterpreter)

Method Summary

Modifier and TypeMethod and Description
public static void
bind(This ths, NameSpace namespace, Interpreter declaringInterpreter)

Bind a This reference to a parent's namespace with the specified declaring interpreter.

public Object
getInterface(Class<T> clas)

Get a version of this scripted object implementing the specified interface.

public Object
getInterface(Class<T>[] ca)

Get a version of this scripted object implementing the specified interfaces.

public NameSpace
pack-priv static This
getThis(NameSpace namespace, Interpreter declaringInterpreter)

getThis() is a factory for bsh.This type references.

public Object
invokeMethod(String name, Object[] args)

Invoke specified method as from outside java code, using the declaring interpreter and current namespace.

public Object
invokeMethod(String
callStack is null a new CallStack will be created and initialized with this namespace.
methodName
,
Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo, boolean
if true then only methods declared directly in the namespace will be visible - no inherited or imported methods will be visible.
declaredOnly
)

Invoke a method in this namespace with the specified args, interpreter reference, callstack, and caller info.

pack-priv static boolean
isExposedThisMethod(String name)

Allow invocations of these method names on This type objects.

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

declaringInterpreterback to summary
pack-priv transient Interpreter declaringInterpreter

This is the interpreter running when the This ref was created. It's used as a default interpreter for callback through the This where there is no current interpreter instance e.g. interface proxy or event call backs from outside of bsh.

namespaceback to summary
pack-priv NameSpace namespace

The namespace that this This reference wraps.

Constructor Detail

Thisback to summary
protected This(NameSpace namespace, Interpreter declaringInterpreter)

Method Detail

bindback to summary
public static void bind(This ths, NameSpace namespace, Interpreter declaringInterpreter)

Bind a This reference to a parent's namespace with the specified declaring interpreter. Also re-init the callstack. It's necessary to bind a This reference before it can be used after deserialization. This is used by the bsh load() command.

This is a static utility method because it's used by a bsh command bind() and the interpreter doesn't currently allow access to direct methods of This objects (small hack)

getInterfaceback to summary
public Object getInterface(Class<T> clas) throws UtilEvalError

Get a version of this scripted object implementing the specified interface.

getInterfaceback to summary
public Object getInterface(Class<T>[] ca) throws UtilEvalError

Get a version of this scripted object implementing the specified interfaces.

getNameSpaceback to summary
public NameSpace getNameSpace()
getThisback to summary
pack-priv static This getThis(NameSpace namespace, Interpreter declaringInterpreter)

getThis() is a factory for bsh.This type references. The capabilities of ".this" references in bsh are version dependent up until jdk1.3. The version dependence was to support different default interface implementations. i.e. different sets of listener interfaces which scripted objects were capable of implementing. In jdk1.3 the reflection proxy mechanism was introduced which allowed us to implement arbitrary interfaces. This is fantastic. A This object is a thin layer over a namespace, comprising a bsh object context. We create it here only if needed for the namespace.

Note

this method could be considered slow because of the way it dynamically factories objects. However I've also done tests where I hard-code the factory to return JThis and see no change in the rough test suite time. This references are also cached in NameSpace.

invokeMethodback to summary
public Object invokeMethod(String name, Object[] args) throws EvalError

Invoke specified method as from outside java code, using the declaring interpreter and current namespace. The call stack will indicate that the method is being invoked from outside of bsh in native java code.

Note

you must still wrap/unwrap args/return values using Primitive/Primitive.unwrap() for use outside of BeanShell.

See Also
bsh.Primitive
invokeMethodback to summary
public Object invokeMethod(String methodName, Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo, boolean declaredOnly) throws EvalError

Invoke a method in this namespace with the specified args, interpreter reference, callstack, and caller info.

Note

If you use this method outside of the bsh package and wish to use variables with primitive values you will have to wrap them using bsh.Primitive. Consider using This getInterface() to make a true Java interface for invoking your scripted methods.

This method also implements the default object protocol of toString(), hashCode() and equals() and the invoke() meta-method handling as a last resort.

Note

The invoke() meta-method will not catch the Object protocol methods (toString(), hashCode()...). If you want to override them you have to script them directly.

Parameters
methodName:String

callStack is null a new CallStack will be created and initialized with this namespace.

declaredOnly:boolean

if true then only methods declared directly in the namespace will be visible - no inherited or imported methods will be visible.

See Also
bsh.This.invokeMethod(String methodName, Object [] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo), bsh.Primitive
isExposedThisMethodback to summary
pack-priv static boolean isExposedThisMethod(String name)

Allow invocations of these method names on This type objects. Don't give bsh.This a chance to override their behavior.

If the method is passed here the invocation will actually happen on the bsh.This object via the regular reflective method invocation mechanism. If not, then the method is evaluated by bsh.This itself as a scripted method call.

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.