org.gjt.sp.jedit.bsh

## Class This

- java.lang.Object
- - org.gjt.sp.jedit.bsh.This

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Runnable
  Direct Known Subclasses:
    XThis

      public class This
      extends java.lang.Object
      implements java.io.Serializable, java.lang.Runnable

  '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.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `This(NameSpace namespace, Interpreter declaringInterpreter)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `bind(This ths, NameSpace namespace, Interpreter declaringInterpreter)` Bind a This reference to a parent's namespace with the specified declaring interpreter.
    `java.lang.Object` | `getInterface(java.lang.Class clas)` Get a version of this scripted object implementing the specified interface.
    `java.lang.Object` | `getInterface(java.lang.Class[] ca)` Get a version of this scripted object implementing the specified interfaces.
    `NameSpace` | `getNameSpace()`
    `java.lang.Object` | `invokeMethod(java.lang.String name, java.lang.Object[] args)` Invoke specified method as from outside java code, using the declaring interpreter and current namespace.
    `java.lang.Object` | `invokeMethod(java.lang.String methodName, java.lang.Object[] args, Interpreter interpreter, CallStack callstack, org.gjt.sp.jedit.bsh.SimpleNode callerInfo, boolean declaredOnly)` Invoke a method in this namespace with the specified args, interpreter reference, callstack, and caller info.
    `void` | `run()`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### This

          protected This(NameSpace namespace,
              Interpreter declaringInterpreter)

  - ### Method Detail

    - #### getInterface

          public java.lang.Object getInterface(java.lang.Class clas)
                                        throws UtilEvalError

      Get a version of this scripted object implementing the specified interface.
      Throws:
        `UtilEvalError`

    - #### getInterface

          public java.lang.Object getInterface(java.lang.Class[] ca)
                                        throws UtilEvalError

      Get a version of this scripted object implementing the specified interfaces.
      Throws:
        `UtilEvalError`

    - #### getNameSpace

          public NameSpace getNameSpace()

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### run

          public void run()

      Specified by:
        `run` in interface `java.lang.Runnable`

    - #### invokeMethod

          public java.lang.Object invokeMethod(java.lang.String name,
                                      java.lang.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.
      Throws:
        `EvalError`
      See Also:
        `Primitive`

    - #### invokeMethod

          public java.lang.Object invokeMethod(java.lang.String methodName,
                                      java.lang.Object[] args,
                                      Interpreter interpreter,
                                      CallStack callstack,
                                      org.gjt.sp.jedit.bsh.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:
        `callstack` - if callStack is null a new CallStack will be created and initialized with this namespace.
        `declaredOnly` - if true then only methods declared directly in the namespace will be visible - no inherited or imported methods will be visible.
      Throws:
        `EvalError`
      See Also:
        `invokeMethod`, `Primitive`

    - #### bind

          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)