Implementing a Custom Field Parser

If none of the standard parsing strategies allow you to correctly parse data from the message buffer, you can customize the field parser in a message definition.

  1. In Sybase WorkSpace, configure a Java project and Java builder settings.
  2. Write custom logic to parse a field type and implement the com.sybase.jtf.parser.api.ICustomParserField interface.

    The return value is the number of bytes consumed or -1, which indicates failure.

    The parameter of type com.sybase.jtf.parser.api.ParseResult is passed by reference and represents the result of the parse. This object indicates where the parsed data lies in the original message buffer (the first parameter in the iCustomParserField.parseField method).

    Table 1. Methods relevant to populating a ParseResult
    Method Description
    ParseResult.setFieldPosition(int fieldPosition) Sets the zero-based index of the starting position of the field data.
    ParseResult.setLength(int length) Sets the length (in bytes) of the data.
    ParseResult.setResult(int fieldPosition, int length) Equivalent to calling ParseResult.setLength and ParseResult.setFieldPosition .
    ParseResult.setErrorMessage(String message) Sets an error message that is reported if ICustomParserField.parseField returns -1 and the field is mandatory.
    ParseResult.setErrorMessage(String message, Object[] parameters) Sets an error message that is reported if ICustomParserField.parseField returns -1 and the field is mandatory.

    The parameter of type String is a formattable string (for example, 'error {0}, caused by {1}'), and each object in the Object array must have the toString method called to supply the appropriate values in the formattable string.

    The result of this process is a custom class that is an extension point of a field.

  3. Export the custom code as a JAR file and put the file into the CustomClasses directory under the MessageDesigns directory.
  4. If the custom code JAR file requires any supporting JAR files, put the supporting JAR files in CustomClasses directory as well.
  5. Modify the Class-Path variable for the custom code JAR file and any supporting JAR files.
    For example:
    $ cat manifestChange.txt 
     Class-Path: MyUtils.jar
    $ jar ufm customField.jar manifestChange.txt 
    
    Note: For more information about adding classes to the JAR file's classpath, see Adding Classes to the JAR File's Classpath at the Sun Java Tutorials documentation Web site.

    Message Designer can now instantiate the class when the custom field JAR is loaded in the following steps when you insert the custom field code into a message definition and at runtime.

  6. To start Sybase WorkSpace, select Start > Programs > Sybase > Sybase WorkSpace > Sybase WorkSpace <version>.
  7. To start the Service Container server, select Start > Programs > Sybase > Sybase WorkSpace > SC <version> > Start SC.
  8. In the WorkSpace Navigator of the Service Development perspective, expand the project folder that contains the message definition with which you want to work, then expand the MessageDesigns and MessageDefinitions folders.
  9. Double-click the message definition file, which has a .wfim file name extension.

    The message definition file opens in the Message Definition editor.

  10. Select the Message Details tab.
  11. In the Message Definition pane, expand the message definition containers and select the field in which to use the custom field code.
  12. In the Field Properties pane, select the Custom Field Parser, then click the ellipsis button to the right of that option.

    The Custom Field Parser dialog box opens.

  13. Select the custom field JAR and the class desired for the field and click OK.

    Repeat this step to add the custom field code to other fields in the message definition.

  14. Select File > Save from the main menu bar.

    The custom code is added to a message definition.

Next 

Test the message definition.

Related tasks
Testing a Message Definition
Developing a Message Definition
Implementing a Custom Field Serializer
Implementing a Custom Parser Extension
Adding a Field to a Message Definition
Related reference
Custom Field Parsers

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.