You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/12/23 01:12:33 UTC
svn commit: r728827 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/impl/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/main...
Author: veithen
Date: Mon Dec 22 16:12:33 2008
New Revision: 728827
URL: http://svn.apache.org/viewvc?rev=728827&view=rev
Log:
DOOM: Implemented the serialization methods in DocumentImpl.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java?rev=728827&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java Mon Dec 22 16:12:33 2008
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDocument;
+
+/**
+ * Utility class with default implementations for some of the methods defined by the
+ * {@link OMDocument} interface.
+ */
+public class OMDocumentImplUtil {
+ private OMDocumentImplUtil() {}
+
+ public static void internalSerialize(OMDocument document, XMLStreamWriter writer2,
+ boolean cache, boolean includeXMLDeclaration) throws XMLStreamException {
+
+ MTOMXMLStreamWriter writer = (MTOMXMLStreamWriter) writer2;
+ if (includeXMLDeclaration) {
+ //Check whether the OMOutput char encoding and OMDocument char
+ //encoding matches, if not use char encoding of OMOutput
+ String outputCharEncoding = writer.getCharSetEncoding();
+ if (outputCharEncoding == null || "".equals(outputCharEncoding)) {
+ writer.getXmlStreamWriter().writeStartDocument(document.getCharsetEncoding(),
+ document.getXMLVersion());
+ } else {
+ writer.getXmlStreamWriter().writeStartDocument(outputCharEncoding,
+ document.getXMLVersion());
+ }
+ }
+
+ Iterator children = document.getChildren();
+
+ if (cache) {
+ while (children.hasNext()) {
+ OMNodeEx omNode = (OMNodeEx) children.next();
+ omNode.internalSerialize(writer);
+ }
+ } else {
+ while (children.hasNext()) {
+ OMNodeEx omNode = (OMNodeEx) children.next();
+ omNode.internalSerializeAndConsume(writer);
+ }
+ }
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=728827&r1=728826&r2=728827&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Mon Dec 22 16:12:33 2008
@@ -28,6 +28,8 @@
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.OMDocumentImplUtil;
import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
@@ -101,7 +103,7 @@
}
public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
- // TODO Auto-generated method stub
+ internalSerialize(writer, true, !((MTOMXMLStreamWriter) writer).isIgnoreXMLDeclaration());
}
// /
@@ -379,21 +381,9 @@
}
- public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException("TODO");
- }
-
public void internalSerializeAndConsume(XMLStreamWriter writer)
throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException("TODO");
- }
-
- public void serializeAndConsume(XMLStreamWriter xmlWriter)
- throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException("TODO");
+ internalSerialize(writer, false, !((MTOMXMLStreamWriter) writer).isIgnoreXMLDeclaration());
}
// /
@@ -425,14 +415,15 @@
public void serializeAndConsume(OutputStream output, OMOutputFormat format)
throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException("TODO");
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
+ internalSerializeAndConsume(writer);
+ writer.flush();
}
- public void serialize(OutputStream output, OMOutputFormat format)
- throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException("TODO");
+ public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
+ internalSerialize(writer);
+ writer.flush();
}
public void setXMLVersion(String version) {
@@ -581,4 +572,8 @@
setXMLVersion(version);
}
+ protected void internalSerialize(XMLStreamWriter writer, boolean cache,
+ boolean includeXMLDeclaration) throws XMLStreamException {
+ OMDocumentImplUtil.internalSerialize(this, writer, cache, includeXMLDeclaration);
+ }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java?rev=728827&r1=728826&r2=728827&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java Mon Dec 22 16:12:33 2008
@@ -36,10 +36,6 @@
super(new OMDOMImplementation());
}
- public void testSerializeAndConsume() throws XMLStreamException {
- // TODO: temporarily skip this; doesn't work yet
- }
-
public void testCreateElement() throws Exception {
DOMTestUtil.execute(new DOMTestUtil.Test() {
public void execute(DocumentBuilderFactory dbf) throws Exception {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=728827&r1=728826&r2=728827&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java Mon Dec 22 16:12:33 2008
@@ -28,6 +28,7 @@
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMDocumentImplUtil;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
@@ -402,35 +403,9 @@
}
- protected void internalSerialize(XMLStreamWriter writer2, boolean cache,
+ protected void internalSerialize(XMLStreamWriter writer, boolean cache,
boolean includeXMLDeclaration) throws XMLStreamException {
- MTOMXMLStreamWriter writer = (MTOMXMLStreamWriter) writer2;
- if (includeXMLDeclaration) {
- //Check whether the OMOutput char encoding and OMDocument char
- //encoding matches, if not use char encoding of OMOutput
- String outputCharEncoding = writer.getCharSetEncoding();
- if (outputCharEncoding == null || "".equals(outputCharEncoding)) {
- writer.getXmlStreamWriter().writeStartDocument(charSetEncoding,
- xmlVersion);
- } else {
- writer.getXmlStreamWriter().writeStartDocument(outputCharEncoding,
- xmlVersion);
- }
- }
-
- Iterator children = this.getChildren();
-
- if (cache) {
- while (children.hasNext()) {
- OMNodeEx omNode = (OMNodeEx) children.next();
- omNode.internalSerialize(writer);
- }
- } else {
- while (children.hasNext()) {
- OMNodeEx omNode = (OMNodeEx) children.next();
- omNode.internalSerializeAndConsume(writer);
- }
- }
+ OMDocumentImplUtil.internalSerialize(this, writer, cache, includeXMLDeclaration);
}
public OMFactory getOMFactory() {