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/02/29 20:40:06 UTC
svn commit: r1295236 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom:
om/impl/dom/ChildNode.java om/impl/dom/NodeImpl.java
soap/impl/dom/SOAPEnvelopeImpl.java
Author: veithen
Date: Wed Feb 29 19:40:05 2012
New Revision: 1295236
URL: http://svn.apache.org/viewvc?rev=1295236&view=rev
Log:
More code simplifications made possible by the change in AXIOM-385.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1295236&r1=1295235&r2=1295236&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java Wed Feb 29 19:40:05 2012
@@ -19,11 +19,21 @@
package org.apache.axiom.om.impl.dom;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.util.StAXUtils;
import org.w3c.dom.Node;
public abstract class ChildNode extends NodeImpl {
@@ -223,7 +233,7 @@ public abstract class ChildNode extends
}
public void setComplete(boolean state) {
- super.setComplete(state);
+ done = state;
if (parentNode != null) {
if (!done) {
parentNode.setComplete(false);
@@ -232,4 +242,159 @@ public abstract class ChildNode extends
}
}
}
+
+ public boolean isComplete() {
+ return this.done;
+ }
+
+ /** Builds next element. */
+ public void build() {
+ while (!done)
+ this.builder.next();
+ }
+
+ /**
+ * Parses this node and builds the object structure in memory. AXIOM supports two levels of
+ * deffered building. First is deffered building of AXIOM using StAX. Second level is the deffered
+ * building of attachments. AXIOM reads in the attachements from the stream only when user asks by
+ * calling getDataHandler(). build() method builds the OM without the attachments. buildAll()
+ * builds the OM together with attachement data. This becomes handy when user wants to free the
+ * input stream.
+ */
+ public void buildWithAttachments() {
+ if (!this.done) {
+ this.build();
+ }
+ }
+
+ public void close(boolean build) {
+ if (build) {
+ this.build();
+ }
+ this.done = true;
+
+ // If this is a StAXBuilder, close it.
+ if (builder instanceof StAXBuilder &&
+ !((StAXBuilder) builder).isClosed()) {
+ ((StAXBuilder) builder).releaseParserOnClose(true);
+ ((StAXBuilder) builder).close();
+ }
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ serialize(xmlWriter, true);
+ }
+
+ public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ serialize(xmlWriter, false);
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter, boolean cache) throws XMLStreamException {
+ MTOMXMLStreamWriter writer = xmlWriter instanceof MTOMXMLStreamWriter ?
+ (MTOMXMLStreamWriter) xmlWriter :
+ new MTOMXMLStreamWriter(xmlWriter);
+ internalSerialize(writer, cache);
+ writer.flush();
+ }
+
+ public void serialize(OutputStream output) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
+ try {
+ serialize(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serialize(Writer writer) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ try {
+ serialize(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serializeAndConsume(OutputStream output)
+ throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
+ try {
+ serializeAndConsume(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serializeAndConsume(Writer writer) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ try {
+ serializeAndConsume(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, true);
+ try {
+ internalSerialize(writer, true);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serialize(Writer writer2, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
+ .createXMLStreamWriter(writer2));
+ writer.setOutputFormat(format);
+ try {
+ internalSerialize(writer, true);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serializeAndConsume(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, false);
+ try {
+ internalSerialize(writer, false);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serializeAndConsume(Writer writer2, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
+ .createXMLStreamWriter(writer2));
+ try {
+ writer.setOutputFormat(format);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ internalSerialize(writer, false);
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
+ internalSerialize(writer, true);
+ }
+
+ public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException {
+ internalSerialize(writer, false);
+ }
+
+ // This method is actually defined by OMNodeEx, but OMNodeEx is only implemented
+ // by certain subclasses (for the reason, see AXIOM-385).
+ public abstract void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1295236&r1=1295235&r2=1295236&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Wed Feb 29 19:40:05 2012
@@ -19,15 +19,8 @@
package org.apache.axiom.om.impl.dom;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -35,10 +28,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.OutputStream;
-import java.io.Writer;
import java.util.Hashtable;
public abstract class NodeImpl implements Node, NodeList, Cloneable {
@@ -358,126 +347,6 @@ public abstract class NodeImpl implement
flags = (short) (value ? flags | NORMALIZED : flags & ~NORMALIZED);
}
- // /
- // /OM Methods
- // /
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axis2.om.OMNode#getParent()
- */
- public OMContainer getParent() throws OMException {
- return null; // overriden by ChildNode
- // Document, DocumentFragment, and Attribute will never have parents.
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axis2.om.OMNode#isComplete()
- */
- public boolean isComplete() {
- return this.done;
- }
-
- public void setComplete(boolean state) {
- this.done = state;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axis2.om.OMNode#insertSiblingAfter
- * (org.apache.axis2.om.OMNode)
- */
- public void insertSiblingAfter(OMNode sibling) throws OMException {
- // Overridden in ChildNode
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axis2.om.OMNode#insertSiblingBefore
- * (org.apache.axis2.om.OMNode)
- */
- public void insertSiblingBefore(OMNode sibling) throws OMException {
- // Overridden in ChildNode
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
-
- }
-
- /** Default behavior returns null, overriden in ChildNode. */
- public OMNode getPreviousOMSibling() {
- return null;
- }
-
- /** Default behavior returns null, overriden in ChildNode. */
- public OMNode getNextOMSibling() {
- return null;
- }
-
- public OMNode getNextOMSiblingIfAvailable() {
- return null;
- }
-
- public void setPreviousOMSibling(OMNode previousSibling) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
- }
-
- public void setNextOMSibling(OMNode previousSibling) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
- }
-
- /** Builds next element. */
- public void build() {
- while (!done)
- this.builder.next();
- }
-
- /**
- * Parses this node and builds the object structure in memory. AXIOM supports two levels of
- * deffered building. First is deffered building of AXIOM using StAX. Second level is the deffered
- * building of attachments. AXIOM reads in the attachements from the stream only when user asks by
- * calling getDataHandler(). build() method builds the OM without the attachments. buildAll()
- * builds the OM together with attachement data. This becomes handy when user wants to free the
- * input stream.
- */
- public void buildWithAttachments() {
- if (!this.done) {
- this.build();
- }
- }
-
- public void close(boolean build) {
- if (build) {
- this.build();
- }
- this.done = true;
-
- // If this is a StAXBuilder, close it.
- if (builder instanceof StAXBuilder &&
- !((StAXBuilder) builder).isClosed()) {
- ((StAXBuilder) builder).releaseParserOnClose(true);
- ((StAXBuilder) builder).close();
- }
- }
-
/**
* Sets the owner document.
*
@@ -488,22 +357,6 @@ public abstract class NodeImpl implement
this.isOwned(true);
}
- public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
- serialize(xmlWriter, true);
- }
-
- public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
- serialize(xmlWriter, false);
- }
-
- public void serialize(XMLStreamWriter xmlWriter, boolean cache) throws XMLStreamException {
- MTOMXMLStreamWriter writer = xmlWriter instanceof MTOMXMLStreamWriter ?
- (MTOMXMLStreamWriter) xmlWriter :
- new MTOMXMLStreamWriter(xmlWriter);
- internalSerialize(writer, cache);
- writer.flush();
- }
-
/*
* DOM-Level 3 methods
*/
@@ -768,109 +621,8 @@ public abstract class NodeImpl implement
return null;
}
- public void serialize(OutputStream output) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
- try {
- serialize(xmlStreamWriter);
- } finally {
- xmlStreamWriter.close();
- }
- }
-
- public void serialize(Writer writer) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
- try {
- serialize(xmlStreamWriter);
- } finally {
- xmlStreamWriter.close();
- }
- }
-
- public void serializeAndConsume(OutputStream output)
- throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
- try {
- serializeAndConsume(xmlStreamWriter);
- } finally {
- xmlStreamWriter.close();
- }
- }
-
- public void serializeAndConsume(Writer writer) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
- try {
- serializeAndConsume(xmlStreamWriter);
- } finally {
- xmlStreamWriter.close();
- }
- }
-
- public void serialize(OutputStream output, OMOutputFormat format)
- throws XMLStreamException {
- MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, true);
- try {
- internalSerialize(writer, true);
- // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
- writer.flush();
- } finally {
- writer.close();
- }
- }
-
- public void serialize(Writer writer2, OMOutputFormat format)
- throws XMLStreamException {
- MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
- .createXMLStreamWriter(writer2));
- writer.setOutputFormat(format);
- try {
- internalSerialize(writer, true);
- // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
- writer.flush();
- } finally {
- writer.close();
- }
- }
-
- public void serializeAndConsume(OutputStream output, OMOutputFormat format)
- throws XMLStreamException {
- MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, false);
- try {
- internalSerialize(writer, false);
- // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
- writer.flush();
- } finally {
- writer.close();
- }
- }
-
- public void serializeAndConsume(Writer writer2, OMOutputFormat format)
- throws XMLStreamException {
- MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
- .createXMLStreamWriter(writer2));
- try {
- writer.setOutputFormat(format);
- // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
- internalSerialize(writer, false);
- writer.flush();
- } finally {
- writer.close();
- }
- }
-
/** Returns the <code>OMFactory</code> that created this node */
public OMFactory getOMFactory() {
return this.factory;
}
-
- public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
- internalSerialize(writer, true);
- }
-
- public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException {
- internalSerialize(writer, false);
- }
-
- // This method is actually defined by OMNodeEx, but OMNodeEx is only implemented
- // by certain subclasses (for the reason, see AXIOM-385).
- public abstract void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java?rev=1295236&r1=1295235&r2=1295236&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java Wed Feb 29 19:40:05 2012
@@ -26,8 +26,8 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.dom.ChildNode;
import org.apache.axiom.om.impl.dom.DocumentImpl;
-import org.apache.axiom.om.impl.dom.NodeImpl;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP11Version;
@@ -244,11 +244,11 @@ public class SOAPEnvelopeImpl extends SO
OMSerializerUtil.serializeStartpart(this, writer);
OMElement header = getHeader();
if ((header != null) && (header.getFirstOMChild() != null)) {
- serializeInternally((NodeImpl) header, writer);
+ serializeInternally((ChildNode) header, writer);
}
SOAPBody body = getBody();
if (body != null) {
- serializeInternally((NodeImpl) body, writer);
+ serializeInternally((ChildNode) body, writer);
}
OMSerializerUtil.serializeEndpart(writer);
} else {
@@ -257,7 +257,7 @@ public class SOAPEnvelopeImpl extends SO
}
}
- private void serializeInternally(NodeImpl child, MTOMXMLStreamWriter writer)
+ private void serializeInternally(ChildNode child, MTOMXMLStreamWriter writer)
throws XMLStreamException {
if ((!(child instanceof OMElement)) || child.isComplete() || child.builder == null) {
child.internalSerialize(writer, false);