Class SimpleHook

java.lang.Object
com.scriptbasic.spi.SimpleHook
All Implemented Interfaces:
InterpreterHook
Direct Known Subclasses:
RunLimitHook

public abstract class SimpleHook extends Object implements InterpreterHook
A simple implementation of the InterpreterHook.

This hook does nothing, only calls the next in the hook chain. Classes implementing hooks may use the pleasant feature of this hook that it implements empty methods for each hook method of the interface. For example the method beforeExecute calls the method beforeExecuteEx and then it calls on the chain. A hook extending this class instead of implementing the interface need not implement hook methods that are empty and need not care about not to break the chain.

Author:
Peter Verhas date Aug 3, 2012
  • Constructor Details

    • SimpleHook

      public SimpleHook()
  • Method Details

    • getInterpreter

      protected Interpreter getInterpreter()
      Returns:
      the interpreter
    • setInterpreter

      public void setInterpreter(Interpreter interpreter)
      Description copied from interface: InterpreterHook
      During registration the interpreter calls this method to make the interpreter accessible for the hook objects.
      Specified by:
      setInterpreter in interface InterpreterHook
      Parameters:
      interpreter - the interpreter to set
    • setNext

      public void setNext(InterpreterHook next)
      Description copied from interface: InterpreterHook
      When a hook is registered the registering process calls this method and passes the next element in the hook chain. The hook object should remember this object and call the appropriate methods when that is called not to break the chain.
      Specified by:
      setNext in interface InterpreterHook
      Parameters:
      next - the next element in the chain.
    • beforeExecute

      public void beforeExecute(Command command)
      Description copied from interface: InterpreterHook
      This method is called before the interpreter executes a command.
      Specified by:
      beforeExecute in interface InterpreterHook
      Parameters:
      command - the command object to be executed
    • beforeExecute

      public void beforeExecute()
      Description copied from interface: InterpreterHook
      This method is called before the execution of the program starts.
      Specified by:
      beforeExecute in interface InterpreterHook
    • beforeExecuteEx

      public void beforeExecuteEx()
    • beforeExecuteEx

      public void beforeExecuteEx(Command command)
      Parameters:
      command - parameter
    • afterExecute

      public void afterExecute(Command command)
      Description copied from interface: InterpreterHook
      This method is called after the interpreter executed a command.
      Specified by:
      afterExecute in interface InterpreterHook
      Parameters:
      command - the command just executed.
    • afterExecuteEx

      public void afterExecuteEx(Command command)
      Parameters:
      command - parameter
    • afterExecute

      public void afterExecute()
      Description copied from interface: InterpreterHook
      This method is called after the execution of the whole program has finished.
      Specified by:
      afterExecute in interface InterpreterHook
    • afterExecuteEx

      public void afterExecuteEx()
    • beforeRegisteringJavaMethod

      public void beforeRegisteringJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes)
      Description copied from interface: InterpreterHook
      This method is called before registering a java method into the interpreter.
      Specified by:
      beforeRegisteringJavaMethod in interface InterpreterHook
      Parameters:
      alias - the name of the function as it will be known to the BASIC program.
      klass - the Java class where the static method is.
      methodName - the Java name of the method
      argumentTypes - the argument types of the methods. This, together with the name of the method and the class identifies the actual method that will be available to the BASIC programs to be called through the name alias.
    • beforeRegisteringJavaMethodEx

      public void beforeRegisteringJavaMethodEx(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes)
      Parameters:
      alias - parameter
      klass - parameter
      methodName - parameter
      argumentTypes - parameter
    • beforePush

      public void beforePush(Command command)
      Specified by:
      beforePush in interface InterpreterHook
      Parameters:
      command - parameter
    • beforePushEx

      public void beforePushEx(Command command)
      Parameters:
      command - parameter
    • afterPush

      public void afterPush(Command command)
      Specified by:
      afterPush in interface InterpreterHook
      Parameters:
      command - parameter
    • afterPushEx

      public void afterPushEx(Command command)
      Parameters:
      command - parameter
    • beforePop

      public void beforePop()
      Specified by:
      beforePop in interface InterpreterHook
    • beforePopEx

      public void beforePopEx()
    • afterPop

      public void afterPop(Command command)
      Specified by:
      afterPop in interface InterpreterHook
      Parameters:
      command - parameter
    • afterPopEx

      public void afterPopEx(Command command)
      Parameters:
      command - parameter
    • setReturnValue

      public void setReturnValue(RightValue returnValue)
      Description copied from interface: InterpreterHook
      This method is called after a subroutine has set its return value. It is possible to modify the return value calling back to the interpreter but it has to be only invoked together with Interpreter.disableHook() and Interpreter.enableHook().
      Specified by:
      setReturnValue in interface InterpreterHook
      Parameters:
      returnValue - parameter
      See Also:
    • setReturnValueEx

      public void setReturnValueEx(RightValue returnValue)
      Parameters:
      returnValue - parameter
    • beforeSubroutineCall

      public void beforeSubroutineCall(String subroutineName, LeftValueList arguments, RightValue[] argumentValues)
      Description copied from interface: InterpreterHook
      This method is called before the interpreter invokes a subroutine. At this point the local variables are those of the subroutine to be called.
      Specified by:
      beforeSubroutineCall in interface InterpreterHook
      Parameters:
      subroutineName - the symbolic name of the subroutine
      arguments - the argument left values
      argumentValues - the argument evaluated values that were assigned to the local variable table to the arguments
    • beforeSubroutineCallEx

      public void beforeSubroutineCallEx(String subroutineName, LeftValueList arguments, RightValue[] argumentValues)
      Parameters:
      subroutineName - parameter
      arguments - parameter
      argumentValues - parameter
    • beforeCallJavaFunction

      public void beforeCallJavaFunction(Method method)
      Specified by:
      beforeCallJavaFunction in interface InterpreterHook
      Parameters:
      method - parameter
    • beforeCallJavaFunctionEx

      public void beforeCallJavaFunctionEx(Method method)
      Parameters:
      method - parameter
    • afterCallJavaFunction

      public Object afterCallJavaFunction(Method method, Object result)
      Description copied from interface: InterpreterHook
      This method is called when the interpreter was calling a Java static method. The
      Specified by:
      afterCallJavaFunction in interface InterpreterHook
      Parameters:
      method - the method that was called
      result - the result that the static method returned
      Returns:
      the modified result or just the same object if the hook does not want to modify the result
    • afterCallJavaFunctionEx

      public Object afterCallJavaFunctionEx(Method method, Object result)
      Parameters:
      method - parameter
      result - the original result returned by the Java
      Returns:
      the result object unmodified
    • variableRead

      public RightValue variableRead(String variableName, RightValue value)
      Description copied from interface: InterpreterHook
      This hook is called when the interpreter accesses a variable.
      Specified by:
      variableRead in interface InterpreterHook
      Parameters:
      variableName - the name of the variable
      value - the value of the variable when accessed
      Returns:
      the value that will be used. The implementation may decide to alter the value used. Returning a modified value will not, however alterthe value of the variable itself.
    • variableReadEx

      public RightValue variableReadEx(String variableName, RightValue value)
      Parameters:
      variableName - parameter
      value - parameter
      Returns:
      return value
    • init

      public void init()
      Description copied from interface: InterpreterHook
      This method is called at the end of the hook registering. When this method is called the hook does have interpreter and the field 'next' already set. The method should do its initialization and then call the same method of the next hook in the chain.
      Specified by:
      init in interface InterpreterHook
    • initEx

      public void initEx()