You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/02/17 00:30:33 UTC
svn commit: r1730770 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder:
StAXHelper.java StAXOMBuilder.java
Author: veithen
Date: Tue Feb 16 23:30:33 2016
New Revision: 1730770
URL: http://svn.apache.org/viewvc?rev=1730770&view=rev
Log:
Decouple StAXHelper from BuilderHandler.
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXHelper.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXHelper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXHelper.java?rev=1730770&r1=1730769&r2=1730770&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXHelper.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXHelper.java Tue Feb 16 23:30:33 2016
@@ -74,7 +74,6 @@ public class StAXHelper {
public XMLStreamReader parser;
private final XmlHandler handler;
- private final BuilderHandler builderHandler;
private final Closeable closeable;
/**
@@ -99,11 +98,10 @@ public class StAXHelper {
private int lookAheadToken;
- public StAXHelper(XMLStreamReader parser, XmlHandler handler, BuilderHandler builderHandler,
+ public StAXHelper(XMLStreamReader parser, XmlHandler handler,
Closeable closeable, boolean autoClose) {
this.parser = parser;
this.handler = handler;
- this.builderHandler = builderHandler;
this.closeable = closeable;
this.autoClose = autoClose;
dataHandlerReader = XMLStreamReaderUtils.getDataHandlerReader(parser);
@@ -111,7 +109,7 @@ public class StAXHelper {
}
public StAXHelper(XMLStreamReader parser, XmlHandler handler) {
- this(parser, handler, null, null, false);
+ this(parser, handler, null, false);
}
private static String normalize(String s) {
@@ -206,14 +204,6 @@ public class StAXHelper {
* @throws OMException
*/
public int next() throws OMException {
- if (builderHandler != null) {
- if (!builderHandler.cache) {
- throw new IllegalStateException("Can't process next node because caching is disabled");
- }
- if (builderHandler.done) {
- throw new OMException();
- }
- }
int token = parserNext();
// Note: if autoClose is enabled, then the parser may be null at this point
@@ -257,26 +247,6 @@ public class StAXHelper {
throw new OMException(ex);
}
- // TODO: this will fail if there is whitespace before the document element
- if (builderHandler != null && token != XMLStreamConstants.START_DOCUMENT && builderHandler.target == null && !builderHandler.done) {
- // We get here if the document has been discarded (by getDocumentElement(true)
- // or because the builder is linked to an OMSourcedElement) and
- // we just processed the END_ELEMENT event for the root element. In this case, we consume
- // the remaining events until we reach the end of the document. This serves several purposes:
- // * It allows us to detect documents that have an epilog that is not well formed.
- // * Many parsers will perform some cleanup when the end of the document is reached.
- // For example, Woodstox will recycle the symbol table if the parser gets past the
- // last END_ELEMENT. This improves performance because Woodstox by default interns
- // all symbols; if the symbol table can be recycled, then this reduces the number of
- // calls to String#intern().
- // * If autoClose is set, the parser will be closed so that even more resources
- // can be released.
- while (parserNext() != XMLStreamConstants.END_DOCUMENT) {
- // Just loop
- }
- builderHandler.done = true;
- }
-
return token;
}
@@ -385,13 +355,8 @@ public class StAXHelper {
parserException = ex;
throw ex;
}
- if (builderHandler != null && event == XMLStreamConstants.END_DOCUMENT) {
- if (builderHandler.cache && builderHandler.depth != 0) {
- throw new OMException("Unexpected END_DOCUMENT event");
- }
- if (autoClose) {
- close();
- }
+ if (autoClose && event == XMLStreamConstants.END_DOCUMENT) {
+ close();
}
return event;
} catch (XMLStreamException ex) {
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java?rev=1730770&r1=1730769&r2=1730770&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java Tue Feb 16 23:30:33 2016
@@ -64,7 +64,7 @@ public class StAXOMBuilder extends Abstr
if (parser.getEventType() != XMLStreamReader.START_DOCUMENT) {
throw new IllegalStateException("The XMLStreamReader must be positioned on a START_DOCUMENT event");
}
- helper = new StAXHelper(parser, handler, builderHandler, closeable, autoClose);
+ helper = new StAXHelper(parser, handler, closeable, autoClose);
this.detachable = detachable;
charEncoding = parser.getEncoding();
}
@@ -339,9 +339,36 @@ public class StAXOMBuilder extends Abstr
* @throws OMException
*/
public int next() throws OMException {
- int result = helper.next();
+ if (!builderHandler.cache) {
+ throw new IllegalStateException("Can't process next node because caching is disabled");
+ }
+ if (builderHandler.done) {
+ throw new OMException();
+ }
+ int event = helper.next();
builderHandler.executeDeferredListenerActions();
- return result;
+
+ // TODO: this will fail if there is whitespace before the document element
+ if (event != XMLStreamConstants.START_DOCUMENT && builderHandler.target == null && !builderHandler.done) {
+ // We get here if the document has been discarded (by getDocumentElement(true)
+ // or because the builder is linked to an OMSourcedElement) and
+ // we just processed the END_ELEMENT event for the root element. In this case, we consume
+ // the remaining events until we reach the end of the document. This serves several purposes:
+ // * It allows us to detect documents that have an epilog that is not well formed.
+ // * Many parsers will perform some cleanup when the end of the document is reached.
+ // For example, Woodstox will recycle the symbol table if the parser gets past the
+ // last END_ELEMENT. This improves performance because Woodstox by default interns
+ // all symbols; if the symbol table can be recycled, then this reduces the number of
+ // calls to String#intern().
+ // * If autoClose is set, the parser will be closed so that even more resources
+ // can be released.
+ while (helper.parserNext() != XMLStreamConstants.END_DOCUMENT) {
+ // Just loop
+ }
+ builderHandler.done = true;
+ }
+
+ return event;
}
public final OMElement getDocumentElement() {