org.opennms.bb.dp.poller.parsers
Class MonitorResponseParser

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--org.opennms.bb.dp.poller.parsers.MonitorResponseParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public final class MonitorResponseParser
extends org.xml.sax.helpers.DefaultHandler

The MonitorResponseParser is designed to parse ICMP monitor responses from discovery. The SOAP document that is exchanged can be decomposed into an ICMP poll reply including (but not limited to) IPv4 address, number of retries and timeout (ms).

In order to use the class, first create an instance of an XML parser using the Xerces SAXPaser class. Then set an instance of this class as the ErrorHandler and the ContentHandler. After seting up the parser just call the parse method. If the parser fails then the list of address returned will be null.

See Also:
SAXParser, ContentHandler, ErrorHandler, DefaultHandler

Field Summary
private  String DISCOVERY_NS
          The BlueBird Discovery namespace uri.
private  String IPV4ADDR
           
private  StringBuffer m_addrBuf
          A temporary string buffer to store character data when the m_isIPv4Addr is true.
private  int m_error
          Set if a tag is in error.
private  boolean m_isIPv4Addr
           
private  boolean m_isMonitorResponse
          Set to true if the corresponding tag was processed successfully.
private  boolean m_isResponse
           
private  boolean m_isSoapCompliantBody
          Set to true if the SOAP body tag was processed successfully
private  boolean m_isSoapCompliantEnv
          Set to true if the SOAP envlope was processed successfully.
private  boolean m_isStatus
           
private  List m_responses
          A list of response objects extracted from the document.
private  StringBuffer m_statusBuf
          A temporary string buffer to store character data when the m_isStatus is true.
private  String MONITOR_RESPONSE
           
private  String RESPONSE
           
private  String SOAP_BODY
          The SOAP Body tag
private  String SOAP_ENV
          The SOAP Envelope tag
private  String SOAP_NS
          The SOAP envelope namespace that is required for SOAP conformance.
private  String STATUS
           
 
Constructor Summary
MonitorResponseParser()
          The class constructor creates a new instance of the MonitorResponseParser.
 
Method Summary
 void characters(char[] data, int offset, int length)
          This method is used to receive event notifiaction of character data.
 void endElement(String uri, String localName, String qName)
          Called to process the end of an element for the document.
 void error(org.xml.sax.SAXParseException ex)
          The error handler is invoked by the parser when a recoverable error occurs parsing the document.
 void fatalError(org.xml.sax.SAXParseException ex)
          The fatal error handler is invoked by the parser when a non-recoverable error occurs parsing the document.
 List getResponses()
          Returns the list of responses recovered by the parser.
static void main(String[] args)
          A sample test program.
 void startDocument()
          The startDocument method is called by the xerces parser when a new document is started.
 void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes)
          Called to process the start of a new element for the document.
 void warning(org.xml.sax.SAXParseException ex)
          The warning handler is invoked by the parser when a recoverable error occurs parsing the document.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_responses

private List m_responses

A list of response objects extracted from the document.


m_addrBuf

private StringBuffer m_addrBuf

A temporary string buffer to store character data when the m_isIPv4Addr is true.


m_statusBuf

private StringBuffer m_statusBuf

A temporary string buffer to store character data when the m_isStatus is true.


m_isSoapCompliantEnv

private boolean m_isSoapCompliantEnv

Set to true if the SOAP envlope was processed successfully.


m_isSoapCompliantBody

private boolean m_isSoapCompliantBody

Set to true if the SOAP body tag was processed successfully


m_isMonitorResponse

private boolean m_isMonitorResponse

Set to true if the corresponding tag was processed successfully.


m_isResponse

private boolean m_isResponse

m_isIPv4Addr

private boolean m_isIPv4Addr

m_isStatus

private boolean m_isStatus

m_error

private int m_error

Set if a tag is in error. Each call to start element will increment the tag, if non-zero. Each call to end element will decrement the tag, if non-zero. This keeps tags from being processed when an error occurs until the corresponding end tag is caught.


SOAP_ENV

private final String SOAP_ENV

The SOAP Envelope tag


SOAP_BODY

private final String SOAP_BODY

The SOAP Body tag


SOAP_NS

private final String SOAP_NS

The SOAP envelope namespace that is required for SOAP conformance.


MONITOR_RESPONSE

private final String MONITOR_RESPONSE

RESPONSE

private final String RESPONSE

IPV4ADDR

private final String IPV4ADDR

STATUS

private final String STATUS

DISCOVERY_NS

private final String DISCOVERY_NS

The BlueBird Discovery namespace uri.

Constructor Detail

MonitorResponseParser

public MonitorResponseParser()

The class constructor creates a new instance of the MonitorResponseParser. The parser is used to decompose SOAP messages from the discovery system about addresses the discovery system found.

Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException

The startDocument method is called by the xerces parser when a new document is started. If the instance previously contained any data, then it is lost since the class is reset to its initial state. This allows for an instance to be reused to parse new document and avoid creating new instances.

Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Thrown if an error occurs parsing the start of the document.

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException

Called to process the start of a new element for the document. If namespaces are enabled, then the uri will be a valid namesapce. See the base class for more information.

Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The XML namespace.
localName - The local name with the namespace prefix.
qName - The qualified name (includs namepace prefix).
attributes - The attributes associated with the element.
Throws:
org.xml.sax.SAXException - Thrown if a processing error occurs.

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws org.xml.sax.SAXException

Called to process the end of an element for the document. If namespaces are enabled, then the uri will be a valid namesapce. See the base class for more information.

Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The XML namespace.
localName - The local name with the namespace prefix.
qName - The qualified name (includs namepace prefix).
Throws:
org.xml.sax.SAXException - Thrown if a processing error occurs.

characters

public void characters(char[] data,
                       int offset,
                       int length)
                throws org.xml.sax.SAXException

This method is used to receive event notifiaction of character data. The character data is attached to the last tag that was processed by the startElement method.

The character data in this method is ignored unless an address tag is being processed. No validation is performed to ensure that non-data elements have no data.

Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
data - The character data from the parser.
offset - The offset in the data buffer that is valid.
length - The length of valid data from the offset.
Throws:
org.xml.sax.SAXException - Thrown if a processing error occurs.

warning

public void warning(org.xml.sax.SAXParseException ex)
             throws org.xml.sax.SAXException

The warning handler is invoked by the parser when a recoverable error occurs parsing the document.

Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
ex - The exception that occured.
Throws:
org.xml.sax.SAXException - Thrown if an error occurs processing the exception.

error

public void error(org.xml.sax.SAXParseException ex)
           throws org.xml.sax.SAXException

The error handler is invoked by the parser when a recoverable error occurs parsing the document.

Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
ex - The exception that occured.
Throws:
org.xml.sax.SAXException - Thrown if an error occurs processing the exception.

fatalError

public void fatalError(org.xml.sax.SAXParseException ex)
                throws org.xml.sax.SAXException

The fatal error handler is invoked by the parser when a non-recoverable error occurs parsing the document.

Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Parameters:
ex - The exception that occured.
Throws:
org.xml.sax.SAXException - Thrown if an error occurs processing the exception.

getResponses

public List getResponses()

Returns the list of responses recovered by the parser.


main

public static void main(String[] args)

A sample test program. Creates an instance of the parser and parses each file passed on the command line. Once the each file is parse, the address(es) in the file are printed to the commmand line.

This is used solely for debugging and development testing.

Parameters:
args - The arguments to main.