org.opennms.bb.dp.capsd.utils
Class DiscNewAddressParser

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

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

The DiscNewAddressParser is designed to parse new node addresses that are sent by the discovery process to the capabilities daemon. The SOAP document that is exchanged can be decomposed into the new addresses.

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_IPV4ADDR
          The BlueBird Discovery IPv4Address address.
private  String DISCOVERY_NEWADDR
          The BlueBird Discovery new address found tag.
private  String DISCOVERY_NS
          The BlueBird Discovery namespace uri.
private  StringBuffer m_addrBuf
          A temporary string buffer to store character data when the m_isIPv4Addr is true.
private  List m_addresses
          A list of IPv4Address objects extracted from the document.
private  int m_error
          Set if a tag is in error.
private  boolean m_isIPv4Addr
          Set to true if the IPv4Address tag has been parsed.
private  boolean m_isNewAddr
          Set to true if the OpenNMS NewAddress tag was processed successfully.
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  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.
 
Constructor Summary
DiscNewAddressParser()
          The class constructor creates a new instance of the DiscNewAddressParser.
 
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 getAddresses()
          Returns the list of address 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_addresses

private List m_addresses

A list of IPv4Address 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_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_isNewAddr

private boolean m_isNewAddr

Set to true if the OpenNMS NewAddress tag was processed successfully.


m_isIPv4Addr

private boolean m_isIPv4Addr

Set to true if the IPv4Address tag has been parsed.


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.


DISCOVERY_NEWADDR

private final String DISCOVERY_NEWADDR

The BlueBird Discovery new address found tag.


DISCOVERY_IPV4ADDR

private final String DISCOVERY_IPV4ADDR

The BlueBird Discovery IPv4Address address.


DISCOVERY_NS

private final String DISCOVERY_NS

The BlueBird Discovery namespace uri.

Constructor Detail

DiscNewAddressParser

public DiscNewAddressParser()

The class constructor creates a new instance of the DiscNewAddressParser. 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.

getAddresses

public List getAddresses()

Returns the list of address 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.