IBM TDI, Version 7.1
The Script Parser enables you to write your own Parser
To operate, a Script Parser must implement a few functions. The
functions do not use parameters.
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 you have the inp BufferedReader
object available for reading character data from a stream. When writing
entries you have the out BufferedWriter object
available for writing character data to a stream.
You can add your own parameters to the configuration and obtain
these by using the parser object.
Common objects (these are the same as for an AssemblyLine):
- The Config Instance (RS object) that is running.
- The AssemblyLine this Parser is a part of.
- A UserFunctions object.
- The configuration for this element, that is, this Parser.
The following objects are the only ones accessible to the script
The result object
- 0 - End of Input
- 1 - Status OK
- 2 - Error
The entry object
- addAttributeValue (name, value)
- Adds a value to an attribute.
- getAttribute (name)
- Returns the named attribute.
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).
The inp object
- Returns next character from stream.
- Returns next CRLF-stopped line from the input stream.
The out object
- write (str)
- Writes a string to the output stream.
- writeln (str)
- Writes a string followed by CRLF to the output stream.
The parser object
- Returns the parameter value associated with parameter name str
- setParam(str, value)
- Sets the parameter str to value value
- Writes the parameter str in the log file
A complete list of methods can be found in the installation package.
The connector object
For more information, see the JavaDocs material included in the
The Parser should supply the following functions, where
relevant for the intended usage in IBM TDI:
- Read the next logical entry from the input stream and populate
the entry object. This function is
not required for Parsers called in add_only situations only.
- Write the contents of the entry object
to the output stream. This function is not required for Parsers that
are only used for reading.
- closeParser ( )
- The closeParser function, if implemented, will be called when
Connector.close is called. For example:
function closeParser ( )
- The flush function will be called if the Parser's flush is called
via the connector.getParser( ).flush( ) method. Implementing these
methods in effect overrides the Parser's methods. For example:
function flush ( )
- The querySchema function is called by the Parser's parent, that is the Connector into which this Parser has been configured.
It is used to discover the Schema of the underlying data source, to
populate the Input and Output maps. See Schema for
The Parser has the following parameters:
- External Files
- If you want to include external script files at runtime, specify
them here, one file on each line. These files are run before your
- Include Global Scripts
- Include scripts from the Script Library.
- Character Encoding
- Character Encoding to be used; the default is UTF-8.
Also see Character Encoding conversion.
- Detailed Log
- If this parameter is checked, more detailed log messages are
- The user-defined script to run.
When you use a Script Connector or Parser, the script
is copied from the Library where it resides and into your configuration
file. This has the advantage that you can customize the script, but
with the disadvantage that new versions are not known to your AssemblyLine.
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 you want specific behavior,
override this function.
In it there are two predefined objects which are accessible from
these two script objects:
- This is a Vector object. The querySchema(Object) function
should add Entry objects to this Vector.
- This is an Object parameter passed to the querySchema(Object) function
when it is called.
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 you can set three
different types of exit codes, calling the predefined result object's
function setStatus(int) with one of the following values:
- 0 - End of Input
- 1 - Status OK
- 2 - Error
For setting more detailed information about the result you 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 your IBM TDI installation.
Scripted Function Component