org.jawk.ext
Class AbstractExtension

java.lang.Object
  extended by org.jawk.ext.AbstractExtension
All Implemented Interfaces:
JawkExtension
Direct Known Subclasses:
CoreExtension, SocketExtension, StdinExtension

public abstract class AbstractExtension
extends java.lang.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().


Field Summary
protected  JRT jrt
           
protected  VariableManager vm
           
 
Constructor Summary
AbstractExtension()
           
 
Method Summary
protected static void checkNumArgs(java.lang.Object[] arr, int expected_num)
          Verifies that an exact number of arguments has been passed in by checking the length of the argument array.
 int[] getAssocArrayParameterPositions(java.lang.String extension_keyword, int arg_count)
          Assume no guarantee of any extension parameter being an associative array.
 void init(VariableManager vm, JRT jrt)
          Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.
protected  java.lang.String toAwkString(java.lang.Object obj)
          Convert a Jawk variable to a Jawk string based on the value of the CONVFMT variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jawk.ext.JawkExtension
extensionKeywords, getExtensionName, invoke
 

Field Detail

jrt

protected JRT jrt

vm

protected VariableManager vm
Constructor Detail

AbstractExtension

public AbstractExtension()
Method Detail

init

public void init(VariableManager vm,
                 JRT jrt)
Description copied from interface: JawkExtension
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

toAwkString

protected final java.lang.String toAwkString(java.lang.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.

getAssocArrayParameterPositions

public int[] getAssocArrayParameterPositions(java.lang.String extension_keyword,
                                             int arg_count)
Assume no guarantee of any extension parameter being an associative array.

Specified by:
getAssocArrayParameterPositions in interface JawkExtension
Parameters:
extension_keyword - The extension keyword to check.
arg_count - The number of actual parameters used in this extension invocation.
Returns:
An array of parameter indexes containing associative arrays. Note: non-inclusion of a parameter index into this array makes no implication as to whether the parameter is a scalar or an associative array. It means that its type is not guaranteed to be an associative array.

checkNumArgs

protected static final void checkNumArgs(java.lang.Object[] arr,
                                         int expected_num)
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.
expected_num - The expected number of arguments.
Throws:
IllegalAwkArgumentException - if the number of arguments do not match the expected number of arguments.