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 2013/01/28 22:13:18 UTC

svn commit: r1439636 [1/2] - in /webservices/axiom/trunk/modules: axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/ axiom-dom/src/main/java/org/apache/axiom/om/i...

Author: veithen
Date: Mon Jan 28 21:13:17 2013
New Revision: 1439636

URL: http://svn.apache.org/viewvc?rev=1439636&view=rev
Log:
Started to refactor the serialization code with the ultimate goal to have a mechanism that covers StAX and SAX as well as cache=true and cache=false in a unified way.

Added:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java   (with props)
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java   (with props)
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/Serializer.java
      - copied, changed from r1439517, webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/StAXSerializer.java
      - copied, changed from r1439499, webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java
Removed:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java
Modified:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ISerializable.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDocumentHelper.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/EntityReferenceImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMEntityReferenceImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSerializableImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPFaultImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ISerializable.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ISerializable.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ISerializable.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ISerializable.java Mon Jan 28 21:13:17 2013
@@ -21,6 +21,8 @@ package org.apache.axiom.om.impl.common;
 import javax.xml.stream.XMLStreamException;
 
 import org.apache.axiom.om.OMSerializable;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 
 public interface ISerializable extends OMSerializable {
     /**
@@ -29,7 +31,7 @@ public interface ISerializable extends O
      * @param serializer
      * @param cache indicates if caching should be enabled
      * @throws XMLStreamException
-     *
+     * @throws OutputException 
      */
-    void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException;
+    void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException, OutputException;
 }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDocumentHelper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDocumentHelper.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDocumentHelper.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDocumentHelper.java Mon Jan 28 21:13:17 2013
@@ -24,6 +24,8 @@ import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
 
 /**
@@ -34,7 +36,7 @@ public class OMDocumentHelper {
     private OMDocumentHelper() {}
     
     public static void internalSerialize(OMDocument document, StAXSerializer serializer,
-            boolean cache, boolean includeXMLDeclaration) throws XMLStreamException {
+            boolean cache, boolean includeXMLDeclaration) throws XMLStreamException, OutputException {
         
         MTOMXMLStreamWriter writer = (MTOMXMLStreamWriter)serializer.getWriter();
         if (includeXMLDeclaration) {

Added: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java?rev=1439636&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java (added)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java Mon Jan 28 21:13:17 2013
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+public class OutputException extends Exception {
+    private static final long serialVersionUID = 7173617216602466028L;
+
+    public OutputException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/OutputException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java?rev=1439636&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java (added)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java Mon Jan 28 21:13:17 2013
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+public class SAXSerializer extends Serializer {
+    private final ContentHandler contentHandler;
+    private final LexicalHandler lexicalHandler;
+    
+    public SAXSerializer(OMSerializable contextNode, ContentHandler contentHandler, LexicalHandler lexicalHandler) {
+        super(contextNode);
+        this.contentHandler = contentHandler;
+        this.lexicalHandler = lexicalHandler;
+    }
+
+    protected boolean isAssociated(String prefix, String namespace) throws OutputException {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    protected void setPrefix(String prefix, String namespaceURI) throws OutputException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    protected void writeStartElement(String prefix, String namespaceURI, String localName)
+            throws OutputException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    protected void writeNamespace(String prefix, String namespaceURI) throws OutputException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    protected void writeAttribute(String prefix, String namespaceURI, String localName, String value)
+            throws OutputException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void writeText(int type, String data) throws OutputException {
+        char[] ch = data.toCharArray();
+        try {
+            switch (type) {
+                case OMNode.TEXT_NODE:
+                    contentHandler.characters(ch, 0, ch.length);
+                    break;
+                case OMNode.CDATA_SECTION_NODE:
+                    if (lexicalHandler != null) {
+                        lexicalHandler.startCDATA();
+                    }
+                    contentHandler.characters(ch, 0, ch.length);
+                    if (lexicalHandler != null) {
+                        lexicalHandler.endCDATA();
+                    }
+                    break;
+                case OMNode.SPACE_NODE:
+                    contentHandler.ignorableWhitespace(ch, 0, ch.length);
+            }
+        } catch (SAXException ex) {
+            throw new OutputException(ex);
+        }
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/SAXSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/Serializer.java (from r1439517, webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/Serializer.java?p2=webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/Serializer.java&p1=webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java&r1=1439517&r2=1439636&rev=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/Serializer.java Mon Jan 28 21:13:17 2013
@@ -16,346 +16,160 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.impl.common;
+package org.apache.axiom.om.impl.common.serializer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMConstants;
-import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
 
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-public class StAXSerializer {
-    private static final Log log = LogFactory.getLog(StAXSerializer.class);
-    
-    private static final QName XSI_TYPE = new QName("http://www.w3.org/2001/XMLSchema-instance", "type");
+public abstract class Serializer {
+    private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
+    private static final String XSI_LOCAL_NAME = "type";
     
-    private final XMLStreamWriter writer;
+    private final OMElement contextElement;
     private final ArrayList writePrefixList = new ArrayList();
     private final ArrayList writeNSList = new ArrayList();
-
     
-    public StAXSerializer(XMLStreamWriter writer) {
-        this.writer = writer;
-    }
-
-    public XMLStreamWriter getWriter() {
-        return writer;
-    }
-
-    /**
-     * Method serializeEndpart.
-     *
-     * @throws javax.xml.stream.XMLStreamException
-     *
-     */
-    public void serializeEndpart() throws XMLStreamException {
-        writer.writeEndElement();
-    }
-
-    /**
-     * Method serializeStartpart. Serialize the start tag of an element.
-     *
-     * @param element
-     * @throws XMLStreamException
-     */
-    public void serializeStartpart(OMElement element) throws XMLStreamException {
-
-        // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
-        // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
-
-        // The algorithm is:
-        // ... generate writeStartElement
-        //
-        // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
-        // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
-        // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
-        //
-        // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
-        // ... generate writeAttribute for each attribute
-
-        // Get the namespace and prefix of the element
-        String ePrefix = element.getPrefix();
-        String eNamespace = element.getNamespaceURI();
-
-        if (eNamespace != null) {
-            if (ePrefix == null) {
-                if (!isAssociated("", eNamespace)) {
-                    writePrefixList.add("");
-                    writeNSList.add(eNamespace);
-                }
-                writer.writeStartElement("", element.getLocalName(), eNamespace);
+    public Serializer(OMSerializable contextNode) {
+        if (contextNode instanceof OMNode) {
+            OMContainer parent = ((OMNode)contextNode).getParent();
+            if (parent instanceof OMElement) {
+                contextElement = (OMElement)parent; 
             } else {
-                /*
-                 * If XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) associates
-                 * the prefix with the namespace .. 
-                 */
-                if (!isAssociated(ePrefix, eNamespace)) {
-                    writePrefixList.add(ePrefix);
-                    writeNSList.add(eNamespace);
-                }
-                
-                writer.writeStartElement(ePrefix, element.getLocalName(), eNamespace);
+                contextElement = null;
             }
         } else {
-            writer.writeStartElement(element.getLocalName());
-        }
-
-        // Generate setPrefix for the namespace declarations
-        Iterator it = element.getAllDeclaredNamespaces();
-        while (it.hasNext()) {
-            OMNamespace omNamespace = (OMNamespace) it.next();
-            String prefix = omNamespace.getPrefix();
-            String namespace = omNamespace.getNamespaceURI();
-            generateSetPrefix(prefix.length() == 0 ? null : prefix,
-                              namespace.length() == 0 ? null : namespace, false);
-        }
-
-        // Generate setPrefix for the element
-        // Get the prefix and namespace of the element.  "" and null are identical.
-        generateSetPrefix(ePrefix, eNamespace, false);
-
-        // Now Generate setPrefix for each attribute
-        Iterator attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            generateSetPrefix(attr.getPrefix(), attr.getNamespaceURI(), true);
-        }
-        
-        // Now Generate setPrefix for each prefix referenced in an xsi:type
-        // For example xsi:type="p:dataType"
-        // The following code will make sure that setPrefix is called for "p".
-        attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            if (attr.hasName(XSI_TYPE)) {
-                String value = attr.getAttributeValue();
-                if (log.isDebugEnabled()) {
-                    log.debug("The value of xsi:type is " + value);
-                }
-                value = value.trim();
-                if (value.indexOf(":") > 0) {
-                    String refPrefix = value.substring(0, value.indexOf(":"));
-                    OMNamespace omNS = element.findNamespaceURI(refPrefix);
-                    String refNamespace = (omNS == null) ? null : omNS.getNamespaceURI();
-                    if (refNamespace != null && refNamespace.length() > 0) {
-                        generateSetPrefix(refPrefix, refNamespace, true);
-                    }
-                }
-            }
+            contextElement = null;
         }
+    }
 
-        // Now write out the list of namespace declarations in this list that we constructed
-        // while doing the "set" processing.
-        for (int i = 0; i < writePrefixList.size(); i++) {
-            String prefix = (String) writePrefixList.get(i);
-            String namespace = (String) writeNSList.get(i);
-            if (prefix != null) {
-                writer.writeNamespace(prefix, namespace == null ? "" : namespace);
-            } else {
-                writer.writeDefaultNamespace(namespace);
-            }
+    public final void serializeStartpart(OMElement element) throws OutputException {
+        OMNamespace ns = element.getNamespace();
+        if (ns == null) {
+            beginStartElement("", "", element.getLocalName());
+        } else {
+            beginStartElement(ns.getPrefix(), ns.getNamespaceURI(), element.getLocalName());
         }
-
-        // Now write the attributes
-        attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            String prefix = attr.getPrefix();
-            String namespace = attr.getNamespaceURI();
-
-            if (namespace != null) {
-                // Use the writer's prefix if it is different, but if the writers
-                // prefix is empty then do not replace because attributes do not
-                // default to the default namespace like elements do.
-                String writerPrefix = writer.getPrefix(namespace);
-                if (!prefix.equals(writerPrefix) && writerPrefix  != null && !"".equals(writerPrefix)) {
-                    prefix = writerPrefix;
-                }
-            }
-            if (namespace != null) {
-                if(prefix == null && OMConstants.XMLNS_URI.equals(namespace)){
-                    prefix = OMConstants.XMLNS_PREFIX;
-                }
-                // Qualified attribute
-                writer.writeAttribute(prefix, namespace,
-                                      attr.getLocalName(),
-                                      attr.getAttributeValue());
+        for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
+            ns = (OMNamespace)it.next();
+            generateSetPrefix(ns.getPrefix(), ns.getNamespaceURI(), false);
+        }
+        for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
+            OMAttribute attr = (OMAttribute)it.next();
+            ns = attr.getNamespace();
+            if (ns == null) {
+                processAttribute("", "", attr.getLocalName(), attr.getAttributeValue());
             } else {
-                // Unqualified attribute
-                writer.writeAttribute(attr.getLocalName(),
-                                      attr.getAttributeValue());
+                processAttribute(ns.getPrefix(), ns.getNamespaceURI(), attr.getLocalName(), attr.getAttributeValue());
             }
         }
-        
-        writePrefixList.clear();
-        writeNSList.clear();
+        finishStartElement();
     }
-
-    public void serializeByPullStream(OMElement element, boolean cache) throws XMLStreamException {
-        XMLStreamReader reader = element.getXMLStreamReader(cache);
-        try {
-            new StreamingOMSerializer().serialize(reader, writer);
-        } finally {
-            reader.close();
+    
+    public final void copyEvent(XMLStreamReader reader) throws XMLStreamException, OutputException {
+        int eventType = reader.getEventType();
+        switch (eventType) {
+            case XMLStreamReader.START_ELEMENT:
+                beginStartElement(normalize(reader.getPrefix()), normalize(reader.getNamespaceURI()), reader.getLocalName());
+                for (int i=0, count=reader.getNamespaceCount(); i<count; i++) {
+                    generateSetPrefix(normalize(reader.getNamespacePrefix(i)), normalize(reader.getNamespacePrefix(i)), false);
+                }
+                for (int i=0, count=reader.getAttributeCount(); i<count; i++) {
+                    processAttribute(
+                            normalize(reader.getAttributePrefix(i)),
+                            normalize(reader.getAttributeNamespace(i)),
+                            reader.getAttributeLocalName(i),
+                            reader.getAttributeValue(i));
+                }
+                finishStartElement();
+                break;
+            case XMLStreamReader.CHARACTERS:
+            case XMLStreamReader.SPACE:
+            case XMLStreamReader.CDATA:
+                writeText(eventType, reader.getText());
+                break;
         }
     }
-
-    public void serializeChildren(OMContainer container, boolean cache) throws XMLStreamException {
-        if (cache) {
-            IChildNode child = (IChildNode)container.getFirstOMChild();
-            while (child != null) {
-                child.internalSerialize(this, true);
-                child = (IChildNode)child.getNextOMSibling();
-            }
-        } else {
-            IChildNode child = (IChildNode)container.getFirstOMChild();
-            while (child != null) {
-                if ((!(child instanceof OMElement)) || child.isComplete() ||
-                        ((OMElement)child).getBuilder() == null) {
-                    child.internalSerialize(this, false);
-                } else {
-                    OMElement element = (OMElement) child;
-                    element.getBuilder().setCache(false);
-                    serializeByPullStream(element, cache);
+    
+    private static String normalize(String s) {
+        return s == null ? "" : s;
+    }
+    
+    private void beginStartElement(String prefix, String namespaceURI, String localName) throws OutputException {
+        writeStartElement(prefix, namespaceURI, localName);
+        generateSetPrefix(prefix, namespaceURI, false);
+    }
+    
+    private void processAttribute(String prefix, String namespaceURI, String localName, String value) throws OutputException {
+        generateSetPrefix(prefix, namespaceURI, true);
+        if (contextElement != null && namespaceURI.equals(XSI_URI) && localName.equals(XSI_LOCAL_NAME)) {
+            String trimmedValue = value.trim();
+            if (trimmedValue.indexOf(":") > 0) {
+                String refPrefix = trimmedValue.substring(0, trimmedValue.indexOf(":"));
+                OMNamespace ns = contextElement.findNamespaceURI(refPrefix);
+                if (ns != null) {
+                    generateSetPrefix(refPrefix, ns.getNamespaceURI(), true);
                 }
-                child = (IChildNode)child.getNextOMSiblingIfAvailable();
             }
         }
+        writeAttribute(prefix, namespaceURI, localName, value);
     }
-
+    
+    private void finishStartElement() throws OutputException {
+        for (int i = 0; i < writePrefixList.size(); i++) {
+            writeNamespace((String)writePrefixList.get(i), (String)writeNSList.get(i));
+        }
+        writePrefixList.clear();
+        writeNSList.clear();
+    }
+    
     /**
      * Generate setPrefix/setDefaultNamespace if the prefix is not associated
      *
-     * @param prefix
-     * @param namespace
+     * @param prefix the namespace prefix; must not be <code>null</code>
+     * @param namespaceURI the namespace URI; must not be <code>null</code>
      * @param attr
      * @return prefix name if a setPrefix/setDefaultNamespace is performed
      */
-    private void generateSetPrefix(String prefix, String namespace, boolean attr) throws XMLStreamException {
-        prefix = (prefix == null) ? "" : prefix;
-        
-        
+    private void generateSetPrefix(String prefix, String namespaceURI, boolean attr) throws OutputException {
         // If the prefix and namespace are already associated, no generation is needed
-        if (isAssociated(prefix, namespace)) {
+        if (isAssociated(prefix, namespaceURI)) {
             return;
         }
         
         // Attributes without a prefix always are associated with the unqualified namespace
         // according to the schema specification.  No generation is needed.
-        if (prefix.length() == 0 && namespace == null && attr) {
+        if (prefix.length() == 0 && namespaceURI.length() == 0 && attr) {
             return;
         }
         
         // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
-        String newPrefix;
-        if (namespace != null) {
-            // Qualified Namespace
-            if (prefix.length() == 0) {
-                writer.setDefaultNamespace(namespace);
-                newPrefix = "";
-            } else {
-                writer.setPrefix(prefix, namespace);
-                newPrefix = prefix;
-            }
-        } else {
-            // Unqualified Namespace
-            // Disable the default namespace
-            writer.setDefaultNamespace("");
-            newPrefix = "";
-        }
+        setPrefix(prefix, namespaceURI);
         // If this is a new association, remember it so that it can written out later
-        if (!writePrefixList.contains(newPrefix)) {
-            writePrefixList.add(newPrefix);
-            writeNSList.add(namespace);
-        }
-    }
-    /**
-     * @param prefix 
-     * @param namespace
-     * @return true if the prefix is associated with the namespace in the current context
-     */
-    private boolean isAssociated(String prefix, String namespace) throws XMLStreamException {
-        
-        // The "xml" prefix is always (implicitly) associated. Returning true here makes sure that
-        // we never write a declaration for the xml namespace. See AXIOM-37 for a discussion
-        // of this issue.
-        if ("xml".equals(prefix)) {
-            return true;
-        }
-        
-        // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
-        // Please use other writer methods first.
-        
-        // For consistency, convert null arguments.
-        // This helps get around the parser implementation differences.
-        // In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
-        prefix = (prefix == null) ? "" : prefix;
-        namespace = (namespace == null) ? "" : namespace;
-        
-        if (namespace.length() > 0) {
-            // QUALIFIED NAMESPACE
-            // Get the namespace associated with the prefix
-            String writerPrefix = writer.getPrefix(namespace);
-            if (prefix.equals(writerPrefix)) {
-                return true;
-            }
-            
-            // It is possible that the namespace is associated with multiple prefixes,
-            // So try getting the namespace as a second step.
-            if (writerPrefix != null) {
-                NamespaceContext nsContext = writer.getNamespaceContext();
-                if(nsContext != null) {
-                    String writerNS = nsContext.getNamespaceURI(prefix);
-                    return namespace.equals(writerNS);
-                }
-            }
-            return false;
-        } else {
-            // UNQUALIFIED NAMESPACE
-            
-            // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
-            if (prefix.length() > 0) {
-                throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");  
-            }
-            
-            // Get the namespace associated with the prefix.
-            // It is illegal to call getPrefix with null, but the specification is not
-            // clear on what happens if called with "".  So the following code is 
-            // protected
-            try {
-                String writerPrefix = writer.getPrefix("");
-                if (writerPrefix != null && writerPrefix.length() == 0) {
-                    return true;
-                }
-            } catch (Throwable t) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
-                }
-            }
-            
-            
-            
-            // Fallback to using the namespace context
-            NamespaceContext nsContext = writer.getNamespaceContext();
-            if (nsContext != null) {
-                String writerNS = nsContext.getNamespaceURI("");
-                if (writerNS != null && writerNS.length() > 0) {
-                    return false;
-                }
-            }
-            return true;
+        if (!writePrefixList.contains(prefix)) {
+            writePrefixList.add(prefix);
+            writeNSList.add(namespaceURI);
         }
     }
+    
+    protected abstract boolean isAssociated(String prefix, String namespace) throws OutputException;
+    
+    protected abstract void setPrefix(String prefix, String namespaceURI) throws OutputException;
+    
+    protected abstract void writeStartElement(String prefix, String namespaceURI, String localName) throws OutputException;
+    
+    protected abstract void writeNamespace(String prefix, String namespaceURI) throws OutputException;
+    
+    protected abstract void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws OutputException;
+    
+    public abstract void writeText(int type, String data) throws OutputException;
 }

Copied: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/StAXSerializer.java (from r1439499, webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/StAXSerializer.java?p2=webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/StAXSerializer.java&p1=webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java&r1=1439499&r2=1439636&rev=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StAXSerializer.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/StAXSerializer.java Mon Jan 28 21:13:17 2013
@@ -16,37 +16,30 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.impl.common;
+package org.apache.axiom.om.impl.common.serializer;
 
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
+import org.apache.axiom.om.impl.common.IChildNode;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
 
-public class StAXSerializer {
+public class StAXSerializer extends Serializer {
     private static final Log log = LogFactory.getLog(StAXSerializer.class);
     
-    private static final QName XSI_TYPE = new QName("http://www.w3.org/2001/XMLSchema-instance", "type");
-    
     private final XMLStreamWriter writer;
-    private final ArrayList writePrefixList = new ArrayList();
-    private final ArrayList writeNSList = new ArrayList();
-
     
-    public StAXSerializer(XMLStreamWriter writer) {
+    public StAXSerializer(OMSerializable contextNode, XMLStreamWriter writer) {
+        super(contextNode);
         this.writer = writer;
     }
 
@@ -64,143 +57,32 @@ public class StAXSerializer {
         writer.writeEndElement();
     }
 
-    /**
-     * Method serializeStartpart. Serialize the start tag of an element.
-     *
-     * @param element
-     * @throws XMLStreamException
-     */
-    public void serializeStartpart(OMElement element) throws XMLStreamException {
-
-        // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
-        // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
-
-        // The algorithm is:
-        // ... generate writeStartElement
-        //
-        // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
-        // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
-        // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
-        //
-        // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
-        // ... generate writeAttribute for each attribute
-
-        // Get the namespace and prefix of the element
-        String ePrefix = element.getPrefix();
-        String eNamespace = element.getNamespaceURI();
-
-        if (eNamespace != null) {
-            if (ePrefix == null) {
-                if (!isAssociated("", eNamespace)) {
-                    writePrefixList.add("");
-                    writeNSList.add(eNamespace);
-                }
-                writer.writeStartElement("", element.getLocalName(), eNamespace);
-            } else {
-                /*
-                 * If XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) associates
-                 * the prefix with the namespace .. 
-                 */
-                if (!isAssociated(ePrefix, eNamespace)) {
-                    writePrefixList.add(ePrefix);
-                    writeNSList.add(eNamespace);
-                }
-                
-                writer.writeStartElement(ePrefix, element.getLocalName(), eNamespace);
-            }
-        } else {
-            writer.writeStartElement(element.getLocalName());
-        }
-
-        // Generate setPrefix for the namespace declarations
-        Iterator it = element.getAllDeclaredNamespaces();
-        while (it.hasNext()) {
-            OMNamespace omNamespace = (OMNamespace) it.next();
-            String prefix = omNamespace.getPrefix();
-            String namespace = omNamespace.getNamespaceURI();
-            generateSetPrefix(prefix.length() == 0 ? null : prefix,
-                              namespace.length() == 0 ? null : namespace, false);
-        }
-
-        // Generate setPrefix for the element
-        // Get the prefix and namespace of the element.  "" and null are identical.
-        generateSetPrefix(ePrefix, eNamespace, false);
-
-        // Now Generate setPrefix for each attribute
-        Iterator attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            generateSetPrefix(attr.getPrefix(), attr.getNamespaceURI(), true);
-        }
-        
-        // Now Generate setPrefix for each prefix referenced in an xsi:type
-        // For example xsi:type="p:dataType"
-        // The following code will make sure that setPrefix is called for "p".
-        attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            if (attr.hasName(XSI_TYPE)) {
-                String value = attr.getAttributeValue();
-                if (log.isDebugEnabled()) {
-                    log.debug("The value of xsi:type is " + value);
-                }
-                value = value.trim();
-                if (value.indexOf(":") > 0) {
-                    String refPrefix = value.substring(0, value.indexOf(":"));
-                    OMNamespace omNS = element.findNamespaceURI(refPrefix);
-                    String refNamespace = (omNS == null) ? null : omNS.getNamespaceURI();
-                    if (refNamespace != null && refNamespace.length() > 0) {
-                        generateSetPrefix(refPrefix, refNamespace, true);
-                    }
-                }
-            }
+    protected void writeStartElement(String prefix, String namespaceURI, String localName) throws OutputException {
+        try {
+            writer.writeStartElement(prefix, localName, namespaceURI);
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
         }
+    }
 
-        // Now write out the list of namespace declarations in this list that we constructed
-        // while doing the "set" processing.
-        for (int i = 0; i < writePrefixList.size(); i++) {
-            String prefix = (String) writePrefixList.get(i);
-            String namespace = (String) writeNSList.get(i);
-            if (prefix != null) {
-                writer.writeNamespace(prefix, namespace == null ? "" : namespace);
+    protected void writeNamespace(String prefix, String namespaceURI) throws OutputException {
+        try {
+            if (prefix.length() != 0) {
+                writer.writeNamespace(prefix, namespaceURI);
             } else {
-                writer.writeDefaultNamespace(namespace);
+                writer.writeDefaultNamespace(namespaceURI);
             }
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
         }
+    }
 
-        // Now write the attributes
-        attrs = element.getAllAttributes();
-        while (attrs.hasNext()) {
-            OMAttribute attr = (OMAttribute) attrs.next();
-            String prefix = attr.getPrefix();
-            String namespace = attr.getNamespaceURI();
-
-            if (namespace != null) {
-                // Use the writer's prefix if it is different, but if the writers
-                // prefix is empty then do not replace because attributes do not
-                // default to the default namespace like elements do.
-                String writerPrefix = writer.getPrefix(namespace);
-                if (!prefix.equals(writerPrefix) && writerPrefix  != null && !"".equals(writerPrefix)) {
-                    prefix = writerPrefix;
-                }
-            }
-            if (namespace != null) {
-                if(prefix == null && OMConstants.XMLNS_URI.equals(namespace)){
-                    prefix = OMConstants.XMLNS_PREFIX;
-                }
-                // Qualified attribute
-                writer.writeAttribute(prefix, namespace,
-                                      attr.getLocalName(),
-                                      attr.getAttributeValue());
-            } else {
-                // Unqualified attribute
-                writer.writeAttribute(attr.getLocalName(),
-                                      attr.getAttributeValue());
-            }
+    protected void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws OutputException {
+        try {
+            writer.writeAttribute(prefix, namespaceURI, localName, value);
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
         }
-        
-        writePrefixList.clear();
-        writeNSList.clear();
     }
 
     public void serializeByPullStream(OMElement element, boolean cache) throws XMLStreamException {
@@ -212,7 +94,7 @@ public class StAXSerializer {
         }
     }
 
-    public void serializeChildren(OMContainer container, boolean cache) throws XMLStreamException {
+    public void serializeChildren(OMContainer container, boolean cache) throws XMLStreamException, OutputException {
         if (cache) {
             IChildNode child = (IChildNode)container.getFirstOMChild();
             while (child != null) {
@@ -235,127 +117,108 @@ public class StAXSerializer {
         }
     }
 
-    /**
-     * Generate setPrefix/setDefaultNamespace if the prefix is not associated
-     *
-     * @param prefix
-     * @param namespace
-     * @param attr
-     * @return prefix name if a setPrefix/setDefaultNamespace is performed
-     */
-    private void generateSetPrefix(String prefix, String namespace, boolean attr) throws XMLStreamException {
-        prefix = (prefix == null) ? "" : prefix;
-        
-        
-        // If the prefix and namespace are already associated, no generation is needed
-        if (isAssociated(prefix, namespace)) {
-            return;
-        }
-        
-        // Attributes without a prefix always are associated with the unqualified namespace
-        // according to the schema specification.  No generation is needed.
-        if (prefix.length() == 0 && namespace == null && attr) {
-            return;
-        }
-        
-        // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
-        String newPrefix;
-        if (namespace != null) {
-            // Qualified Namespace
+    protected void setPrefix(String prefix, String namespaceURI) throws OutputException {
+        try {
             if (prefix.length() == 0) {
-                writer.setDefaultNamespace(namespace);
-                newPrefix = "";
+                writer.setDefaultNamespace(namespaceURI);
             } else {
-                writer.setPrefix(prefix, namespace);
-                newPrefix = prefix;
+                writer.setPrefix(prefix, namespaceURI);
             }
-        } else {
-            // Unqualified Namespace
-            // Disable the default namespace
-            writer.setDefaultNamespace("");
-            newPrefix = "";
-        }
-        // If this is a new association, remember it so that it can written out later
-        if (!writePrefixList.contains(newPrefix)) {
-            writePrefixList.add(newPrefix);
-            writeNSList.add(namespace);
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
         }
     }
+
     /**
      * @param prefix 
      * @param namespace
      * @return true if the prefix is associated with the namespace in the current context
      */
-    private boolean isAssociated(String prefix, String namespace) throws XMLStreamException {
-        
-        // The "xml" prefix is always (implicitly) associated. Returning true here makes sure that
-        // we never write a declaration for the xml namespace. See AXIOM-37 for a discussion
-        // of this issue.
-        if ("xml".equals(prefix)) {
-            return true;
-        }
-        
-        // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
-        // Please use other writer methods first.
-        
-        // For consistency, convert null arguments.
-        // This helps get around the parser implementation differences.
-        // In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
-        prefix = (prefix == null) ? "" : prefix;
-        namespace = (namespace == null) ? "" : namespace;
-        
-        if (namespace.length() > 0) {
-            // QUALIFIED NAMESPACE
-            // Get the namespace associated with the prefix
-            String writerPrefix = writer.getPrefix(namespace);
-            if (prefix.equals(writerPrefix)) {
+    protected boolean isAssociated(String prefix, String namespace) throws OutputException {
+        try {
+            // The "xml" prefix is always (implicitly) associated. Returning true here makes sure that
+            // we never write a declaration for the xml namespace. See AXIOM-37 for a discussion
+            // of this issue.
+            if ("xml".equals(prefix)) {
                 return true;
             }
             
-            // It is possible that the namespace is associated with multiple prefixes,
-            // So try getting the namespace as a second step.
-            if (writerPrefix != null) {
-                NamespaceContext nsContext = writer.getNamespaceContext();
-                if(nsContext != null) {
-                    String writerNS = nsContext.getNamespaceURI(prefix);
-                    return namespace.equals(writerNS);
-                }
-            }
-            return false;
-        } else {
-            // UNQUALIFIED NAMESPACE
+            // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
+            // Please use other writer methods first.
             
-            // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
-            if (prefix.length() > 0) {
-                throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");  
-            }
-            
-            // Get the namespace associated with the prefix.
-            // It is illegal to call getPrefix with null, but the specification is not
-            // clear on what happens if called with "".  So the following code is 
-            // protected
-            try {
-                String writerPrefix = writer.getPrefix("");
-                if (writerPrefix != null && writerPrefix.length() == 0) {
+            // For consistency, convert null arguments.
+            // This helps get around the parser implementation differences.
+            // In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
+            prefix = (prefix == null) ? "" : prefix;
+            namespace = (namespace == null) ? "" : namespace;
+            
+            if (namespace.length() > 0) {
+                // QUALIFIED NAMESPACE
+                // Get the namespace associated with the prefix
+                String writerPrefix = writer.getPrefix(namespace);
+                if (prefix.equals(writerPrefix)) {
                     return true;
                 }
-            } catch (Throwable t) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
+                
+                // It is possible that the namespace is associated with multiple prefixes,
+                // So try getting the namespace as a second step.
+                if (writerPrefix != null) {
+                    NamespaceContext nsContext = writer.getNamespaceContext();
+                    if(nsContext != null) {
+                        String writerNS = nsContext.getNamespaceURI(prefix);
+                        return namespace.equals(writerNS);
+                    }
                 }
-            }
-            
-            
-            
-            // Fallback to using the namespace context
-            NamespaceContext nsContext = writer.getNamespaceContext();
-            if (nsContext != null) {
-                String writerNS = nsContext.getNamespaceURI("");
-                if (writerNS != null && writerNS.length() > 0) {
-                    return false;
+                return false;
+            } else {
+                // UNQUALIFIED NAMESPACE
+                
+                // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
+                if (prefix.length() > 0) {
+                    throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");  
+                }
+                
+                // Get the namespace associated with the prefix.
+                // It is illegal to call getPrefix with null, but the specification is not
+                // clear on what happens if called with "".  So the following code is 
+                // protected
+                try {
+                    String writerPrefix = writer.getPrefix("");
+                    if (writerPrefix != null && writerPrefix.length() == 0) {
+                        return true;
+                    }
+                } catch (Throwable t) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
+                    }
                 }
+                
+                
+                
+                // Fallback to using the namespace context
+                NamespaceContext nsContext = writer.getNamespaceContext();
+                if (nsContext != null) {
+                    String writerNS = nsContext.getNamespaceURI("");
+                    if (writerNS != null && writerNS.length() > 0) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
+        }
+    }
+
+    public void writeText(int type, String data) throws OutputException {
+        try {
+            if (type == OMNode.CDATA_SECTION_NODE) {
+                writer.writeCData(data);
+            } else {
+                writer.writeCharacters(data);
             }
-            return true;
+        } catch (XMLStreamException ex) {
+            throw new OutputException(ex);
         }
     }
 }

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java Mon Jan 28 21:13:17 2013
@@ -27,7 +27,7 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Element;

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java Mon Jan 28 21:13:17 2013
@@ -22,7 +22,7 @@ package org.apache.axiom.om.impl.dom;
 import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.Comment;
 import org.w3c.dom.Node;
 

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java Mon Jan 28 21:13:17 2013
@@ -25,7 +25,7 @@ import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.common.IContainer;
 import org.apache.axiom.om.impl.common.OMContainerHelper;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Node;
 

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Mon Jan 28 21:13:17 2013
@@ -35,7 +35,8 @@ import org.apache.axiom.om.impl.common.I
 import org.apache.axiom.om.impl.common.OMContainerHelper;
 import org.apache.axiom.om.impl.common.OMDocumentHelper;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.Attr;
 import org.w3c.dom.CDATASection;
 import org.w3c.dom.Comment;
@@ -103,7 +104,7 @@ public class DocumentImpl extends RootNo
         return null;
     }
 
-    public void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException {
+    public void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException, OutputException {
         internalSerialize(serializer, cache, !((MTOMXMLStreamWriter)serializer.getWriter()).isIgnoreXMLDeclaration());
     }
 
@@ -404,13 +405,21 @@ public class DocumentImpl extends RootNo
     public void serializeAndConsume(OutputStream output, OMOutputFormat format)
             throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
-        internalSerialize(new StAXSerializer(writer), false);
+        try {
+            internalSerialize(new StAXSerializer(this, writer), false);
+        } catch (OutputException ex) {
+            throw (XMLStreamException)ex.getCause();
+        }
         writer.flush();
     }
 
     public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
-        internalSerialize(new StAXSerializer(writer), true);
+        try {
+            internalSerialize(new StAXSerializer(this, writer), true);
+        } catch (OutputException ex) {
+            throw (XMLStreamException)ex.getCause();
+        }
         writer.flush();
     }
 
@@ -570,7 +579,7 @@ public class DocumentImpl extends RootNo
     }
 
     protected void internalSerialize(StAXSerializer serializer, boolean cache,
-            boolean includeXMLDeclaration) throws XMLStreamException {
+            boolean includeXMLDeclaration) throws XMLStreamException, OutputException {
         OMDocumentHelper.internalSerialize(this, serializer, cache, includeXMLDeclaration);
     }
 

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java Mon Jan 28 21:13:17 2013
@@ -24,7 +24,7 @@ import javax.xml.stream.XMLStreamExcepti
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.util.stax.XMLStreamWriterUtils;
 import org.w3c.dom.DocumentType;
 import org.w3c.dom.NamedNodeMap;

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Mon Jan 28 21:13:17 2013
@@ -36,7 +36,8 @@ import org.apache.axiom.om.impl.common.O
 import org.apache.axiom.om.impl.common.OMElementHelper;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.OMNodeHelper;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.traverse.OMQNameFilterIterator;
 import org.apache.axiom.om.impl.traverse.OMQualifiedNameFilterIterator;
 import org.apache.axiom.om.impl.util.EmptyIterator;
@@ -890,7 +891,7 @@ public class ElementImpl extends ParentN
     }
 
     public void internalSerialize(StAXSerializer serializer,
-                                     boolean cache) throws XMLStreamException {
+                                     boolean cache) throws XMLStreamException, OutputException {
 
         if (cache || state == COMPLETE || (this.builder == null)) {
             serializer.serializeStartpart(this);

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/EntityReferenceImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/EntityReferenceImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/EntityReferenceImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/EntityReferenceImpl.java Mon Jan 28 21:13:17 2013
@@ -23,7 +23,7 @@ import javax.xml.stream.XMLStreamExcepti
 import org.apache.axiom.om.OMEntityReference;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.EntityReference;
 import org.w3c.dom.Node;
 

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Mon Jan 28 21:13:17 2013
@@ -26,11 +26,13 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMInformationItem;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMSerializable;
 import org.apache.axiom.om.OMXMLParserWrapper;
 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.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.w3c.dom.DOMException;
@@ -745,7 +747,11 @@ public abstract class NodeImpl implement
         MTOMXMLStreamWriter writer = xmlWriter instanceof MTOMXMLStreamWriter ?
                 (MTOMXMLStreamWriter) xmlWriter : 
                     new MTOMXMLStreamWriter(xmlWriter);
-        internalSerialize(new StAXSerializer(writer), cache);
+        try {
+            internalSerialize(new StAXSerializer((OMSerializable)this, writer), cache);
+        } catch (OutputException ex) {
+            throw (XMLStreamException)ex.getCause();
+        }
         writer.flush();
     }
 
@@ -790,7 +796,11 @@ public abstract class NodeImpl implement
             throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, true);
         try {
-            internalSerialize(new StAXSerializer(writer), true);
+            try {
+                internalSerialize(new StAXSerializer((OMSerializable)this, writer), true);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -804,7 +814,11 @@ public abstract class NodeImpl implement
                 .createXMLStreamWriter(writer2));
         writer.setOutputFormat(format);
         try {
-            internalSerialize(new StAXSerializer(writer), true);
+            try {
+                internalSerialize(new StAXSerializer((OMSerializable)this, writer), true);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -816,7 +830,11 @@ public abstract class NodeImpl implement
             throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, false);
         try {
-            internalSerialize(new StAXSerializer(writer), false);
+            try {
+                internalSerialize(new StAXSerializer((OMSerializable)this, writer), false);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -831,7 +849,11 @@ public abstract class NodeImpl implement
         try {
             writer.setOutputFormat(format);
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
-            internalSerialize(new StAXSerializer(writer), false);
+            try {
+                internalSerialize(new StAXSerializer((OMSerializable)this, writer), false);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             writer.flush();
         } finally {
             writer.close();
@@ -840,7 +862,7 @@ public abstract class NodeImpl implement
 
     // This method is actually defined by ISerializable, but ISerializable is only implemented
     // by certain subclasses (for the reason, see AXIOM-385).
-    public abstract void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException;
+    public abstract void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException, OutputException;
     
     public final OMInformationItem clone(OMCloneOptions options) {
         return (OMInformationItem)clone(options, null, true, true);

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java Mon Jan 28 21:13:17 2013
@@ -25,7 +25,7 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMProcessingInstruction;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
 import org.w3c.dom.ProcessingInstruction;

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java Mon Jan 28 21:13:17 2013
@@ -28,7 +28,8 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.util.UIDGenerator;
 import org.apache.axiom.util.base64.Base64Utils;
 import org.apache.axiom.util.stax.XMLStreamWriterUtils;
@@ -39,7 +40,6 @@ import org.w3c.dom.Text;
 import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
 import java.io.IOException;
 
 public abstract class TextNodeImpl extends CharacterImpl implements Text, OMText {
@@ -235,20 +235,6 @@ public abstract class TextNodeImpl exten
         }
     }
 
-    /**
-     * Writes the relevant output.
-     *
-     * @param writer
-     * @throws XMLStreamException
-     */
-    private void writeOutput(XMLStreamWriter writer) throws XMLStreamException {
-        if (getType() == OMNode.CDATA_SECTION_NODE) {
-            writer.writeCData(this.getText());
-        } else {
-            writer.writeCharacters(this.getText());
-        }
-    }
-
     public String getText() {
         if (this.charArray != null || this.textValue != null) {
             return getTextFromProperPlace();
@@ -357,9 +343,9 @@ public abstract class TextNodeImpl exten
     }
 
     public void internalSerialize(StAXSerializer serializer, boolean cache)
-            throws XMLStreamException {
+            throws XMLStreamException, OutputException {
         if (!this.isBinary) {
-            writeOutput(serializer.getWriter());
+            serializer.writeText(getType(), getText());
         } else {
             try {
                 if (dataHandlerObject instanceof DataHandlerProvider) {

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java Mon Jan 28 21:13:17 2013
@@ -30,11 +30,10 @@ 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.OMNodeEx;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.dom.NodeImpl;
 import org.apache.axiom.om.impl.dom.ParentNode;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP11Version;
 import org.apache.axiom.soap.SOAP12Constants;
@@ -52,7 +51,6 @@ import org.w3c.dom.Node;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
 
 public class SOAPEnvelopeImpl extends SOAPElement implements SOAPEnvelope,
         OMConstants {
@@ -192,7 +190,7 @@ public class SOAPEnvelopeImpl extends SO
     }
 
     public void internalSerialize(StAXSerializer serializer, boolean cache)
-            throws XMLStreamException {
+            throws XMLStreamException, OutputException {
 
         MTOMXMLStreamWriter writer = (MTOMXMLStreamWriter)serializer.getWriter();
         if (!writer.isIgnoreXMLDeclaration()) {

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java Mon Jan 28 21:13:17 2013
@@ -23,7 +23,8 @@ import org.apache.axiom.om.OMCloneOption
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.dom.DocumentImpl;
 import org.apache.axiom.om.impl.dom.NodeImpl;
 import org.apache.axiom.soap.SOAPEnvelope;
@@ -59,7 +60,7 @@ public class SOAPMessageImpl extends Doc
     }
 
     protected void internalSerialize(StAXSerializer serializer, boolean cache,
-                                     boolean includeXMLDeclaration) throws XMLStreamException {
+                                     boolean includeXMLDeclaration) throws XMLStreamException, OutputException {
         ((NodeImpl)getOwnerDocument().getDocumentElement()).internalSerialize(serializer, cache);
     }
 

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java Mon Jan 28 21:13:17 2013
@@ -24,7 +24,7 @@ import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 
 import javax.xml.stream.XMLStreamException;
 

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java Mon Jan 28 21:13:17 2013
@@ -24,7 +24,7 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.util.stax.XMLStreamWriterUtils;
 
 import javax.xml.stream.XMLStreamException;

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java Mon Jan 28 21:13:17 2013
@@ -36,7 +36,8 @@ import org.apache.axiom.om.impl.common.O
 import org.apache.axiom.om.impl.common.OMContainerHelper;
 import org.apache.axiom.om.impl.common.OMDescendantsIterator;
 import org.apache.axiom.om.impl.common.OMDocumentHelper;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 
@@ -289,12 +290,12 @@ public class OMDocumentImpl extends OMSe
         this.xmlEncoding = encoding;
     }
 
-    public void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException {
+    public void internalSerialize(StAXSerializer serializer, boolean cache) throws XMLStreamException, OutputException {
         internalSerialize(serializer, cache, !((MTOMXMLStreamWriter)serializer.getWriter()).isIgnoreXMLDeclaration());
     }
 
     protected void internalSerialize(StAXSerializer serializer, boolean cache,
-                                     boolean includeXMLDeclaration) throws XMLStreamException {
+                                     boolean includeXMLDeclaration) throws XMLStreamException, OutputException {
         OMDocumentHelper.internalSerialize(this, serializer, cache, includeXMLDeclaration);
     }
 

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Mon Jan 28 21:13:17 2013
@@ -43,7 +43,8 @@ import org.apache.axiom.om.impl.common.O
 import org.apache.axiom.om.impl.common.OMDescendantsIterator;
 import org.apache.axiom.om.impl.common.OMElementHelper;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.apache.axiom.om.impl.util.EmptyIterator;
@@ -787,7 +788,7 @@ public class OMElementImpl extends OMNod
 //////////////////////////////////////////////////////////////////////////////////////////////
 
     public void internalSerialize(StAXSerializer serializer, boolean cache)
-            throws XMLStreamException {
+            throws XMLStreamException, OutputException {
 
         if (cache || state == COMPLETE || (this.builder == null)) {
             serializer.serializeStartpart(this);

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMEntityReferenceImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMEntityReferenceImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMEntityReferenceImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMEntityReferenceImpl.java Mon Jan 28 21:13:17 2013
@@ -25,7 +25,7 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMEntityReference;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 
 public class OMEntityReferenceImpl extends OMLeafNode implements OMEntityReference {
     private final String name;

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java Mon Jan 28 21:13:17 2013
@@ -24,7 +24,7 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMProcessingInstruction;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 
 import javax.xml.stream.XMLStreamException;
 

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSerializableImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSerializableImpl.java?rev=1439636&r1=1439635&r2=1439636&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSerializableImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSerializableImpl.java Mon Jan 28 21:13:17 2013
@@ -31,7 +31,8 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.om.impl.common.ISerializable;
-import org.apache.axiom.om.impl.common.StAXSerializer;
+import org.apache.axiom.om.impl.common.serializer.OutputException;
+import org.apache.axiom.om.impl.common.serializer.StAXSerializer;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.commons.logging.Log;
@@ -84,7 +85,11 @@ public abstract class OMSerializableImpl
         MTOMXMLStreamWriter writer = xmlWriter instanceof MTOMXMLStreamWriter ?
                 (MTOMXMLStreamWriter) xmlWriter : 
                     new MTOMXMLStreamWriter(xmlWriter);
-        internalSerialize(new StAXSerializer(writer), cache);
+        try {
+            internalSerialize(new StAXSerializer(this, writer), cache);
+        } catch (OutputException ex) {
+            throw (XMLStreamException)ex.getCause();
+        }
         writer.flush();
     }
 
@@ -127,7 +132,11 @@ public abstract class OMSerializableImpl
     public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, true);
         try {
-            internalSerialize(new StAXSerializer(writer), true);
+            try {
+                internalSerialize(new StAXSerializer(this, writer), true);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -140,7 +149,11 @@ public abstract class OMSerializableImpl
                 new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer2));
         writer.setOutputFormat(format);
         try {
-            internalSerialize(new StAXSerializer(writer), true);
+            try {
+                internalSerialize(new StAXSerializer(this, writer), true);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -152,7 +165,11 @@ public abstract class OMSerializableImpl
             throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, false);
         try {
-            internalSerialize(new StAXSerializer(writer), false);
+            try {
+                internalSerialize(new StAXSerializer(this, writer), false);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
@@ -166,7 +183,11 @@ public abstract class OMSerializableImpl
                 new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer2));
         writer.setOutputFormat(format);
         try {
-            internalSerialize(new StAXSerializer(writer), false);
+            try {
+                internalSerialize(new StAXSerializer(this, writer), false);
+            } catch (OutputException ex) {
+                throw (XMLStreamException)ex.getCause();
+            }
             // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {