Package io.jawk.ext

Class AbstractExtension

java.lang.Object
io.jawk.ext.AbstractExtension
All Implemented Interfaces:
JawkExtension
Direct Known Subclasses:
GawkExtension, StdinExtension

public abstract class AbstractExtension extends Object implements JawkExtension
Base class of various extensions.

Provides functionality common to most extensions, such as VM and JRT variable management, and convenience methods such as checkNumArgs() and toAwkString().

Author:
Danny Daglas
  • Constructor Details

    • AbstractExtension

      public AbstractExtension()
  • Method Details

    • getExtensionName

      public String getExtensionName()

      getExtensionName.

      Specified by:
      getExtensionName in interface JawkExtension
      Returns:
      name of the extension package.
    • init

      public void init(VariableManager vmParam, JRT runtime, AwkSettings conf)
      Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.

      It is guaranteed init() is called before invoke() is called.

      Specified by:
      init in interface JawkExtension
      Parameters:
      vmParam - Reference to the Variable Manager
      runtime - Reference to the Runtime
      conf - Reference to the settings
    • toAwkString

      protected final String toAwkString(Object obj)
      Convert a Jawk variable to a Jawk string based on the value of the CONVFMT variable.
      Parameters:
      obj - The Jawk variable to convert to a Jawk string.
      Returns:
      A string representation of obj after CONVFMT has been applied.
    • checkNumArgs

      protected static void checkNumArgs(Object[] arr, int expectedNum)
      Verifies that an exact number of arguments has been passed in by checking the length of the argument array.
      Parameters:
      arr - The arguments to check.
      expectedNum - The expected number of arguments.
    • getJrt

      protected JRT getJrt()

      Getter for the field jrt.

      Returns:
      the Runtime
    • getVm

      protected VariableManager getVm()

      Getter for the field vm.

      Returns:
      the Variable Manager
    • getSettings

      protected AwkSettings getSettings()

      Getter for the field settings.

      Returns:
      the Settings
    • getExtensionFunctions

      public Map<String,ExtensionFunction> getExtensionFunctions()
      Returns the mapping between Awk keywords and the functions implemented by this extension. The returned map must be unmodifiable.
      Specified by:
      getExtensionFunctions in interface JawkExtension
      Returns:
      mapping from keyword to ExtensionFunction
    • beforeStart

      public void beforeStart(AVM avm, JRT runtime)
      Called after the runtime global variable slots have been allocated and before the first executable tuple runs.
      Specified by:
      beforeStart in interface JawkExtension
      Parameters:
      avm - interpreter instance about to execute the tuple stream
      runtime - runtime services associated with avm