org.opennms.bb.common.utils
Class BBParser

java.lang.Object
  |
  +--org.opennms.bb.common.utils.BBParser
Direct Known Subclasses:
AdminMainUserProfParser, CapsdPluginParser, DiscIcebergParser, DiscPollersParser, DPControlPollersParser, DPControlUserProfParser, DPPollerPerfParser, EUIDataParser, EUIEventsParser, EUIMenuParser, EUIUserProfParser, EventsParser, FilterSchemaParser, LoginParser, ModelsParser, onetimeXmlParser, PackageParser, packageXmlParser, ParserBase, PitXmlParser, pollerXmlParser, repcalXmlParser, ServiceModelsParser, ServiceXmlParser, SMUserProfParser, SnmpUserProfParser, SnmpXmlParser

public class BBParser
extends Object

BBParser provides basic XML parsing functionality to parse XML
 from a file or an input stream

 BBParser creates a DOMParser which creates a DOM tree of the XML being
 parsed. BBParser provides the error handling routines for the DOM parser
 and provides some methods to traverse the elements of the DOM tree 
 created as a result of the parse.

 The DOMParser created throws an IOException if the xml file is not found
 or if the xml does not conform to its DTD. In addition to this,
 BBParser and its sub-classes can set their own exception messages and throw
 exceptions if the values read are not what is expected.

 Sub-classes will need to override the 'processElement()' method and
 implement their own storage and data getter methods specific to the XML
 that is being processed

Version:
$Revision: 1.9 $
Author:
Sowmya, OpenNMS

Inner Class Summary
private  class BBParser.BBErrorHandler
          Class BBErrorHandler implements the org.xml.sax.ErrorHandler interface - this is then set as the error handler for the DOMParser to track errors
 
Field Summary
protected  int ATTRIB_VALUE_PAIR_ERR
          Error number set when a typical .. block does not have both the parm name and value pair as expected
protected  String ATTRIB_VALUE_PAIR_ERR_STR
          Error message set when the ATTRIB_VALUE_PAIR error occurs
protected  int EXCEPTION
          Error number set by default when there is an exception
protected  StringBuffer m_curElement
          Element currently being processed - will need to be set as the sub-class goes through the DOM tree
protected  int m_errNum
          The error number set when an error is encountered
protected  String m_exceptionMsg
          The error message set when an error is encountered
protected  org.xml.sax.InputSource m_inpSource
          Input Stream being parsed
protected  org.apache.xerces.parsers.DOMParser m_parser
          DOM parser that builds the DOM tree
protected  int NULL_VALUE_ERR
          Error number set when the value read is null
protected  String NULL_VALUE_ERR_STR
          Error message set when the value read is null
 
Constructor Summary
BBParser()
          Default constructor - creates the DOMParser
 
Method Summary
 String getErrorMessage()
          Returns the error message for the parse
 int getErrorNumber()
          Returns the error number for the parse
 void parse()
          Parse the already set 'm_inpSource'
 void parse(org.xml.sax.InputSource inpSource)
          Parses the input stream passed
 void parse(InputStream inpStream)
          Parses the input stream passed
 void parse(String fileName)
          Parse the fileName passed
protected  boolean processDocument(org.w3c.dom.Document doc)
          Process the 'Document' object or the root of the DOM tree
protected  boolean processElement(org.w3c.dom.Element el, boolean isRoot)
          This is the method to be overridden by sub-classes to branch off and go through the DOM tree to handle elements specific to the XML they are parsing - does nothing here
protected  boolean processNode(org.w3c.dom.Node node)
          Processes a 'Node' object of the DOM tree depending upon the node type
protected  String processParmValue(org.w3c.dom.Node parmValueNode)
          Returns the value from a "2s" type node
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

ATTRIB_VALUE_PAIR_ERR

protected final int ATTRIB_VALUE_PAIR_ERR
Error number set when a typical .. block does not have both the parm name and value pair as expected

NULL_VALUE_ERR

protected final int NULL_VALUE_ERR
Error number set when the value read is null

EXCEPTION

protected final int EXCEPTION
Error number set by default when there is an exception

ATTRIB_VALUE_PAIR_ERR_STR

protected final String ATTRIB_VALUE_PAIR_ERR_STR
Error message set when the ATTRIB_VALUE_PAIR error occurs

NULL_VALUE_ERR_STR

protected final String NULL_VALUE_ERR_STR
Error message set when the value read is null

m_curElement

protected StringBuffer m_curElement
Element currently being processed - will need to be set as the sub-class goes through the DOM tree

m_exceptionMsg

protected String m_exceptionMsg
The error message set when an error is encountered

m_errNum

protected int m_errNum
The error number set when an error is encountered

m_parser

protected org.apache.xerces.parsers.DOMParser m_parser
DOM parser that builds the DOM tree

m_inpSource

protected org.xml.sax.InputSource m_inpSource
Input Stream being parsed
Constructor Detail

BBParser

public BBParser()
Default constructor - creates the DOMParser
Method Detail

processDocument

protected boolean processDocument(org.w3c.dom.Document doc)
Process the 'Document' object or the root of the DOM tree
Returns:
true if the tree traversal is successful, false otherwise

processNode

protected boolean processNode(org.w3c.dom.Node node)
Processes a 'Node' object of the DOM tree depending upon the node type
Returns:
true if the node is read succefully

processElement

protected boolean processElement(org.w3c.dom.Element el,
                                 boolean isRoot)
This is the method to be overridden by sub-classes to branch off and go through the DOM tree to handle elements specific to the XML they are parsing - does nothing here
Returns:
true if processed sucessfully, false otherwise

processParmValue

protected String processParmValue(org.w3c.dom.Node parmValueNode)
Returns the value from a "2s" type node
Returns:
the value from a "2s" type node

parse

public void parse()
           throws IOException
Parse the already set 'm_inpSource'
Throws:
throws - java.io.IOException if parse fails for any reason

parse

public void parse(String fileName)
           throws IOException
Parse the fileName passed
Parameters:
fileName - file to be parsed
Throws:
throws - java.io.IOException if parse fails for any reason

parse

public void parse(InputStream inpStream)
           throws IOException
Parses the input stream passed
Parameters:
inpStream - the java.io.InputStream that contains the XML to be parsed
Throws:
throws - java.io.IOException if parse fails for any reason

parse

public void parse(org.xml.sax.InputSource inpSource)
           throws IOException
Parses the input stream passed
Parameters:
inpStream - the org.xml.sax.InputSource that contains the XML to be parsed
Throws:
throws - java.io.IOException if parse fails for any reason

getErrorNumber

public int getErrorNumber()
Returns the error number for the parse

getErrorMessage

public String getErrorMessage()
Returns the error message for the parse