Class ScriptingContext.BindingSwapper

java.lang.Object
org.bzdev.scripting.ScriptingContext.BindingSwapper
Enclosing class:
ScriptingContext

public static class ScriptingContext.BindingSwapper extends Object
Class to allow two sets of bindings associated with a ScriptingContext to be swapped. The method ScriptingContext.createBindingSwapper(Bindings) is used to create instances of this class, and that method is protected. Subclasses of ScriptingContext can create instances of BindingSwapper, provided the subclasses have the necessary permissions. As a result, the ability to swap bindings can be restricted to specific classes.

Most applications should not need to create binding swappers. The class was created to support classes in the package org.bzdev.devqsim. The ScriptingContext class does not provide a public method that returns a script engine, nor a public method to set its bindings. Some methods such as evalScript, however, allow alternate bindings to be used, and will keep the old bindings on a stack, restoring those with the method exits. A binding swapper can be used to swap those temporary bindings with the script engine's default bindings. For example, the devqsim package has a class named TaskThread that uses a binding swapper to temporarily change the current bindings to the default bindings when a thread is being paused because the simulation may be running in a script and needs those original bindings for instrumentation-related tasks that occur as threads are suspended and restored.

  • Method Details

    • swap

      public void swap()
      Switch from one binding to the other.