org.opennms.bb.dp.events
Class XMLEventsConfParser

java.lang.Object
  |
  +--org.opennms.bb.dp.events.XMLEventsConfParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ErrorHandler

public class XMLEventsConfParser
extends Object
implements org.xml.sax.ContentHandler, org.xml.sax.ErrorHandler

The XMLEventsConfParser is a SAX based parser used to decompose an event configuration stream into the corresponding event base classes. The class provides realitivly strong structure checking, but does not require and/or parse an DTD that may proceed the data. This allows the parser to be used with a SAX based SOAP parser, since SOAP prohibits the used of DTDs.

Version:
$Revision: 1.3 $
Author:
Sowmya Kumaraswamy, Brian Weaver, OpenNMS.org

Field Summary
private  org.xml.sax.Attributes m_attributes
          The last attributes elements passed to the startElement() method.
private  StringBuffer m_data
          The buffer where subsequent textual information from the character() method are appendedd.
private  int m_depth
          The current depth of the elements in the document and the TOS for the m_save member.
private  EventBase m_event
          The event being currently processes
private  List m_events
          The list of events from the stream, this is a list of EventBase objects!
private  List m_overrides
          The header recovered from the event stream
private  int[] m_save
          The save buffer stack.
private  EventSnmpInfo m_snmpInfo
          An snmp information block.
private static int SAVE_AUTOACTION
           
private static int SAVE_DESCR
           
private static int SAVE_DONOTOVERRIDE
           
private static int SAVE_EVENT
           
private static int SAVE_EVENTS
           
private static int SAVE_FORWARD
           
private static int SAVE_GLOBAL
           
private static int SAVE_IGNORE
           
private static int SAVE_LOGGROUP
           
private static int SAVE_LOGMSG
           
private static int SAVE_MOUSEOVERTEXT
           
private static int SAVE_NOTIFICATION
           
private static int SAVE_OPERACTION
           
private static int SAVE_OPERINSTRUCT
           
private static int SAVE_SECURITY
           
private static int SAVE_SEVERITY
           
private static int SAVE_SNMP
           
private static int SAVE_SNMP_EID
           
private static int SAVE_SNMP_EIDTEXT
           
private static int SAVE_SNMP_GENERIC
           
private static int SAVE_SNMP_SPECIFIC
           
private static int SAVE_TTICKET
           
private static int SAVE_UEI
           
(package private) static String TAG_AUTOACTION
           
(package private) static String TAG_DESCR
           
(package private) static String TAG_DONOTOVERRIDE
           
(package private) static String TAG_EID
           
(package private) static String TAG_EIDTEXT
           
(package private) static String TAG_EVENT
           
(package private) static String TAG_EVENTS
           
(package private) static String TAG_FORWARD
           
(package private) static String TAG_GENERIC
           
(package private) static String TAG_GLOBAL
           
(package private) static String TAG_LOGGROUP
           
(package private) static String TAG_LOGMSG
           
(package private) static String TAG_LOGMSGDEST
           
(package private) static String TAG_LOGMSGDEST_ATTR_LOGNDISPLAY
           
(package private) static String TAG_LOGMSGDEST_ATTR_LOGONLY
           
(package private) static String TAG_LOGMSGDEST_ATTR_SUPPRESS
           
(package private) static String TAG_MECHANISM
           
(package private) static String TAG_MECHANISM_ATTR_SNMPTCP
           
(package private) static String TAG_MECHANISM_ATTR_SNMPUDP
           
(package private) static String TAG_MECHANISM_ATTR_XMLTCP
           
(package private) static String TAG_MECHANISM_ATTR_XMLUDP
           
(package private) static String TAG_MOUSEOVERTEXT
           
(package private) static String TAG_NOTIFICATION
           
(package private) static String TAG_OPERACTION
           
(package private) static String TAG_OPERACTIONMENU
           
(package private) static String TAG_OPERINSTR
           
(package private) static String TAG_SECURITY
           
(package private) static String TAG_SEVERITY
           
(package private) static String TAG_SNMP
           
(package private) static String TAG_SPECIFIC
           
(package private) static String TAG_STATE
           
(package private) static String TAG_STATE_ATTR_OFF
           
(package private) static String TAG_STATE_ATTR_ON
           
(package private) static String TAG_TTICKET
           
(package private) static String TAG_UEI
           
 
Constructor Summary
XMLEventsConfParser()
          Constructs a new default instance of the parser that can be registered with a SAXParser.
 
Method Summary
 void characters(char[] data, int offset, int length)
          Store the characters of the current element in the current element value buffer
private  int depthOf(int token)
          Returns the depth of a particular SAVE_??? tag.
 void endDocument()
          Called when the end of the document is reached.
 void endElement(String uri, String localName, String qName)
          At the end of the element store the current element buffer value to the appropriate buffer.
 void endPrefixMapping(String prefix)
          Ends a prefix to URI mapping.
 void error(org.xml.sax.SAXParseException ex)
          Throw an exception if there is an error during parse
 void fatalError(org.xml.sax.SAXParseException ex)
          Throw an exception if there is a fatal error during parse
 List getEvents()
          Return the events from the parsed stream.
 List getOverrides()
          Returns the list of events that must be overridden by the event daemon.
 void ignorableWhitespace(char[] data, int offset, int length)
          Ignore the whitespaces
static void main(String[] args)
          used for debugging
 void processingInstruction(String target, String data)
          Receives processing instructions
static void serializeToXML(OutputStream out, List events)
          Generates a document confomant to this parser from the passed events.
static void serializeToXML(OutputStream out, List overrides, List events)
          Generates a document confomant to this parser from the passed events.
static void serializeToXML(PrintStream out, List events)
          Generates a document confomant to this parser from the passed events.
static void serializeToXML(PrintStream out, List overrides, List events)
          Generates a document confomant to this parser from the passed events.
 void setDocumentLocator(org.xml.sax.Locator loc)
          Sets the document locator.
 void skippedEntity(String name)
          Recieves notification of a skipped entity.
 void startDocument()
          Called when the document parsing is beginning.
 void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attrs)
          Called when a new element is encountered in the document.
 void startPrefixMapping(String prefix, String uri)
          Starts a prefix to URI mapping.
protected  boolean validate(EventBase e)
          Used to validate the event before it is placed onto the actual list of events.
 void warning(org.xml.sax.SAXParseException ex)
          Throw an exception if there is a warning during parse
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

TAG_EVENTS

static final String TAG_EVENTS

TAG_GLOBAL

static final String TAG_GLOBAL

TAG_SECURITY

static final String TAG_SECURITY

TAG_DONOTOVERRIDE

static final String TAG_DONOTOVERRIDE

TAG_EVENT

static final String TAG_EVENT

TAG_UEI

static final String TAG_UEI

TAG_SNMP

static final String TAG_SNMP

TAG_EID

static final String TAG_EID

TAG_EIDTEXT

static final String TAG_EIDTEXT

TAG_SPECIFIC

static final String TAG_SPECIFIC

TAG_GENERIC

static final String TAG_GENERIC

TAG_DESCR

static final String TAG_DESCR

TAG_LOGMSG

static final String TAG_LOGMSG

TAG_LOGMSGDEST

static final String TAG_LOGMSGDEST

TAG_LOGMSGDEST_ATTR_SUPPRESS

static final String TAG_LOGMSGDEST_ATTR_SUPPRESS

TAG_LOGMSGDEST_ATTR_LOGONLY

static final String TAG_LOGMSGDEST_ATTR_LOGONLY

TAG_LOGMSGDEST_ATTR_LOGNDISPLAY

static final String TAG_LOGMSGDEST_ATTR_LOGNDISPLAY

TAG_SEVERITY

static final String TAG_SEVERITY

TAG_OPERINSTR

static final String TAG_OPERINSTR

TAG_AUTOACTION

static final String TAG_AUTOACTION

TAG_OPERACTION

static final String TAG_OPERACTION

TAG_OPERACTIONMENU

static final String TAG_OPERACTIONMENU

TAG_LOGGROUP

static final String TAG_LOGGROUP

TAG_NOTIFICATION

static final String TAG_NOTIFICATION

TAG_TTICKET

static final String TAG_TTICKET

TAG_STATE

static final String TAG_STATE

TAG_STATE_ATTR_ON

static final String TAG_STATE_ATTR_ON

TAG_STATE_ATTR_OFF

static final String TAG_STATE_ATTR_OFF

TAG_FORWARD

static final String TAG_FORWARD

TAG_MECHANISM

static final String TAG_MECHANISM

TAG_MECHANISM_ATTR_SNMPUDP

static final String TAG_MECHANISM_ATTR_SNMPUDP

TAG_MECHANISM_ATTR_SNMPTCP

static final String TAG_MECHANISM_ATTR_SNMPTCP

TAG_MECHANISM_ATTR_XMLUDP

static final String TAG_MECHANISM_ATTR_XMLUDP

TAG_MECHANISM_ATTR_XMLTCP

static final String TAG_MECHANISM_ATTR_XMLTCP

TAG_MOUSEOVERTEXT

static final String TAG_MOUSEOVERTEXT

SAVE_IGNORE

private static final int SAVE_IGNORE

SAVE_EVENTS

private static final int SAVE_EVENTS

SAVE_GLOBAL

private static final int SAVE_GLOBAL

SAVE_SECURITY

private static final int SAVE_SECURITY

SAVE_DONOTOVERRIDE

private static final int SAVE_DONOTOVERRIDE

SAVE_EVENT

private static final int SAVE_EVENT

SAVE_UEI

private static final int SAVE_UEI

SAVE_SNMP

private static final int SAVE_SNMP

SAVE_SNMP_EID

private static final int SAVE_SNMP_EID

SAVE_SNMP_EIDTEXT

private static final int SAVE_SNMP_EIDTEXT

SAVE_SNMP_SPECIFIC

private static final int SAVE_SNMP_SPECIFIC

SAVE_SNMP_GENERIC

private static final int SAVE_SNMP_GENERIC

SAVE_DESCR

private static final int SAVE_DESCR

SAVE_LOGMSG

private static final int SAVE_LOGMSG

SAVE_SEVERITY

private static final int SAVE_SEVERITY

SAVE_OPERINSTRUCT

private static final int SAVE_OPERINSTRUCT

SAVE_AUTOACTION

private static final int SAVE_AUTOACTION

SAVE_OPERACTION

private static final int SAVE_OPERACTION

SAVE_LOGGROUP

private static final int SAVE_LOGGROUP

SAVE_NOTIFICATION

private static final int SAVE_NOTIFICATION

SAVE_TTICKET

private static final int SAVE_TTICKET

SAVE_FORWARD

private static final int SAVE_FORWARD

SAVE_MOUSEOVERTEXT

private static final int SAVE_MOUSEOVERTEXT

m_data

private StringBuffer m_data
The buffer where subsequent textual information from the character() method are appendedd. This is normally cleared after each call to endElement. If an element will contain both textual information and sub-elements then this should be modified to behave like a stack.

m_save

private int[] m_save
The save buffer stack. The m_depth member is used to as the TOS pointer for accesing the save states.

m_depth

private int m_depth
The current depth of the elements in the document and the TOS for the m_save member.

m_overrides

private List m_overrides
The header recovered from the event stream

m_events

private List m_events
The list of events from the stream, this is a list of EventBase objects!

m_event

private EventBase m_event
The event being currently processes

m_snmpInfo

private EventSnmpInfo m_snmpInfo
An snmp information block. This is valid between <snmp>...</snmp>

m_attributes

private org.xml.sax.Attributes m_attributes
The last attributes elements passed to the startElement() method. If Attributes are need for post processing, but the element to be post processed has subelements, then a stack based approach MUST be used!
Constructor Detail

XMLEventsConfParser

public XMLEventsConfParser()
Constructs a new default instance of the parser that can be registered with a SAXParser.
Method Detail

depthOf

private int depthOf(int token)
Returns the depth of a particular SAVE_??? tag.
Parameters:
token - The tag to return depth information from.
Returns:
The depth of the tag.

validate

protected boolean validate(EventBase e)

Used to validate the event before it is placed onto the actual list of events. If the method returns true then the event is added to the list. If the method returns false then it is not added to the list.

Additionally, the method is able to modify the values contained in the event if necessary, prior to the event being added to the list of events. Care should be used by all derived classes that implement this behavior.

Parameters:
e - The event to validate
Returns:
True if the event is valid, false if it should be discarded by the parser.

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator loc)
Sets the document locator.
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Parameters:
loc - The document locator.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Called when the document parsing is beginning.
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - Thrown if an error occurs processing the start of the document.

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Called when the end of the document is reached.
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - Thrown if an error occurs validating the document semantics.

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Called when a new element is encountered in the document.
Specified by:
startElement in interface org.xml.sax.ContentHandler
Parameters:
uri - The namespace of the element.
localName - The unqualified name of the element.
qName - The qualified name of the element.
attrs - The attributes for the element.
Throws:
org.xml.sax.SAXException - Thrown if an error occurs processing the element.

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws org.xml.sax.SAXException
At the end of the element store the current element buffer value to the appropriate buffer. Reset all the buffers at the end of each event
Specified by:
endElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - Thrown if there is an error during parse

characters

public void characters(char[] data,
                       int offset,
                       int length)
                throws org.xml.sax.SAXException
Store the characters of the current element in the current element value buffer
Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - if there is an error during parse

ignorableWhitespace

public void ignorableWhitespace(char[] data,
                                int offset,
                                int length)
                         throws org.xml.sax.SAXException
Ignore the whitespaces
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException - if there is an error during parse

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws org.xml.sax.SAXException
Receives processing instructions
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Parameters:
target - The target of the processing instruction.
data - The processing data.
Throws:
org.xml.sax.SAXException - Thrown if an an error occurs during processing

skippedEntity

public void skippedEntity(String name)
                   throws org.xml.sax.SAXException
Recieves notification of a skipped entity.
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Parameters:
name - The name of the skipped entity.
Throws:
org.xml.sax.SAXException - Thrown if an an error occurs during processing

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws org.xml.sax.SAXException
Starts a prefix to URI mapping.
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - The prefix.
uri - The namespace mapping.
Throws:
org.xml.sax.SAXException - Thrown if an an error occurs during processing

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws org.xml.sax.SAXException
Ends a prefix to URI mapping.
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - The prefix that is ending
Throws:
org.xml.sax.SAXException - Thrown if an an error occurs during processing

warning

public void warning(org.xml.sax.SAXParseException ex)
             throws org.xml.sax.SAXException
Throw an exception if there is a warning during parse
Specified by:
warning in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException - if there is an error during parse

error

public void error(org.xml.sax.SAXParseException ex)
           throws org.xml.sax.SAXException
Throw an exception if there is an error during parse
Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException - if there is an error during parse

fatalError

public void fatalError(org.xml.sax.SAXParseException ex)
                throws org.xml.sax.SAXException
Throw an exception if there is a fatal error during parse
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException - if there is an error during parse

getOverrides

public List getOverrides()
Returns the list of events that must be overridden by the event daemon. These fields are considered non modifiable by the local administrator.
Returns:
The list of non-modifiable tags. If there are no tags then a null is returned, or an empty list.

getEvents

public List getEvents()
Return the events from the parsed stream. The events are instances of the EventBase object.
Returns:
the events in the stream

serializeToXML

public static void serializeToXML(OutputStream out,
                                  List overrides,
                                  List events)
Generates a document confomant to this parser from the passed events.
Parameters:
out - The output stream
overrides - The list of overrides
events - The list of events to be written.

serializeToXML

public static void serializeToXML(PrintStream out,
                                  List overrides,
                                  List events)
Generates a document confomant to this parser from the passed events.
Parameters:
out - The output stream
overrides - The list of overrides.
events - The list of events to be written.

serializeToXML

public static void serializeToXML(OutputStream out,
                                  List events)
Generates a document confomant to this parser from the passed events.
Parameters:
out - The output stream
events - The list of events to be written.

serializeToXML

public static void serializeToXML(PrintStream out,
                                  List events)
Generates a document confomant to this parser from the passed events.
Parameters:
out - The output stream
events - The list of events to be written.

main

public static void main(String[] args)
used for debugging