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/01/30 00:44:49 UTC
svn commit: r1727665 - in /webservices/axiom/trunk:
aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
Author: veithen
Date: Fri Jan 29 23:44:48 2016
New Revision: 1727665
URL: http://svn.apache.org/viewvc?rev=1727665&view=rev
Log:
Reimplement the optimization described in AXIOM-282 without keeping additional state in SOAPBodyImpl and without the need to override the addChild method.
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
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=1727665&r1=1727664&r2=1727665&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 Fri Jan 29 23:44:48 2016
@@ -354,13 +354,7 @@ public class StAXOMBuilder implements Bu
}
}
- /**
- * Method getNamespace.
- *
- * @return Returns String.
- * @throws OMException
- */
- public final String getNamespace() throws OMException {
+ public final String getNamespaceURI() {
return parser.getNamespaceURI();
}
@@ -384,23 +378,11 @@ public class StAXOMBuilder implements Bu
return cache;
}
- /**
- * Method getName.
- *
- * @return Returns String.
- * @throws OMException
- */
- public final String getName() throws OMException {
+ public final String getLocalName() {
return parser.getLocalName();
}
- /**
- * Method getPrefix.
- *
- * @return Returns String.
- * @throws OMException
- */
- public final String getPrefix() throws OMException {
+ public final String getPrefix() {
return parser.getPrefix();
}
@@ -1054,46 +1036,22 @@ public class StAXOMBuilder implements Bu
}
/**
- * This method looks ahead to the next start element.
- * @return true if successful
+ * Look ahead to the next event. This method advanced the parser to the next event, but defers
+ * creation of the corresponding node to the next call of {@link #next()}.
+ *
+ * @return The type of the next event. If the return value is
+ * {@link XMLStreamConstants#START_ELEMENT START_ELEMENT}, then the information related
+ * to that element can be obtained by calls to {@link #getLocalName()},
+ * {@link #getNamespaceURI()} and {@link #getPrefix()}.
*/
- public final boolean lookahead() {
- while (true) {
- if (lookAheadToken < 0) {
- lookAheadToken = parserNext();
- }
- if (lookAheadToken == XMLStreamConstants.START_ELEMENT) {
- log.debug("Performing look-ahead; START_ELEMENT found");
- return true;
- } else if (lookAheadToken == XMLStreamConstants.END_ELEMENT ||
- lookAheadToken == XMLStreamConstants.START_DOCUMENT ||
- lookAheadToken == XMLStreamConstants.END_DOCUMENT) {
- if (log.isDebugEnabled()) {
- log.debug("Performing look-ahead; " + XMLEventUtils.getEventTypeString(lookAheadToken) + " found");
- }
- next();
- return false; // leaving scope...start element not found
- } else {
- next(); // continue looking past whitespace etc.
- }
+ public final int lookahead() {
+ if (lookAheadToken < 0) {
+ lookAheadToken = parserNext();
}
+ return lookAheadToken;
}
-
- /**
- * Check if the node for the current token has already been created or if the parser is ahead
- * of the builder.
- *
- * @return A return value of <code>true</code> indicates that the parser is one token ahead
- * of the builder, i.e. that the node for the current token has not been created yet.
- * This state can only be reached by a call to {@link #lookahead()}, and the
- * current token is always a {@link XMLStreamConstants#START_ELEMENT START_ELEMENT}.
- * The information related to that element can be obtained by calls to
- * {@link #getName()}, {@link #getNamespace()} and {@link #getPrefix()}.
- * <p>
- * A return value of <code>false</code> indicates that the node corresponding to the
- * current token hold by the parser has already been created.
- */
- public final boolean isLookahead() {
- return lookAheadToken >= 0;
+
+ public final AxiomContainer getTarget() {
+ return target;
}
}
Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java?rev=1727665&r1=1727664&r2=1727665&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java Fri Jan 29 23:44:48 2016
@@ -19,28 +19,23 @@
package org.apache.axiom.soap.impl.llom;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.core.CoreChildNode;
import org.apache.axiom.om.OMConstants;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.om.impl.common.builder.StAXOMBuilder;
import org.apache.axiom.soap.SOAPConstants;
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPProcessingException;
-import org.apache.axiom.soap.impl.common.builder.StAXSOAPModelBuilder;
import org.apache.axiom.soap.impl.intf.AxiomSOAPBody;
/** Class SOAPBodyImpl */
public abstract class SOAPBodyImpl extends SOAPElement
implements AxiomSOAPBody, OMConstants {
- private boolean enableLookAhead = true;
- private boolean lookAheadAttempted = false;
- private boolean lookAheadSuccessful = false;
- private String lookAheadLocalName = null;
- private OMNamespace lookAheadNS = null;
-
/**
* Indicates whether a <code>SOAPFault</code> object exists in this <code>SOAPBody</code>
* object.
@@ -51,10 +46,9 @@ public abstract class SOAPBodyImpl exten
public boolean hasFault() {
// Set hasSOAPFault if it matches the name matches a SOAP Fault
if (hasLookahead()) {
- return SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(lookAheadLocalName)
- && lookAheadNS != null
- && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()) ||
- SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()));
+ StAXOMBuilder builder = (StAXOMBuilder)getBuilder();
+ return SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(builder.getLocalName())
+ && getSOAPHelper().getEnvelopeURI().equals(builder.getNamespaceURI());
} else {
return getFirstElement() instanceof SOAPFault;
}
@@ -97,36 +91,35 @@ public abstract class SOAPBodyImpl exten
}
private boolean hasLookahead() {
- if (!enableLookAhead) {
- return false;
- }
- if (lookAheadAttempted) {
- return lookAheadSuccessful;
- }
- lookAheadAttempted = true;
- StAXSOAPModelBuilder soapBuilder = (StAXSOAPModelBuilder)getBuilder();
- if (soapBuilder != null &&
- soapBuilder.isCache() &&
- !soapBuilder.isCompleted() &&
- !soapBuilder.isClosed()) {
- lookAheadSuccessful = soapBuilder.lookahead();
- if (lookAheadSuccessful) {
- this.lookAheadLocalName = soapBuilder.getName();
- String ns = soapBuilder.getNamespace();
- if (ns == null) {
- lookAheadNS = null;
- } else {
- String prefix = soapBuilder.getPrefix();
- lookAheadNS = getOMFactory().createOMNamespace(ns, prefix == null ? "" : prefix);
+ StAXOMBuilder builder = (StAXOMBuilder)getBuilder();
+ if (builder != null && !builder.isCompleted() && builder.getTarget() == this) {
+ CoreChildNode child = coreGetFirstChildIfAvailable();
+ while (child != null) {
+ if (child instanceof OMElement) {
+ return false;
}
+ child = child.coreGetNextSiblingIfAvailable();
}
+ do {
+ if (builder.lookahead() == XMLStreamReader.START_ELEMENT) {
+ return true;
+ }
+ builder.next();
+ } while (builder.getTarget() == this);
}
- return lookAheadSuccessful;
+ return false;
}
public OMNamespace getFirstElementNS() {
if (hasLookahead()) {
- return this.lookAheadNS;
+ StAXOMBuilder builder = (StAXOMBuilder)getBuilder();
+ String ns = builder.getNamespaceURI();
+ if (ns == null) {
+ return null;
+ } else {
+ String prefix = builder.getPrefix();
+ return getOMFactory().createOMNamespace(ns, prefix == null ? "" : prefix);
+ }
} else {
OMElement element = this.getFirstElement();
if (element == null) {
@@ -139,7 +132,7 @@ public abstract class SOAPBodyImpl exten
public String getFirstElementLocalName() {
if (hasLookahead()) {
- return this.lookAheadLocalName;
+ return ((StAXOMBuilder)getBuilder()).getLocalName();
} else {
OMElement element = this.getFirstElement();
if (element == null) {
@@ -149,9 +142,4 @@ public abstract class SOAPBodyImpl exten
}
}
}
-
- public void addChild(OMNode child, boolean fromBuilder) {
- this.enableLookAhead = false;
- super.addChild(child, fromBuilder);
- }
}