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 2013/05/18 13:47:51 UTC
svn commit: r1484095 -
/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
Author: veithen
Date: Sat May 18 11:47:51 2013
New Revision: 1484095
URL: http://svn.apache.org/r1484095
Log:
Eliminated the COMPLETED state and instead use node=null && visited=true to handle that case.
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java?rev=1484095&r1=1484094&r2=1484095&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java Sat May 18 11:47:51 2013
@@ -74,7 +74,9 @@ final class SwitchingWrapper extends Pul
private final PullSerializer serializer;
/**
- * The current node, corresponding to the current event.
+ * The current node, corresponding to the current event. It is <code>null</code> if the root
+ * node is an {@link OMElement} and the current event is
+ * {@link XMLStreamConstants#START_DOCUMENT} or {@link XMLStreamConstants#END_DOCUMENT}.
*/
private OMSerializable node;
@@ -108,13 +110,6 @@ final class SwitchingWrapper extends Pul
private static final short NAVIGABLE = 0;
/**
- * Indicates that the last event before the final {@link XMLStreamConstants#END_DOCUMENT} event
- * has been generated. The next event will be {@link XMLStreamConstants#END_DOCUMENT} and state
- * will transition to {@link #DOCUMENT_COMPLETE}.
- */
- private static final short COMPLETED = 2;
-
- /**
* Indicates that the final {@link XMLStreamConstants#END_DOCUMENT} event has been generated.
*/
private static final short DOCUMENT_COMPLETE = 4;
@@ -716,44 +711,49 @@ final class SwitchingWrapper extends Pul
switch (state) {
case DOCUMENT_COMPLETE:
throw new NoSuchElementException("End of the document reached");
- case COMPLETED:
- state = DOCUMENT_COMPLETE;
- currentEvent = END_DOCUMENT;
- break;
case NAVIGABLE:
- OMSerializable nextNode;
+ boolean navigable;
if (node == null) {
// We get here if rootNode is an element and the current event is START_DOCUMENT
- nextNode = rootNode;
+ assert !visited;
+ node = rootNode;
+ navigable = true;
} else if (!isLeaf(node) && !visited) {
OMNode firstChild = _getFirstChild((OMContainer) node);
if (firstChild != null) {
- nextNode = firstChild;
+ node = firstChild;
visited = false;
+ navigable = true;
} else if (node.isComplete()) {
- nextNode = node;
visited = true;
+ navigable = true;
} else {
- nextNode = null;
+ navigable = false;
}
+ } else if (node == rootNode) {
+ // We get here if rootNode is an element and the next event is END_DOCUMENT
+ node = null;
+ visited = true;
+ navigable = true;
} else {
OMNode current = (OMNode)node;
OMNode nextSibling = getNextSibling(current);
if (nextSibling != null) {
- nextNode = nextSibling;
+ node = nextSibling;
visited = false;
+ navigable = true;
} else {
OMContainer parent = current.getParent();
if (parent.isComplete() || parent.getBuilder() == null) { // TODO: review this condition
- nextNode = parent;
+ node = parent;
visited = true;
+ navigable = true;
} else {
- nextNode = null;
+ navigable = false;
}
}
}
- if (nextNode != null) {
- node = nextNode;
+ if (navigable) {
if (node instanceof OMSourcedElement) {
OMSourcedElement element = (OMSourcedElement)node;
if (!element.isExpanded()) {
@@ -770,9 +770,10 @@ final class SwitchingWrapper extends Pul
}
}
}
- if (node instanceof OMDocument) {
+ if (node == null || node instanceof OMDocument) {
assert visited;
currentEvent = END_DOCUMENT;
+ state = DOCUMENT_COMPLETE;
} else if (node instanceof OMElement) {
currentEvent = visited ? END_ELEMENT : START_ELEMENT;
} else {
@@ -805,13 +806,6 @@ final class SwitchingWrapper extends Pul
visited = true;
currentEvent = wrapper.next();
}
- if (rootNode == node && visited) {
- if (currentEvent == END_DOCUMENT) {
- state = DOCUMENT_COMPLETE;
- } else {
- state = COMPLETED;
- }
- }
break;
default:
throw new IllegalStateException("unsuppported state!");