com.adventnet.util.parser
Class ParserAPI
java.lang.Object
|
+--com.adventnet.util.parser.ParserAPI
- public class ParserAPI
- extends java.lang.Object
This class can be used to parse any Response (for example, a response obtained for a
CLI Command). The Parsing rules are specified in an XML with Rule names.
The rule names typically would be a CLI command name for a CLI Response
parser. The method parse(String message,String command) should be used to
parse the response message.
|
Constructor Summary |
ParserAPI()
Constructs a ParserAPI instance. |
ParserAPI(java.lang.String parserRulesXML)
Constructs a ParserAPI instance. |
|
Method Summary |
void |
loadParserConfig(java.lang.String fileName)
Loads the Rules XML file. |
java.lang.Object |
parse(java.lang.String message,
java.lang.String parserType,
java.lang.String commandName)
This method does the parsing of the response message and returns the
parsed output as any User Object. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
ParserAPI
public ParserAPI()
throws ParseException
- Constructs a ParserAPI instance. The Parsing rules specified in a file
called ParserRules.xml should be present in the CLASSPATH in order for
the Rules and Parsers loading to succeed. If the ParserRules.xml file is
not present in the CLASSPATH, then the method
loadParserConfig can be used to load the rules file.
- Throws:
- ParseException - thrown if any error occurs while parsing of
the rules XML file.
- See Also:
loadParserConfig(String fileName)
ParserAPI
public ParserAPI(java.lang.String parserRulesXML)
throws ParseException
- Constructs a ParserAPI instance. The Parsing rules in XML is
passed as an argument.
- Parameters:
parserRulesXML - the parser rules file name- Throws:
- ParseException - thrown if any error occurs while parsing of
the rules XML file.
parse
public java.lang.Object parse(java.lang.String message,
java.lang.String parserType,
java.lang.String commandName)
throws ParseException
- This method does the parsing of the response message and returns the
parsed output as any User Object. The message parameter contains the
response and the command is used to identify a particular parsing rule
in the list of rules present in the XML.
- Parameters:
message - the message to be parsed.parserType - the type of the parser to use. The parser will be one
of those present in the Parser configuration file.commandName - the command name which is associated with the
response message- Returns:
- the parsed object as an Object.
- Throws:
- ParseException - thrown if any error occurs while parsing of
the message.
loadParserConfig
public void loadParserConfig(java.lang.String fileName)
throws ParseException
- Loads the Rules XML file. This can be used to load a different XML
other than the one which was loaded at the time of instantiating this
class.
- Parameters:
fileName - the file which contains the Parsing rules.- Throws:
- ParseException - thrown if any error occurs during the parsing
of the Rules file.