Author: veithen
Date: Sun May 12 07:19:37 2013
New Revision: 1481479
URL: http://svn.apache.org/r1481479
Log:
AXIOM-288: Allow the builder to continue building the Axiom tree after an
element has been consumed using getXMLStreamReaderWithoutCaching - initial code.
Added:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
(with props)
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
(with props)
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/IncludeWrapper.java
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
Added:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.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/AbstractWrapper.java?rev=1481479&view=auto
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
(added)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
Sun May 12 07:19:37 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.common.serializer.pull;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
+
+//TODO: what about the close() method?
+abstract class AbstractWrapper extends XMLStreamReaderWrapper {
+ private final StreamSwitch streamSwitch;
+ private final XMLStreamReader nextTarget;
+ private int depth;
+
+ AbstractWrapper(StreamSwitch streamSwitch, XMLStreamReader nextTarget,
+ XMLStreamReader parent, int startDepth) {
+ super(parent);
+ this.streamSwitch = streamSwitch;
+ this.nextTarget = nextTarget;
+ depth = startDepth;
+ }
+
+ public int next() throws XMLStreamException {
+ if (depth == 0) {
+ // We get here if the underlying XMLStreamReader is on the last
END_ELEMENT event
+ // TODO: also do this if the reader is prematurely closed
+ release();
+ streamSwitch.setParent(nextTarget);
+ return nextTarget.next();
+ } else {
+ int event = super.next();
+ switch (event) {
+ case START_ELEMENT:
+ depth++;
+ break;
+ case END_ELEMENT:
+ depth--;
+ break;
+ }
+ return event;
+ }
+ }
+
+ public int nextTag() throws XMLStreamException {
+ // TODO: need to handle depth == 0 case here!
+ int result = super.nextTag();
+ switch (result) {
+ case START_ELEMENT:
+ depth++;
+ break;
+ case END_ELEMENT:
+ depth--;
+ }
+ return result;
+ }
+
+ abstract void release() throws XMLStreamException;
+}
Propchange:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/IncludeWrapper.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/IncludeWrapper.java?rev=1481479&r1=1481478&r2=1481479&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/IncludeWrapper.java
(original)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/IncludeWrapper.java
Sun May 12 07:19:37 2013
@@ -21,40 +21,12 @@ package org.apache.axiom.om.impl.common.
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
-
-// TODO: we may have an issue with the depth calculation when nextTag is called
-// TODO: what about the close() method?
-final class IncludeWrapper extends XMLStreamReaderWrapper {
- private final StreamSwitch streamSwitch;
- private final XMLStreamReader nextTarget;
- private int depth = 1;
-
- public IncludeWrapper(StreamSwitch streamSwitch,
- XMLStreamReader nextTarget, XMLStreamReader parent) {
- super(parent);
- this.streamSwitch = streamSwitch;
- this.nextTarget = nextTarget;
+final class IncludeWrapper extends AbstractWrapper {
+ IncludeWrapper(StreamSwitch streamSwitch, XMLStreamReader nextTarget,
XMLStreamReader parent) {
+ super(streamSwitch, nextTarget, parent, 1);
}
- public int next() throws XMLStreamException {
- if (depth == 0) {
- // We get here if the underlying XMLStreamReader is on the last
END_ELEMENT event
- // TODO: also do this if the reader is prematurely closed
- getParent().close();
- streamSwitch.setParent(nextTarget);
- return nextTarget.next();
- } else {
- int event = super.next();
- switch (event) {
- case START_ELEMENT:
- depth++;
- break;
- case END_ELEMENT:
- depth--;
- break;
- }
- return event;
- }
+ void release() throws XMLStreamException {
+ getParent().close();
}
}
Added:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.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/PullThroughWrapper.java?rev=1481479&view=auto
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
(added)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
Sun May 12 07:19:37 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.common.serializer.pull;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+final class PullThroughWrapper extends AbstractWrapper {
+ private final StAXOMBuilder builder;
+ private final OMContainer container;
+
+ PullThroughWrapper(StreamSwitch streamSwitch, XMLStreamReader nextTarget,
+ StAXOMBuilder builder, OMContainer container, XMLStreamReader
reader, int startDepth) {
+ super(streamSwitch, nextTarget, reader, startDepth);
+ this.builder = builder;
+ this.container = container;
+ }
+
+ void release() throws XMLStreamException {
+ builder.reenableCaching(container);
+ }
+}
Propchange:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.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/StreamSwitch.java?rev=1481479&r1=1481478&r2=1481479&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
(original)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
Sun May 12 07:19:37 2013
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.om.impl.common.serializer.pull;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.StreamReaderDelegate;
@@ -43,4 +45,26 @@ final class StreamSwitch extends StreamR
boolean isDataSourceALeaf() {
return isDataSourceALeaf;
}
+
+ public int nextTag() throws XMLStreamException {
+ // The nextTag method is tricky because the delegate may need to switch
+ // to another delegate to locate the next tag. We allow the delegate to
+ // return -1 in this case.
+ int eventType = super.nextTag();
+ if (eventType == -1) {
+ eventType = next();
+ while ((eventType == XMLStreamConstants.CHARACTERS &&
isWhiteSpace()) // skip whitespace
+ || (eventType == XMLStreamConstants.CDATA &&
isWhiteSpace()) // skip whitespace
+ || eventType == XMLStreamConstants.SPACE
+ || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+ || eventType == XMLStreamConstants.COMMENT) {
+ eventType = next();
+ }
+ if (eventType != XMLStreamConstants.START_ELEMENT &&
+ eventType != XMLStreamConstants.END_ELEMENT) {
+ throw new XMLStreamException("expected start or end tag",
getLocation());
+ }
+ }
+ return eventType;
+ }
}
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=1481479&r1=1481478&r2=1481479&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
Sun May 12 07:19:37 2013
@@ -54,6 +54,7 @@ import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.common.IContainer;
import org.apache.axiom.om.impl.common.OMDataSourceUtil;
import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
@@ -935,35 +936,37 @@ class SwitchingWrapper extends AbstractX
currentEvent = END_DOCUMENT;
break;
case NAVIGABLE:
+ OMSerializable nextNode;
if (node == null) {
// We get here if rootNode is an element and the current
event is START_DOCUMENT
- node = rootNode;
+ nextNode = rootNode;
} else if (!isLeaf(node) && !visited) {
OMNode firstChild = _getFirstChild((OMContainer) node);
if (firstChild != null) {
- node = firstChild;
+ nextNode = firstChild;
visited = false;
} else if (node.isComplete()) {
+ nextNode = node;
visited = true;
} else {
- node = null;
+ nextNode = null;
}
} else {
OMNode current = (OMNode)node;
OMContainer parent = current.getParent();
OMNode nextSibling = getNextSibling(current);
if (nextSibling != null) {
- node = nextSibling;
+ nextNode = nextSibling;
visited = false;
} else if (parent.isComplete()) {
- node = parent;
+ nextNode = parent;
visited = true;
} else {
- node = null;
+ nextNode = null;
}
}
- if (node instanceof OMSourcedElement) {
- OMSourcedElement element = (OMSourcedElement)node;
+ if (nextNode instanceof OMSourcedElement) {
+ OMSourcedElement element = (OMSourcedElement)nextNode;
if (!element.isExpanded()) {
OMDataSource ds = element.getDataSource();
if (ds != null &&
!(OMDataSourceUtil.isPushDataSource(ds)
@@ -973,30 +976,41 @@ class SwitchingWrapper extends AbstractX
// Just loop
}
streamSwitch.setParent(new
IncludeWrapper(streamSwitch, this, reader));
+ node = nextNode;
visited = true;
return START_ELEMENT;
}
}
}
- if (node != null) {
+ if (nextNode != null) {
+ node = nextNode;
currentEvent = generateEvents(node);
attributeCount = -1;
namespaceCount = -1;
} else {
- // reset caching (the default is ON so it was not needed
in the
- // earlier case!
+ // Disable caching
builder.setCache(false);
- state = SWITCHED;
-
- // load the parser
- try {
- setParser((XMLStreamReader) builder.getParser());
- } catch (Exception e) {
- throw new XMLStreamException("problem accessing the
parser. " + e.getMessage(),
- e);
+ OMContainer container;
+ if (!(node instanceof OMContainer) || visited) {
+ container = ((OMNode)node).getParent();
+ } else {
+ container = (OMContainer)node;
}
-
- currentEvent = parser.next();
+ int depth = 1;
+ // Find the root node for the builder
+ while (container != rootNode && container instanceof
OMElement) {
+ OMElement element = (OMElement)container;
+ if (element.getBuilder() != builder) {
+ break;
+ }
+ container = element.getParent();
+ depth++;
+ }
+ PullThroughWrapper wrapper = new
PullThroughWrapper(streamSwitch, this, (StAXOMBuilder)builder, container,
((StAXOMBuilder)builder).disableCaching(), depth);
+ streamSwitch.setParent(wrapper);
+ node = container;
+ visited = true;
+ currentEvent = wrapper.next();
}
updateCompleteStatus();
break;
@@ -1010,6 +1024,11 @@ class SwitchingWrapper extends AbstractX
return currentEvent;
}
+ public int nextTag() throws XMLStreamException {
+ // Let StreamSwitch handle this method
+ return -1;
+ }
+
/**
* Method getProperty.
*