org.osesb.objectpools
Class PooledParserAccessHelper

java.lang.Object
  extended by org.osesb.objectpools.PooledParserAccessHelper

public class PooledParserAccessHelper
extends java.lang.Object

This class encapsulates parsing using the standard SAX and DOM pooled parser configurations in the framework. Pooled SAX parsers are managed by SAXKeyedPoolFactory and pooled DOM parsers are managed by DOMPoolFactory.

The standard SAX and DOM pooled parser configurations in the framework are:

1. The pooled DOM parser configuration, which should be in the /config directory as pooled-dom-parser-config.xml.

2. The key pooled SAX Parser, which should be in the /config directory as keyed-pooled-sax-parser-config.xml.

Since:
Version .9

Field Summary
protected static boolean debugFlag
          debugFlag.
protected static java.lang.String thisClassName
          The full name of this class.
 
Constructor Summary
PooledParserAccessHelper()
           
 
Method Summary
static javax.xml.parsers.DocumentBuilder getDOMParser()
          Borrow a DOM DocumentBuilder from the configured pool with the error handler set to DefaultErrorHandler.
static void main(java.lang.String[] args)
          Main method for testing and sandboxing.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText)
          Parse XML payload using the standard pooled DOM parser.
static void parseSAX(java.lang.String xmlText, org.xml.sax.helpers.DefaultHandler saxHandler)
          Parse XML payload using the standard keyed pooled SAX parser with key = 'namespaceaware-true', which is a non-validating parser.
static void parseSAX(java.lang.String xmlText, org.xml.sax.helpers.DefaultHandler saxHandler, boolean namespaceaware, boolean validating)
          Parse XML payload using the standard keyed pooled SAX parser, specifying the namespaceAware and validating attributes for the parser.
static void parseSAX(java.lang.String xmlText, org.xml.sax.helpers.DefaultHandler saxHandler, boolean namespaceaware, boolean validating, java.io.File[] schemaSource)
          Parse XML payload using the standard keyed pooled SAX parser, specifying the namespaceAware and validating attributes for the parser.
static void returnDOMParser(javax.xml.parsers.DocumentBuilder db)
          Return a DOM DocumentBuilder to the configured pool.
static void setDebugFlag(boolean theDebugFlag)
          Sets the debugFlag for this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisClassName

protected static java.lang.String thisClassName
The full name of this class.


debugFlag

protected static boolean debugFlag
debugFlag. Note: In this Class debugFlag is a Class variable and should only be set for unit testing. Using debugFlag like this avoids dependence on the loggers configuration and isDebugEnabled().

Constructor Detail

PooledParserAccessHelper

public PooledParserAccessHelper()
Method Detail

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText)
                                     throws org.xml.sax.SAXException,
                                            java.lang.Exception
Parse XML payload using the standard pooled DOM parser.

Parameters:
xmlText - The XML document to parse.
Returns:
the DOM Document.
Throws:
org.xml.sax.SAXException - if there is an error parsing the document (i.e the xml is invalid)
java.lang.Exception - if there was an internal error parsing the XML

getDOMParser

public static javax.xml.parsers.DocumentBuilder getDOMParser()
                                                      throws java.lang.Exception
Borrow a DOM DocumentBuilder from the configured pool with the error handler set to DefaultErrorHandler.

Returns:
A pooled DOM DocumentBuilder.
Throws:
java.lang.Exception - if there is an error getting a pooled DOM parser.

returnDOMParser

public static void returnDOMParser(javax.xml.parsers.DocumentBuilder db)
                            throws java.lang.Exception
Return a DOM DocumentBuilder to the configured pool.

Throws:
java.lang.Exception - if there is an error returning the DocumentBuilder to the pool.

parseSAX

public static void parseSAX(java.lang.String xmlText,
                            org.xml.sax.helpers.DefaultHandler saxHandler)
                     throws org.xml.sax.SAXException,
                            java.lang.Exception
Parse XML payload using the standard keyed pooled SAX parser with key = 'namespaceaware-true', which is a non-validating parser.

Parameters:
xmlText - The XML document to parse.
saxHandler - A DefaultHandler object.
Throws:
org.xml.sax.SAXException - if there is an error parsing the document (i.e the xml is invalid)
java.lang.Exception - if there was an internal error parsing the XML

parseSAX

public static void parseSAX(java.lang.String xmlText,
                            org.xml.sax.helpers.DefaultHandler saxHandler,
                            boolean namespaceaware,
                            boolean validating)
                     throws org.xml.sax.SAXException,
                            java.lang.Exception
Parse XML payload using the standard keyed pooled SAX parser, specifying the namespaceAware and validating attributes for the parser.

Parameters:
xmlText - The XML document to parse.
saxHandler - A DefaultHandler object.
namespaceaware - Parser is namespaceaware, true/false
validating - Parser is validating, true/false
Throws:
org.xml.sax.SAXException - if there is an error parsing the document (i.e the xml is invalid)
java.lang.Exception - if there was an internal error parsing the XML

parseSAX

public static void parseSAX(java.lang.String xmlText,
                            org.xml.sax.helpers.DefaultHandler saxHandler,
                            boolean namespaceaware,
                            boolean validating,
                            java.io.File[] schemaSource)
                     throws org.xml.sax.SAXException,
                            java.lang.Exception
Parse XML payload using the standard keyed pooled SAX parser, specifying the namespaceAware and validating attributes for the parser.

Parameters:
xmlText - The XML document to parse.
saxHandler - A DefaultHandler object.
namespaceaware - Parser is namespaceaware, true/false
validating - Parser is validating, true/false
schemaSource - a File[] of schema sources
Throws:
org.xml.sax.SAXException - if there is an error parsing the document (i.e the xml is invalid)
java.lang.Exception - if there was an internal error parsing the XML

setDebugFlag

public static void setDebugFlag(boolean theDebugFlag)
Sets the debugFlag for this object.

Note: In this Class debugFlag is a Class variable and should only be set for unit testing. Using debugFlag like this avoids dependence on the loggers configuration and isDebugEnabled().

Parameters:
theDebugFlag - The debugFlag for this object.

main

public static void main(java.lang.String[] args)
Main method for testing and sandboxing.