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 2012/09/23 16:01:17 UTC
svn commit: r1389057 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
Author: veithen
Date: Sun Sep 23 14:01:17 2012
New Revision: 1389057
URL: http://svn.apache.org/viewvc?rev=1389057&view=rev
Log:
Prevent SwitchingWrapper from unnecessarily creating the first child of the root node if caching is disabled.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1389057&r1=1389056&r2=1389057&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Sun Sep 23 14:01:17 2012
@@ -110,7 +110,7 @@ class SwitchingWrapper extends AbstractX
private short state;
/** Field currentEvent Default set to START_DOCUMENT */
- private int currentEvent = START_DOCUMENT;
+ private int currentEvent;
/**
* Specifies whether the original document content is cached (i.e. whether the object model is
@@ -194,17 +194,20 @@ class SwitchingWrapper extends AbstractX
} catch(Throwable t) {}
currentNode = navigator.getNext();
- updateNextNode(false);
- if (resetCache) {
- builder.setCache(cache);
- }
-
+ updateNextNode(!cache);
if (startNode instanceof OMDocument) {
+ currentEvent = -1;
try {
next();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
+ } else {
+ currentEvent = START_DOCUMENT;
+ }
+
+ if (resetCache) {
+ builder.setCache(cache);
}
}
@@ -1094,11 +1097,12 @@ class SwitchingWrapper extends AbstractX
* @return Returns NamespaceContext.
*/
public NamespaceContext getNamespaceContext() {
- if (state==SWITCHED){
- return parser.getNamespaceContext();
+ if (parser != null) {
+ return currentEvent == END_DOCUMENT ? new MapBasedNamespaceContext(Collections.EMPTY_MAP) : parser.getNamespaceContext();
+ } else {
+ return new MapBasedNamespaceContext(
+ currentEvent == END_DOCUMENT ? Collections.EMPTY_MAP : getAllNamespaces(lastNode));
}
- return new MapBasedNamespaceContext(
- currentEvent == END_DOCUMENT ? Collections.EMPTY_MAP : getAllNamespaces(lastNode));
}
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java?rev=1389057&r1=1389056&r2=1389057&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java Sun Sep 23 14:01:17 2012
@@ -54,8 +54,8 @@ public class StaxParserTest extends Abst
//try to find the children of the document element. This should produce an
//error since the underlying stream is fully consumed without building the object tree
- Iterator childElements = documentElement.getChildElements();
try {
+ Iterator childElements = documentElement.getChildElements();
while (childElements.hasNext()) {
childElements.next();
}
@@ -122,7 +122,6 @@ public class StaxParserTest extends Abst
//try to find the children of the document element. This should produce an
//error since the underlying stream is fully consumed without building the object tree
- Iterator childElements = documentElement.getChildElements();
try {
XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(System.out);
documentElement.serializeAndConsume(writer);