org.jawk.ext
Class CoreExtension

java.lang.Object
  extended by org.jawk.ext.AbstractExtension
      extended by org.jawk.ext.CoreExtension
All Implemented Interfaces:
JawkExtension

public class CoreExtension
extends AbstractExtension
implements JawkExtension

Extensions which make developing in Jawk and interfacing other extensions with Jawk much easier.

The extension functions which are available are as follows:

Reference Management

AWK's memory model provides only 4 types of variables for use within AWK scripts: Variables can hold any of these types. However, unlike for scalar types (integer/double/string), AWK applies the following restrictions with regard to associative arrays: These restrictions, while sufficient for AWK, are detrimental to extensions because associative arrays are excellent vehicles for configuration and return values for user extensions. Plus, associative arrays can be subclassed, which can be used to enforce type safety within user extensions. Unfortunately, the memory model restrictions make using associative arrays in this capacity very difficult.

We attempt to alleviate these difficulties by adding references to Jawk via the CoreExtension module. References convert associative arrays into unique strings called reference handles. Since reference handles are strings, they can be assigned and returned via AWK functions without restriction. And, reference handles are then used by other reference extension functions to perform common associative array operations, such as associative array cell lookup and assignment, key existence check, and key iteration.

The reference model functions are explained below:


Field Summary
 
Fields inherited from class org.jawk.ext.AbstractExtension
jrt, vm
 
Constructor Summary
CoreExtension()
           
 
Method Summary
 java.lang.String[] extensionKeywords()
          All the extended keywords supported by this extension.
 int[] getAssocArrayParameterPositions(java.lang.String extension_keyword, int num_args)
          Assume no guarantee of any extension parameter being an associative array.
 java.lang.String getExtensionName()
          The name of the extension package.
 java.lang.Object invoke(java.lang.String keyword, java.lang.Object[] args)
          Invoke extension as a method.
 
Methods inherited from class org.jawk.ext.AbstractExtension
checkNumArgs, init, toAwkString
 
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
init
 

Constructor Detail

CoreExtension

public CoreExtension()
Method Detail

getExtensionName

public java.lang.String getExtensionName()
Description copied from interface: JawkExtension
The name of the extension package.

Specified by:
getExtensionName in interface JawkExtension

extensionKeywords

public java.lang.String[] extensionKeywords()
Description copied from interface: JawkExtension
All the extended keywords supported by this extension.

Note: Jawk will throw a runtime exception if the keyword collides with any other keyword in the system, extension or otherwise.

Specified by:
extensionKeywords in interface JawkExtension

getAssocArrayParameterPositions

public int[] getAssocArrayParameterPositions(java.lang.String extension_keyword,
                                             int num_args)
Description copied from class: AbstractExtension
Assume no guarantee of any extension parameter being an associative array.

Specified by:
getAssocArrayParameterPositions in interface JawkExtension
Overrides:
getAssocArrayParameterPositions in class AbstractExtension
Parameters:
extension_keyword - The extension keyword to check.
num_args - 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.

invoke

public java.lang.Object invoke(java.lang.String keyword,
                               java.lang.Object[] args)
Description copied from interface: JawkExtension
Invoke extension as a method.

Specified by:
invoke in interface JawkExtension
Parameters:
keyword - The extension keyword.
args - Arguments to the extension.
Returns:
The return value (result) of the extension.