AdventNet CLI 2.0 API Specification

com.adventnet.util.parser.generic
Class MessageParser

java.lang.Object
  |
  +--com.adventnet.util.parser.generic.MessageParser

public class MessageParser
extends java.lang.Object

This class parses a message stream and splits it into String tokens based on Delimiter definitions in an XML File. This class can be used to parse the CLI Responses obtained from the syncSend() or send() method in the CLISession.


Constructor Summary
MessageParser()
          Constructor for the Parser.
MessageParser(java.lang.String rulesFile)
          Constructor for the Parser.
 
Method Summary
 java.util.Vector getMatchList()
          Gets the Parameters extracted from the Response as a Vector of Hashtables.
 java.lang.String getRulesFileName()
          Gets the Rule File name.
 java.lang.String getVersion()
          Gets the Message Parser version in the XML.
 java.util.Vector parseIntoTokens(java.lang.String message)
          Splits the message into tokens based on the Delimiter.
 void parseRule(java.lang.String rule)
          Parses the rule given as a String.
 void setRulesFileName(java.lang.String rulesFileName)
          Sets the Rule File name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageParser

public MessageParser()
              throws ParseException
Constructor for the Parser.
Throws:
ParseException - when an error occurs during initialisation.

MessageParser

public MessageParser(java.lang.String rulesFile)
              throws ParseException
Constructor for the Parser. Takes the Rules file name (eg XML)as argument. This will parse the message and store the Token information from the Rules file.
Parameters:
rulesFile - the Rule file name (eg an XML file name).
Throws:
ParseException - When an error occurs during parsing the rule file.
Method Detail

parseRule

public void parseRule(java.lang.String rule)
               throws ParseException
Parses the rule given as a String. Takes the Rule as a String and parses it.
Parameters:
rule - the rule as a String
Throws:
ParseException - when an error occurs during parsing of the rul.

getRulesFileName

public java.lang.String getRulesFileName()
Gets the Rule File name.
Returns:
the Rule file name (for instance an XML file name).

setRulesFileName

public void setRulesFileName(java.lang.String rulesFileName)
                      throws ParseException
Sets the Rule File name. This will internally parse the file and throw a ParseException in case any error is encountered.
Parameters:
rulesFileName - the xml File name.
Throws:
ParseException - When an error occurs during parsing the rule file.

getVersion

public java.lang.String getVersion()
Gets the Message Parser version in the XML.
Returns:
the parser version.

parseIntoTokens

public java.util.Vector parseIntoTokens(java.lang.String message)
Splits the message into tokens based on the Delimiter. The message is split in the order in which the delimiters are encountered.
Parameters:
message - the message to parse (eg the CLI response).
Returns:
the Vector of tokens (Strings) contained in the message.

For example to parse a CLI response do the following:

 try{
 MessageParser cliParser = new MessageParser("test.xml");
 Vector tokens = cliParser.parseIntoTokens(mesg);
 Enumeration en = tokens.elements();
 while(en.hasMoreElements()){
		System.out.println(en.nextElement());
	}
 }catch(Exception e){
	 System.out.println("Error while parsing message:");
	 System.out.println(e);
	 System.exit(1);
 }
 
Assuming the 'mesg' contains the message and test.xml the rules XML file.

getMatchList

public java.util.Vector getMatchList()
Gets the Parameters extracted from the Response as a Vector of Hashtables. Each Hashtable contains the Parameter Name as Key and the Parameter Value as the Value. The Parameter Name are those defined in the XML file used to parse the response. Each Hashtable corresponds to one group of parameters in the Response.
Returns:
Vector of Hashtables containing the parameter value and name.

AdventNet CLI 2.0 API Specification