Package org.igniterealtime.jbosh
Class BodyParserSAX
- java.lang.Object
-
- org.igniterealtime.jbosh.BodyParserSAX
-
- All Implemented Interfaces:
BodyParser
final class BodyParserSAX extends java.lang.Object implements BodyParser
Implementation of the BodyParser interface which uses the SAX API that is part of the JDK. Due to the fact that we can cache and reuse SAXPArser instances, this has proven to be significantly faster than the use of the javax.xml.stream API introduced in Java 6 while simultaneously providing an implementation accessible to Java 5 users.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBodyParserSAX.HandlerSAX event handler class.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.LoggerLOGLogger.private static java.lang.ThreadLocal<java.lang.ref.SoftReference<javax.xml.parsers.SAXParser>>PARSERThread local to contain a SAX parser instance for each thread that attempts to use one.private static javax.xml.parsers.SAXParserFactorySAX_FACTORYSAX parser factory.
-
Constructor Summary
Constructors Constructor Description BodyParserSAX()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static javax.xml.parsers.SAXParsergetSAXParser()Gets a SAXParser for use in parsing incoming messages.BodyParserResultsparse(java.lang.String xml)Parses the XML message, extracting the useful data from the initial body element and returning it in a results object.
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
Logger.
-
SAX_FACTORY
private static final javax.xml.parsers.SAXParserFactory SAX_FACTORY
SAX parser factory.
-
PARSER
private static final java.lang.ThreadLocal<java.lang.ref.SoftReference<javax.xml.parsers.SAXParser>> PARSER
Thread local to contain a SAX parser instance for each thread that attempts to use one. This allows us to gain an order of magnitude of performance as a result of not constructing parsers for each invocation while retaining thread safety.
-
-
Method Detail
-
parse
public BodyParserResults parse(java.lang.String xml) throws BOSHException
Parses the XML message, extracting the useful data from the initial body element and returning it in a results object.- Specified by:
parsein interfaceBodyParser- Parameters:
xml- XML to parse- Returns:
- useful data parsed out of the XML
- Throws:
BOSHException- on parse error
-
getSAXParser
private static javax.xml.parsers.SAXParser getSAXParser()
Gets a SAXParser for use in parsing incoming messages.- Returns:
- parser instance
-
-