The Script Parser enables you to write our own Parser using JavaScript™.
To operate, a Script Parser must implement a few functions. The functions do not use parameters.
The script for the Script Parser is running in a separate JavaScript Engine. This means that the script cannot access any variables that are available, or have been set, in the normal Hooks of an AssemblyLine.
Passing data between the hosting Connector and the script is done by using predefined objects. One of these predefined objects is the result object which is used to communicate status information. Upon entry into either function, the status field is set to normal which causes the hosting Parser to continue calls. Signaling end-of-input or errors is done by setting the status and message fields in this object. The entry object is populated on calls to writeEntry and is expected to be populated in the readEntry function. When reading entries we have the inp BufferedReader object available for reading character data from a stream. When writing entries we have the out BufferedWriter object available for writing character data to a stream.
We can add our own parameters to the configuration and obtain these by using the parser object.
Common objects (these are the same as for an AssemblyLine):
The following objects are the only ones accessible to the script Parser:
A complete list of available methods, including parameters and return values, can be found in the Javadocs (TDI_install_dir/docs/api/com/ibm/di).
A complete list of methods can be found in the installation package.
For more information, see the JavaDocs material included in the installation package.
The Parser should supply the following functions, where relevant for the intended usage in IBM TDI:
function closeParser ( ) { task.logmsg("CLOSE CALLED."); }
function flush ( ) { task.logmsg("FLUSH CALLED."); }
The Parser has the following parameters:
When we use a Script Connector or Parser, the script is copied from the Library where it resides and into our configuration file. This has the advantage that we can customize the script, but with the disadvantage that new versions are not known to our AssemblyLine.
To work around this disadvantage, remove the old Script Parser from the AssemblyLine and re-introduce it.
A sample querySchema function is provided in the configuration parameter Script. It assumes the default case where we read from a text file one line at a time; hence, the schema returned from this function has only one field named 'line' of type java.lang.String. If we want specific behavior, override this function.
In it there are two predefined objects which are accessible from these two script objects:
For building a meaningful query schema populate the predefined list object with entries containing at least one attribute called "name" and optional attributes: "syntax" or "extsyntax". This can be done by creating an Entry object and calling its addAttributeValue function to set the desired values to the attributes.
According to the success in retrieving schema we can set three different types of exit codes, calling the predefined result object's function setStatus(int) with one of the following values:
For setting more detailed information about the result we can use the setMessage(String) function which takes one textual parameter. Only if the exit code is 1 a schema is returned by the querySchema(Object) function, otherwise null is returned.
Go to the root_directory/examples/script_parser directory of the IBM TDI installation.
Script Connector,
Scripted Function Component
"JavaScript Parser" in IBM TDI V7.1 Users Guide.