axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r216290 [5/8] - in /webservices/axis/trunk/java/modules: core/src/org/apache/axis2/transport/ core/src/org/apache/axis2/transport/http/ core/webapp/ saaj/src/org/apache/axis2/saaj/ samples/src/sample/amazon/search/ samples/src/userguide/cli...
Date Thu, 14 Jul 2005 00:30:59 GMT
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Wed Jul 13 17:30:55 2005
@@ -1,416 +1,416 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed 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.axis2.om.impl.llom;
-
-import org.apache.axis2.attachments.Base64;
-import org.apache.axis2.attachments.ByteArrayDataSource;
-import org.apache.axis2.attachments.IOUtils;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMConstants;
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.OMException;
-import org.apache.axis2.om.OMNamespace;
-import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.OMOutput;
-import org.apache.axis2.om.OMText;
-import org.apache.axis2.om.OMXMLParserWrapper;
-import org.apache.axis2.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
-
-import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Random;
-
-public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
-    protected String value = null;
-    protected String mimeType;
-    protected boolean optimize = false;
-    protected boolean isBinary = false;
-    private static Random rnd = new Random(new Date().getTime());
-    /**
-     * Field contentID for the mime part used when serialising Binary stuff as
-     * MTOM optimised
-     */
-    private String contentID = null;
-    /**
-     * Field dataHandler
-     */
-    private DataHandler dataHandler = null;
-    /**
-     * Field nameSpace used when serialising Binary stuff as MTOM optimised
-     */
-    protected OMNamespace ns = new OMNamespaceImpl(
-            "http://www.w3.org/2004/08/xop/Include", "xop");
-    /**
-     * Field localName used when serialising Binary stuff as MTOM optimised
-     */
-    protected String localName = "Include";
-    /**
-     * Field attributes used when serialising Binary stuff as MTOM optimised
-     */
-    protected OMAttribute attribute;
-
-    /**
-     * Constructor OMTextImpl
-     *
-     * @param s
-     */
-    public OMTextImpl(String s) {
-        this.value = s;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * Constructor OMTextImpl
-     *
-     * @param parent
-     * @param text
-     */
-    public OMTextImpl(OMElement parent, String text) {
-        super(parent);
-        this.value = text;
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param s        -
-     *                 base64 encoded String representation of Binary
-     * @param mimeType of the Binary
-     */
-    public OMTextImpl(String s, String mimeType, boolean optimize) {
-        this(null, s, mimeType, optimize);
-    }
-
-    /**
-     * @param parent
-     * @param s        -
-     *                 base64 encoded String representation of Binary
-     * @param mimeType of the Binary
-     */
-    public OMTextImpl(OMElement parent, String s, String mimeType,
-                      boolean optimize) {
-        this(parent, s);
-        this.mimeType = mimeType;
-        this.optimize = optimize;
-        if (this.contentID == null && optimize) {
-            createContentID();
-        }
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param dataHandler To send binary optimised content Created programatically.
-     */
-    public OMTextImpl(DataHandler dataHandler) {
-        this(dataHandler, true);
-    }
-
-    /**
-     * @param dataHandler
-     * @param optimize    To send binary content. Created progrmatically.
-     */
-    public OMTextImpl(DataHandler dataHandler, boolean optimize) {
-        this.dataHandler = dataHandler;
-        this.isBinary = true;
-        this.optimize = optimize;
-        if (this.contentID == null && optimize) {
-            createContentID();
-        }
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param contentID
-     * @param parent
-     * @param builder   Used when the builder is encountered with a XOP:Include tag
-     *                  Stores a reference to the builder and the content-id. Supports
-     *                  deffered parsing of MIME messages
-     */
-    public OMTextImpl(String contentID, OMElement parent,
-                      OMXMLParserWrapper builder) {
-        super(parent);
-        this.contentID = contentID;
-        this.optimize = true;
-        this.isBinary = true;
-        this.builder = builder;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    public void serializeWithCache(OMOutput omOutput) throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        int type = getType();
-        if (type == TEXT_NODE) {
-            writer.writeCharacters(this.value);
-        } else if (type == CDATA_SECTION_NODE) {
-            writer.writeCData(this.value);
-        }
-        OMNode nextSibling = this.getNextSibling();
-        if (nextSibling != null) {
-            nextSibling.serializeWithCache(omOutput);
-        }
-    }
-
-    /**
-     * Returns the value
-     */
-    public String getText() throws OMException {
-        if (this.value != null) {
-            return this.value;
-        } else {
-            try {
-                InputStream inStream;
-                inStream = this.getInputStream();
-                byte[] data;
-                data = new byte[inStream.available()];
-                IOUtils.readFully(inStream, data);
-                return Base64.encode(data);
-            } catch (Exception e) {
-                throw new OMException("Cannot read from Stream taken form the Data Handler"
-                        + e);
-            }
-        }
-    }
-
-    public boolean isOptimized() {
-        return optimize;
-    }
-
-    public void setOptimize(boolean value) {
-        this.optimize = value;
-        if (this.contentID == null && value) {
-            getContentID();
-        }
-    }
-
-    /**
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public DataHandler getDataHandler() {
-        /*
-        * this should return a DataHandler containing the binary data
-        * reperesented by the Base64 strings stored in OMText
-        */
-        if (value != null) {
-            ByteArrayDataSource dataSource;
-            byte[] data = Base64.decode(value);
-            if (mimeType != null) {
-                dataSource = new ByteArrayDataSource(data, mimeType);
-            } else {
-                // Assumes type as application/octet-stream
-                dataSource = new ByteArrayDataSource(data);
-            }
-            return new DataHandler(dataSource);
-        } else {
-            if (dataHandler == null) {
-                dataHandler = ((MTOMStAXSOAPModelBuilder) builder)
-                        .getDataHandler(contentID);
-            }
-            return dataHandler;
-        }
-    }
-
-    public String getLocalName() {
-        return localName;
-    }
-
-    public java.io.InputStream getInputStream() throws OMException {
-        if (isBinary) {
-            if (dataHandler == null) {
-                getDataHandler();
-            }
-            InputStream inStream;
-            try {
-                inStream = dataHandler.getDataSource().getInputStream();
-            } catch (IOException e) {
-                throw new OMException(
-                        "Cannot get InputStream from DataHandler." + e);
-            }
-            return inStream;
-        } else {
-            throw new OMException("Unsupported Operation");
-        }
-    }
-
-    public String getContentID() {
-        return this.contentID;
-    }
-
-    public boolean isComplete() {
-        return done;
-    }
-
-    public void serialize(OMOutput omOutput) throws XMLStreamException {
-        if (!this.isBinary) {
-            serializeWithCache(omOutput);
-        } else {
-            if (omOutput.doOptimise()) {
-                // send binary as MTOM optimised
-                this.attribute =
-                        new OMAttributeImpl("href",
-                                new OMNamespaceImpl("", ""),
-                                "cid:"
-                                        + this.contentID.trim());
-                this.serializeStartpart(omOutput);
-                omOutput.writeOptimised(this);
-                omOutput.getXmlStreamWriter().writeEndElement();
-            } else {
-                omOutput.getXmlStreamWriter().writeCharacters(this.getText());
-            }
-            // TODO do we need these
-            OMNode nextSibling = this.getNextSibling();
-            if (nextSibling != null) {
-                // serilize next sibling
-                nextSibling.serialize(omOutput);
-            } else {
-                // TODO : See whether following part is really needed
-                if (parent != null && !parent.isComplete()) {
-                    // do the special serialization
-                    // Only the push serializer is left now
-                    builder.next();
-                }
-            }
-        }
-    }
-
-    private void createContentID() {
-        // We can use a UUID, taken using Apache commons id project.
-        // TODO change to UUID
-        this.contentID = "2" + String.valueOf(rnd.nextLong()) +
-                "@schemas.xmlsoap.org";
-    }
-
-    /*
-    * Methods to copy from OMSerialize utils
-    */
-    private void serializeStartpart(OMOutput omOutput)
-            throws XMLStreamException {
-        String nameSpaceName;
-        String writer_prefix;
-        String prefix;
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        if (this.ns != null) {
-            nameSpaceName = this.ns.getName();
-            writer_prefix = writer.getPrefix(nameSpaceName);
-            prefix = this.ns.getPrefix();
-            if (nameSpaceName != null) {
-                if (writer_prefix != null) {
-                    writer.writeStartElement(nameSpaceName,
-                            this.getLocalName());
-                } else {
-                    if (prefix != null) {
-                        writer.writeStartElement(prefix, this.getLocalName(),
-                                nameSpaceName);
-                        //TODO FIX ME
-                        //writer.writeNamespace(prefix, nameSpaceName);
-                        writer.setPrefix(prefix, nameSpaceName);
-                    } else {
-                        writer.writeStartElement(nameSpaceName,
-                                this.getLocalName());
-                        writer.writeDefaultNamespace(nameSpaceName);
-                        writer.setDefaultNamespace(nameSpaceName);
-                    }
-                }
-            } else {
-                writer.writeStartElement(this.getLocalName());
-            }
-        } else {
-            writer.writeStartElement(this.getLocalName());
-        }
-        // add the elements attribute "href"
-        serializeAttribute(this.attribute, omOutput);
-        // add the namespace
-        serializeNamespace(this.ns, omOutput);
-    }
-
-    /**
-     * Method serializeAttribute
-     *
-     * @param attr
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    static void serializeAttribute(OMAttribute attr, OMOutput omOutput)
-            throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        // first check whether the attribute is associated with a namespace
-        OMNamespace ns = attr.getNamespace();
-        String prefix;
-        String namespaceName;
-        if (ns != null) {
-            // add the prefix if it's availble
-            prefix = ns.getPrefix();
-            namespaceName = ns.getName();
-            if (prefix != null) {
-                writer.writeAttribute(prefix,
-                        namespaceName,
-                        attr
-                                .getLocalName(),
-                        attr.getValue());
-            } else {
-                writer.writeAttribute(namespaceName,
-                        attr.getLocalName(),
-                        attr
-                                .getValue());
-            }
-        } else {
-            writer.writeAttribute(attr.getLocalName(), attr.getValue());
-        }
-    }
-
-    /**
-     * Method serializeNamespace
-     *
-     * @param namespace
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    static void serializeNamespace(OMNamespace namespace, OMOutput omOutput)
-            throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        if (namespace != null) {
-            String uri = namespace.getName();
-            String ns_prefix = namespace.getPrefix();
-            writer.writeNamespace(ns_prefix, namespace.getName());
-            writer.setPrefix(ns_prefix, uri);
-        }
-    }
-
-    /**
-     * Slightly different implementation of the discard method
-     *
-     * @throws OMException
-     */
-    public void discard() throws OMException {
-        if (done) {
-            this.detach();
-        } else {
-            builder.discard((OMElement) this.parent);
-        }
-    }
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.om.impl.llom;
+
+import org.apache.axis2.attachments.Base64;
+import org.apache.axis2.attachments.ByteArrayDataSource;
+import org.apache.axis2.attachments.IOUtils;
+import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMConstants;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Random;
+
+public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
+    protected String value = null;
+    protected String mimeType;
+    protected boolean optimize = false;
+    protected boolean isBinary = false;
+    private static Random rnd = new Random(new Date().getTime());
+    /**
+     * Field contentID for the mime part used when serialising Binary stuff as
+     * MTOM optimised
+     */
+    private String contentID = null;
+    /**
+     * Field dataHandler
+     */
+    private DataHandler dataHandler = null;
+    /**
+     * Field nameSpace used when serialising Binary stuff as MTOM optimised
+     */
+    protected OMNamespace ns = new OMNamespaceImpl(
+            "http://www.w3.org/2004/08/xop/Include", "xop");
+    /**
+     * Field localName used when serialising Binary stuff as MTOM optimised
+     */
+    protected String localName = "Include";
+    /**
+     * Field attributes used when serialising Binary stuff as MTOM optimised
+     */
+    protected OMAttribute attribute;
+
+    /**
+     * Constructor OMTextImpl
+     *
+     * @param s
+     */
+    public OMTextImpl(String s) {
+        this.value = s;
+        this.nodeType = TEXT_NODE;
+    }
+
+    /**
+     * Constructor OMTextImpl
+     *
+     * @param parent
+     * @param text
+     */
+    public OMTextImpl(OMElement parent, String text) {
+        super(parent);
+        this.value = text;
+        done = true;
+        this.nodeType = TEXT_NODE;
+    }
+
+    /**
+     * @param s        -
+     *                 base64 encoded String representation of Binary
+     * @param mimeType of the Binary
+     */
+    public OMTextImpl(String s, String mimeType, boolean optimize) {
+        this(null, s, mimeType, optimize);
+    }
+
+    /**
+     * @param parent
+     * @param s        -
+     *                 base64 encoded String representation of Binary
+     * @param mimeType of the Binary
+     */
+    public OMTextImpl(OMElement parent, String s, String mimeType,
+                      boolean optimize) {
+        this(parent, s);
+        this.mimeType = mimeType;
+        this.optimize = optimize;
+        if (this.contentID == null && optimize) {
+            createContentID();
+        }
+        done = true;
+        this.nodeType = TEXT_NODE;
+    }
+
+    /**
+     * @param dataHandler To send binary optimised content Created programatically.
+     */
+    public OMTextImpl(DataHandler dataHandler) {
+        this(dataHandler, true);
+    }
+
+    /**
+     * @param dataHandler
+     * @param optimize    To send binary content. Created progrmatically.
+     */
+    public OMTextImpl(DataHandler dataHandler, boolean optimize) {
+        this.dataHandler = dataHandler;
+        this.isBinary = true;
+        this.optimize = optimize;
+        if (this.contentID == null && optimize) {
+            createContentID();
+        }
+        done = true;
+        this.nodeType = TEXT_NODE;
+    }
+
+    /**
+     * @param contentID
+     * @param parent
+     * @param builder   Used when the builder is encountered with a XOP:Include tag
+     *                  Stores a reference to the builder and the content-id. Supports
+     *                  deffered parsing of MIME messages
+     */
+    public OMTextImpl(String contentID, OMElement parent,
+                      OMXMLParserWrapper builder) {
+        super(parent);
+        this.contentID = contentID;
+        this.optimize = true;
+        this.isBinary = true;
+        this.builder = builder;
+        this.nodeType = TEXT_NODE;
+    }
+
+    /**
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    public void serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        int type = getType();
+        if (type == TEXT_NODE) {
+            writer.writeCharacters(this.value);
+        } else if (type == CDATA_SECTION_NODE) {
+            writer.writeCData(this.value);
+        }
+        OMNode nextSibling = this.getNextSibling();
+        if (nextSibling != null) {
+            nextSibling.serializeWithCache(omOutput);
+        }
+    }
+
+    /**
+     * Returns the value
+     */
+    public String getText() throws OMException {
+        if (this.value != null) {
+            return this.value;
+        } else {
+            try {
+                InputStream inStream;
+                inStream = this.getInputStream();
+                byte[] data;
+                data = new byte[inStream.available()];
+                IOUtils.readFully(inStream, data);
+                return Base64.encode(data);
+            } catch (Exception e) {
+                throw new OMException("Cannot read from Stream taken form the Data Handler"
+                        + e);
+            }
+        }
+    }
+
+    public boolean isOptimized() {
+        return optimize;
+    }
+
+    public void setOptimize(boolean value) {
+        this.optimize = value;
+        if (this.contentID == null && value) {
+            getContentID();
+        }
+    }
+
+    /**
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public DataHandler getDataHandler() {
+        /*
+        * this should return a DataHandler containing the binary data
+        * reperesented by the Base64 strings stored in OMText
+        */
+        if (value != null) {
+            ByteArrayDataSource dataSource;
+            byte[] data = Base64.decode(value);
+            if (mimeType != null) {
+                dataSource = new ByteArrayDataSource(data, mimeType);
+            } else {
+                // Assumes type as application/octet-stream
+                dataSource = new ByteArrayDataSource(data);
+            }
+            return new DataHandler(dataSource);
+        } else {
+            if (dataHandler == null) {
+                dataHandler = ((MTOMStAXSOAPModelBuilder) builder)
+                        .getDataHandler(contentID);
+            }
+            return dataHandler;
+        }
+    }
+
+    public String getLocalName() {
+        return localName;
+    }
+
+    public java.io.InputStream getInputStream() throws OMException {
+        if (isBinary) {
+            if (dataHandler == null) {
+                getDataHandler();
+            }
+            InputStream inStream;
+            try {
+                inStream = dataHandler.getDataSource().getInputStream();
+            } catch (IOException e) {
+                throw new OMException(
+                        "Cannot get InputStream from DataHandler." + e);
+            }
+            return inStream;
+        } else {
+            throw new OMException("Unsupported Operation");
+        }
+    }
+
+    public String getContentID() {
+        return this.contentID;
+    }
+
+    public boolean isComplete() {
+        return done;
+    }
+
+    public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        if (!this.isBinary) {
+            serializeWithCache(omOutput);
+        } else {
+            if (omOutput.doOptimise()) {
+                // send binary as MTOM optimised
+                this.attribute =
+                        new OMAttributeImpl("href",
+                                new OMNamespaceImpl("", ""),
+                                "cid:"
+                                        + this.contentID.trim());
+                this.serializeStartpart(omOutput);
+                omOutput.writeOptimized(this);
+                omOutput.getXmlStreamWriter().writeEndElement();
+            } else {
+                omOutput.getXmlStreamWriter().writeCharacters(this.getText());
+            }
+            // TODO do we need these
+            OMNode nextSibling = this.getNextSibling();
+            if (nextSibling != null) {
+                // serilize next sibling
+                nextSibling.serialize(omOutput);
+            } else {
+                // TODO : See whether following part is really needed
+                if (parent != null && !parent.isComplete()) {
+                    // do the special serialization
+                    // Only the push serializer is left now
+                    builder.next();
+                }
+            }
+        }
+    }
+
+    private void createContentID() {
+        // We can use a UUID, taken using Apache commons id project.
+        // TODO change to UUID
+        this.contentID = "2" + String.valueOf(rnd.nextLong()) +
+                "@schemas.xmlsoap.org";
+    }
+
+    /*
+    * Methods to copy from OMSerialize utils
+    */
+    private void serializeStartpart(OMOutputImpl omOutput)
+            throws XMLStreamException {
+        String nameSpaceName;
+        String writer_prefix;
+        String prefix;
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        if (this.ns != null) {
+            nameSpaceName = this.ns.getName();
+            writer_prefix = writer.getPrefix(nameSpaceName);
+            prefix = this.ns.getPrefix();
+            if (nameSpaceName != null) {
+                if (writer_prefix != null) {
+                    writer.writeStartElement(nameSpaceName,
+                            this.getLocalName());
+                } else {
+                    if (prefix != null) {
+                        writer.writeStartElement(prefix, this.getLocalName(),
+                                nameSpaceName);
+                        //TODO FIX ME
+                        //writer.writeNamespace(prefix, nameSpaceName);
+                        writer.setPrefix(prefix, nameSpaceName);
+                    } else {
+                        writer.writeStartElement(nameSpaceName,
+                                this.getLocalName());
+                        writer.writeDefaultNamespace(nameSpaceName);
+                        writer.setDefaultNamespace(nameSpaceName);
+                    }
+                }
+            } else {
+                writer.writeStartElement(this.getLocalName());
+            }
+        } else {
+            writer.writeStartElement(this.getLocalName());
+        }
+        // add the elements attribute "href"
+        serializeAttribute(this.attribute, omOutput);
+        // add the namespace
+        serializeNamespace(this.ns, omOutput);
+    }
+
+    /**
+     * Method serializeAttribute
+     *
+     * @param attr
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)
+            throws XMLStreamException {
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        // first check whether the attribute is associated with a namespace
+        OMNamespace ns = attr.getNamespace();
+        String prefix;
+        String namespaceName;
+        if (ns != null) {
+            // add the prefix if it's availble
+            prefix = ns.getPrefix();
+            namespaceName = ns.getName();
+            if (prefix != null) {
+                writer.writeAttribute(prefix,
+                        namespaceName,
+                        attr
+                                .getLocalName(),
+                        attr.getValue());
+            } else {
+                writer.writeAttribute(namespaceName,
+                        attr.getLocalName(),
+                        attr
+                                .getValue());
+            }
+        } else {
+            writer.writeAttribute(attr.getLocalName(), attr.getValue());
+        }
+    }
+
+    /**
+     * Method serializeNamespace
+     *
+     * @param namespace
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    static void serializeNamespace(OMNamespace namespace, org.apache.axis2.om.impl.OMOutputImpl omOutput)
+            throws XMLStreamException {
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        if (namespace != null) {
+            String uri = namespace.getName();
+            String ns_prefix = namespace.getPrefix();
+            writer.writeNamespace(ns_prefix, namespace.getName());
+            writer.setPrefix(ns_prefix, uri);
+        }
+    }
+
+    /**
+     * Slightly different implementation of the discard method
+     *
+     * @throws OMException
+     */
+    public void discard() throws OMException {
+        if (done) {
+            this.detach();
+        } else {
+            builder.discard((OMElement) this.parent);
+        }
+    }
 }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java Wed Jul 13 17:30:55 2005
@@ -1,234 +1,233 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed 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.axis2.om.impl.llom.serialize;
-
-import org.apache.axis2.om.OMOutput;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-/**
- * Class StreamWriterToContentHandlerConverter
- */
-public class StreamWriterToContentHandlerConverter implements ContentHandler {
-    /**
-     * Field log
-     */
-    private Log log = LogFactory.getLog(getClass());
-
-    /**
-     * Field writer
-     */
-    private XMLStreamWriter writer;
-
-    /**
-     * Constructor StreamWriterToContentHandlerConverter
-     *
-     * @param writer
-     */
-    public StreamWriterToContentHandlerConverter(OMOutput omOutput) {
-        this.writer = omOutput.getXmlStreamWriter();
-    }
-
-    /**
-     * Method endDocument
-     *
-     * @throws SAXException
-     */
-    public void endDocument() throws SAXException {
-
-        // do nothing
-    }
-
-    /**
-     * Method startDocument
-     *
-     * @throws SAXException
-     */
-    public void startDocument() throws SAXException {
-
-        // 
-    }
-
-    /**
-     * Method characters
-     *
-     * @param ch
-     * @param start
-     * @param length
-     * @throws SAXException
-     */
-    public void characters(char ch[], int start, int length)
-            throws SAXException {
-        try {
-            writer.writeCharacters(ch, start, length);
-        } catch (XMLStreamException e) {
-            throw new SAXException(e);
-        }
-    }
-
-    /**
-     * Method ignorableWhitespace
-     *
-     * @param ch
-     * @param start
-     * @param length
-     * @throws SAXException
-     */
-    public void ignorableWhitespace(char ch[], int start, int length)
-            throws SAXException {
-
-        // throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Method endPrefixMapping
-     *
-     * @param prefix
-     * @throws SAXException
-     */
-    public void endPrefixMapping(String prefix) throws SAXException {
-
-        // throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Method skippedEntity
-     *
-     * @param name
-     * @throws SAXException
-     */
-    public void skippedEntity(String name) throws SAXException {
-
-        // throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Method setDocumentLocator
-     *
-     * @param locator
-     */
-    public void setDocumentLocator(Locator locator) {
-
-        // throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Method processingInstruction
-     *
-     * @param target
-     * @param data
-     * @throws SAXException
-     */
-    public void processingInstruction(String target, String data)
-            throws SAXException {
-
-        // throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Method startPrefixMapping
-     *
-     * @param prefix
-     * @param uri
-     * @throws SAXException
-     */
-    public void startPrefixMapping(String prefix, String uri)
-            throws SAXException {
-        try {
-            writer.writeNamespace(prefix, uri);
-            writer.setPrefix(prefix, uri);
-        } catch (XMLStreamException e) {
-            throw new SAXException(e);
-        }
-    }
-
-    /**
-     * Method endElement
-     *
-     * @param namespaceURI
-     * @param localName
-     * @param qName
-     * @throws SAXException
-     */
-    public void endElement(String namespaceURI,
-                           String localName,
-                           String qName)
-            throws SAXException {
-        try {
-            writer.writeEndElement();
-        } catch (XMLStreamException e) {
-            throw new SAXException(e);
-        }
-    }
-
-    /**
-     * Method getPrefix
-     *
-     * @param qName
-     * @return
-     */
-    private String getPrefix(String qName) {
-        if (qName != null) {
-            return qName.substring(0, qName.indexOf(":"));
-        }
-        return null;
-    }
-
-    /**
-     * Method startElement
-     *
-     * @param namespaceURI
-     * @param localName
-     * @param qName
-     * @param atts
-     * @throws SAXException
-     */
-    public void startElement(String namespaceURI,
-                             String localName,
-                             String qName,
-                             Attributes atts)
-            throws SAXException {
-        try {
-            log.info("writing element {" + namespaceURI + '}' + localName
-                    + " directly to stream ");
-            String prefix = getPrefix(qName);
-
-            // it is only the prefix we want to learn from the QName! so we can get rid of the
-            // spliting QName
-            if (prefix == null) {
-                writer.writeStartElement(namespaceURI, localName);
-            } else {
-                writer.writeStartElement(prefix, localName, namespaceURI);
-            }
-            if (atts != null) {
-                int attCount = atts.getLength();
-                for (int i = 0; i < attCount; i++) {
-                    writer.writeAttribute(atts.getURI(i), localName,
-                            atts.getValue(i));
-                }
-            }
-        } catch (XMLStreamException e) {
-            throw new SAXException(e);
-        }
-    }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.om.impl.llom.serialize;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class StreamWriterToContentHandlerConverter
+ */
+public class StreamWriterToContentHandlerConverter implements ContentHandler {
+    /**
+     * Field log
+     */
+    private Log log = LogFactory.getLog(getClass());
+
+    /**
+     * Field writer
+     */
+    private XMLStreamWriter writer;
+
+    /**
+     * Constructor StreamWriterToContentHandlerConverter
+     *
+     * @param writer
+     */
+    public StreamWriterToContentHandlerConverter(org.apache.axis2.om.impl.OMOutputImpl omOutput) {
+        this.writer = omOutput.getXmlStreamWriter();
+    }
+
+    /**
+     * Method endDocument
+     *
+     * @throws SAXException
+     */
+    public void endDocument() throws SAXException {
+
+        // do nothing
+    }
+
+    /**
+     * Method startDocument
+     *
+     * @throws SAXException
+     */
+    public void startDocument() throws SAXException {
+
+        // 
+    }
+
+    /**
+     * Method characters
+     *
+     * @param ch
+     * @param start
+     * @param length
+     * @throws SAXException
+     */
+    public void characters(char ch[], int start, int length)
+            throws SAXException {
+        try {
+            writer.writeCharacters(ch, start, length);
+        } catch (XMLStreamException e) {
+            throw new SAXException(e);
+        }
+    }
+
+    /**
+     * Method ignorableWhitespace
+     *
+     * @param ch
+     * @param start
+     * @param length
+     * @throws SAXException
+     */
+    public void ignorableWhitespace(char ch[], int start, int length)
+            throws SAXException {
+
+        // throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method endPrefixMapping
+     *
+     * @param prefix
+     * @throws SAXException
+     */
+    public void endPrefixMapping(String prefix) throws SAXException {
+
+        // throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method skippedEntity
+     *
+     * @param name
+     * @throws SAXException
+     */
+    public void skippedEntity(String name) throws SAXException {
+
+        // throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method setDocumentLocator
+     *
+     * @param locator
+     */
+    public void setDocumentLocator(Locator locator) {
+
+        // throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method processingInstruction
+     *
+     * @param target
+     * @param data
+     * @throws SAXException
+     */
+    public void processingInstruction(String target, String data)
+            throws SAXException {
+
+        // throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method startPrefixMapping
+     *
+     * @param prefix
+     * @param uri
+     * @throws SAXException
+     */
+    public void startPrefixMapping(String prefix, String uri)
+            throws SAXException {
+        try {
+            writer.writeNamespace(prefix, uri);
+            writer.setPrefix(prefix, uri);
+        } catch (XMLStreamException e) {
+            throw new SAXException(e);
+        }
+    }
+
+    /**
+     * Method endElement
+     *
+     * @param namespaceURI
+     * @param localName
+     * @param qName
+     * @throws SAXException
+     */
+    public void endElement(String namespaceURI,
+                           String localName,
+                           String qName)
+            throws SAXException {
+        try {
+            writer.writeEndElement();
+        } catch (XMLStreamException e) {
+            throw new SAXException(e);
+        }
+    }
+
+    /**
+     * Method getPrefix
+     *
+     * @param qName
+     * @return
+     */
+    private String getPrefix(String qName) {
+        if (qName != null) {
+            return qName.substring(0, qName.indexOf(":"));
+        }
+        return null;
+    }
+
+    /**
+     * Method startElement
+     *
+     * @param namespaceURI
+     * @param localName
+     * @param qName
+     * @param atts
+     * @throws SAXException
+     */
+    public void startElement(String namespaceURI,
+                             String localName,
+                             String qName,
+                             Attributes atts)
+            throws SAXException {
+        try {
+            log.info("writing element {" + namespaceURI + '}' + localName
+                    + " directly to stream ");
+            String prefix = getPrefix(qName);
+
+            // it is only the prefix we want to learn from the QName! so we can get rid of the
+            // spliting QName
+            if (prefix == null) {
+                writer.writeStartElement(namespaceURI, localName);
+            } else {
+                writer.writeStartElement(prefix, localName, namespaceURI);
+            }
+            if (atts != null) {
+                int attCount = atts.getLength();
+                for (int i = 0; i < attCount; i++) {
+                    writer.writeAttribute(atts.getURI(i), localName,
+                            atts.getValue(i));
+                }
+            }
+        } catch (XMLStreamException e) {
+            throw new SAXException(e);
+        }
+    }
+}

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamingOMSerializer.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamingOMSerializer.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/serialize/StreamingOMSerializer.java Wed Jul 13 17:30:55 2005
@@ -1,235 +1,247 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed 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.axis2.om.impl.llom.serialize;
-
-import org.apache.axis2.om.OMOutput;
-import org.apache.axis2.om.OMSerializer;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-/**
- * Class StreamingOMSerializer
- */
-public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {
-
-    /*
-     * The behavior of the serializer is such that it returns when it encounters the
-     * starting element for the second time. The depth variable tracks the depth of the
-     * serilizer and tells it when to return.
-     * Note that it is assumed that this serilization starts on an Element
-     */
-
-    /**
-     * Field depth
-     */
-    private int depth = 0;
-
-    /**
-     * Method serializeWithCache
-     *
-     * @param obj
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    public void serialize(Object obj, OMOutput omOutput)
-            throws XMLStreamException {
-        if (!(obj instanceof XMLStreamReader)) {
-            throw new UnsupportedOperationException(
-                    "Unsupported input object. Must be of the the type XMLStreamReader");
-        }
-        XMLStreamReader node = (XMLStreamReader) obj;
-        serializeNode(node, omOutput);
-    }
-
-    /**
-     * Method serializeNode
-     *
-     * @param reader
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    protected void serializeNode(XMLStreamReader reader, OMOutput omOutput)
-            throws XMLStreamException {
-        //TODO We get the StAXWriter at this point and uses it hereafter assuming that this is the only entry point to this class.
-        // If there can be other classes calling methodes of this we might need to change methode signatures to OMOutputer
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        while (reader.hasNext()) {
-            int event = reader.next();
-            if (event == START_ELEMENT) {
-                serializeElement(reader, writer);
-                depth++;
-            } else if (event == ATTRIBUTE) {
-                serializeAttributes(reader, writer);
-            } else if (event == CHARACTERS) {
-                serializeText(reader, writer);
-            } else if (event == COMMENT) {
-                serializeComment(reader, writer);
-            } else if (event == CDATA) {
-                serializeCData(reader, writer);
-            } else if (event == END_ELEMENT) {
-                serializeEndElement(writer);
-                depth--;
-            } else if (event == END_DOCUMENT) {
-                try {
-                    serializeEndElement(writer);
-                } catch (Exception e) {
-                    //TODO: log exceptions
-                }
-            }
-            if (depth == 0) {
-                break;
-            }
-        }
-    }
-
-    /**
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeElement(XMLStreamReader reader,
-                                    XMLStreamWriter writer)
-            throws XMLStreamException {
-        String prefix = reader.getPrefix();
-        String nameSpaceName = reader.getNamespaceURI();
-        String writer_prefix = writer.getPrefix(nameSpaceName);
-        if (nameSpaceName != null) {
-            if (writer_prefix != null) {
-                writer.writeStartElement(nameSpaceName, reader.getLocalName());
-            } else {
-                if (prefix != null) {
-                    writer.writeStartElement(prefix, reader.getLocalName(),
-                            nameSpaceName);
-                    writer.writeNamespace(prefix, nameSpaceName);
-                    writer.setPrefix(prefix, nameSpaceName);
-                } else {
-                    writer.writeStartElement(nameSpaceName,
-                            reader.getLocalName());
-                    writer.writeDefaultNamespace(nameSpaceName);
-                    writer.setDefaultNamespace(nameSpaceName);
-                }
-            }
-        } else {
-//            throw new OMException(
-//                    "Non namespace qualified elements are not allowed");
-        }
-
-        // add attributes
-        serializeAttributes(reader, writer);
-
-        // add the namespaces
-        int count = reader.getNamespaceCount();
-        for (int i = 0; i < count; i++) {
-            serializeNamespace(reader.getNamespacePrefix(i),
-                    reader.getNamespaceURI(i), writer);
-        }
-    }
-
-    /**
-     * Method serializeEndElement
-     *
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeEndElement(XMLStreamWriter writer)
-            throws XMLStreamException {
-        writer.writeEndElement();
-    }
-
-    /**
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeText(XMLStreamReader reader,
-                                 XMLStreamWriter writer)
-            throws XMLStreamException {
-        writer.writeCharacters(reader.getText());
-    }
-
-    /**
-     * Method serializeCData
-     *
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeCData(XMLStreamReader reader,
-                                  XMLStreamWriter writer)
-            throws XMLStreamException {
-        writer.writeCData(reader.getText());
-    }
-
-    /**
-     * Method serializeComment
-     *
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeComment(XMLStreamReader reader,
-                                    XMLStreamWriter writer)
-            throws XMLStreamException {
-        writer.writeComment(reader.getText());
-    }
-
-    /**
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    protected void serializeAttributes(XMLStreamReader reader,
-                                       XMLStreamWriter writer)
-            throws XMLStreamException {
-        int count = reader.getAttributeCount();
-        String prefix = null;
-        String namespaceName = null;
-        for (int i = 0; i < count; i++) {
-            prefix = reader.getAttributePrefix(i);
-            namespaceName = reader.getAttributeNamespace(i);
-            if ((prefix != null) && !namespaceName.equals("")) {
-                writer.writeAttribute(prefix, namespaceName,
-                        reader.getAttributeLocalName(i),
-                        reader.getAttributeValue(i));
-            } else {
-                writer.writeAttribute(reader.getAttributeLocalName(i),
-                        reader.getAttributeValue(i));
-            }
-        }
-    }
-
-    /**
-     * Method serializeNamespace
-     *
-     * @param prefix
-     * @param URI
-     * @param writer
-     * @throws XMLStreamException
-     */
-    private void serializeNamespace(String prefix,
-                                    String URI,
-                                    XMLStreamWriter writer)
-            throws XMLStreamException {
-        String prefix1 = writer.getPrefix(URI);
-        if (prefix1 == null) {
-            writer.writeNamespace(prefix, URI);
-            writer.setPrefix(prefix, URI);
-        }
-    }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.om.impl.llom.serialize;
+
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.OMSerializer;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class StreamingOMSerializer
+ */
+public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {
+
+    /*
+     * The behavior of the serializer is such that it returns when it encounters the
+     * starting element for the second time. The depth variable tracks the depth of the
+     * serilizer and tells it when to return.
+     * Note that it is assumed that this serilization starts on an Element
+     */
+
+    /**
+     * Field depth
+     */
+    private int depth = 0;
+
+    /**
+     * Method serializeWithCache
+     *
+     * @param node
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public void serialize(XMLStreamReader node, XMLStreamWriter writer)
+            throws XMLStreamException {
+        serializeNode(node, new OMOutputImpl(writer));
+    }
+
+    /**
+     * Method serializeWithCache
+     *
+     * @param obj
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    public void serialize(XMLStreamReader obj, OMOutputImpl omOutput)
+            throws XMLStreamException {
+        if (!(obj instanceof XMLStreamReader)) {
+            throw new UnsupportedOperationException(
+                    "Unsupported input object. Must be of the the type XMLStreamReader");
+        }
+        XMLStreamReader node = (XMLStreamReader) obj;
+        serializeNode(node, omOutput);
+    }
+
+    /**
+     * Method serializeNode
+     *
+     * @param reader
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    protected void serializeNode(XMLStreamReader reader, OMOutputImpl omOutput)
+            throws XMLStreamException {
+        //TODO We get the StAXWriter at this point and uses it hereafter assuming that this is the only entry point to this class.
+        // If there can be other classes calling methodes of this we might need to change methode signatures to OMOutputer
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        while (reader.hasNext()) {
+            int event = reader.next();
+            if (event == START_ELEMENT) {
+                serializeElement(reader, writer);
+                depth++;
+            } else if (event == ATTRIBUTE) {
+                serializeAttributes(reader, writer);
+            } else if (event == CHARACTERS) {
+                serializeText(reader, writer);
+            } else if (event == COMMENT) {
+                serializeComment(reader, writer);
+            } else if (event == CDATA) {
+                serializeCData(reader, writer);
+            } else if (event == END_ELEMENT) {
+                serializeEndElement(writer);
+                depth--;
+            } else if (event == END_DOCUMENT) {
+                try {
+                    serializeEndElement(writer);
+                } catch (Exception e) {
+                    //TODO: log exceptions
+                }
+            }
+            if (depth == 0) {
+                break;
+            }
+        }
+    }
+
+    /**
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeElement(XMLStreamReader reader,
+                                    XMLStreamWriter writer)
+            throws XMLStreamException {
+        String prefix = reader.getPrefix();
+        String nameSpaceName = reader.getNamespaceURI();
+        String writer_prefix = writer.getPrefix(nameSpaceName);
+        if (nameSpaceName != null) {
+            if (writer_prefix != null) {
+                writer.writeStartElement(nameSpaceName, reader.getLocalName());
+            } else {
+                if (prefix != null) {
+                    writer.writeStartElement(prefix, reader.getLocalName(),
+                            nameSpaceName);
+                    writer.writeNamespace(prefix, nameSpaceName);
+                    writer.setPrefix(prefix, nameSpaceName);
+                } else {
+                    writer.writeStartElement(nameSpaceName,
+                            reader.getLocalName());
+                    writer.writeDefaultNamespace(nameSpaceName);
+                    writer.setDefaultNamespace(nameSpaceName);
+                }
+            }
+        } else {
+//            throw new OMException(
+//                    "Non namespace qualified elements are not allowed");
+        }
+
+        // add attributes
+        serializeAttributes(reader, writer);
+
+        // add the namespaces
+        int count = reader.getNamespaceCount();
+        for (int i = 0; i < count; i++) {
+            serializeNamespace(reader.getNamespacePrefix(i),
+                    reader.getNamespaceURI(i), writer);
+        }
+    }
+
+    /**
+     * Method serializeEndElement
+     *
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeEndElement(XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeEndElement();
+    }
+
+    /**
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeText(XMLStreamReader reader,
+                                 XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeCharacters(reader.getText());
+    }
+
+    /**
+     * Method serializeCData
+     *
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeCData(XMLStreamReader reader,
+                                  XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeCData(reader.getText());
+    }
+
+    /**
+     * Method serializeComment
+     *
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeComment(XMLStreamReader reader,
+                                    XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeComment(reader.getText());
+    }
+
+    /**
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeAttributes(XMLStreamReader reader,
+                                       XMLStreamWriter writer)
+            throws XMLStreamException {
+        int count = reader.getAttributeCount();
+        String prefix = null;
+        String namespaceName = null;
+        for (int i = 0; i < count; i++) {
+            prefix = reader.getAttributePrefix(i);
+            namespaceName = reader.getAttributeNamespace(i);
+            if ((prefix != null) && !namespaceName.equals("")) {
+                writer.writeAttribute(prefix, namespaceName,
+                        reader.getAttributeLocalName(i),
+                        reader.getAttributeValue(i));
+            } else {
+                writer.writeAttribute(reader.getAttributeLocalName(i),
+                        reader.getAttributeValue(i));
+            }
+        }
+    }
+
+    /**
+     * Method serializeNamespace
+     *
+     * @param prefix
+     * @param URI
+     * @param writer
+     * @throws XMLStreamException
+     */
+    private void serializeNamespace(String prefix,
+                                    String URI,
+                                    XMLStreamWriter writer)
+            throws XMLStreamException {
+        String prefix1 = writer.getPrefix(URI);
+        if (prefix1 == null) {
+            writer.writeNamespace(prefix, URI);
+            writer.setPrefix(prefix, URI);
+        }
+    }
+}

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultCodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultCodeImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultCodeImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultCodeImpl.java Wed Jul 13 17:30:55 2005
@@ -1,123 +1,122 @@
-package org.apache.axis2.soap.impl.llom;
-
-import org.apache.axis2.om.OMXMLParserWrapper;
-import org.apache.axis2.om.OMOutput;
-import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;
-import org.apache.axis2.om.impl.llom.OMSerializerUtil;
-import org.apache.axis2.soap.SOAPFault;
-import org.apache.axis2.soap.SOAPFaultCode;
-import org.apache.axis2.soap.SOAPFaultSubCode;
-import org.apache.axis2.soap.SOAPFaultValue;
-import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
-import org.apache.axis2.soap.impl.llom.util.UtilProvider;
-
-import javax.xml.stream.XMLStreamException;
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * Licensed 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
- */
-public abstract class SOAPFaultCodeImpl extends SOAPElement implements SOAPFaultCode {
-
-
-    /**
-     * Constructor OMElementImpl
-     *
-     * @param localName
-     * @param ns
-     * @param parent
-     * @param builder
-     */
-    public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {
-        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder);
-    }
-
-    /**
-     * @param parent
-     * @param parent
-     */
-    public SOAPFaultCodeImpl(SOAPFault parent,
-                             boolean extractNamespaceFromParent) throws SOAPProcessingException {
-        super(parent,
-                SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,
-                extractNamespaceFromParent);
-    }
-
-    /**
-     * Eran Chinthaka (chinthaka@apache.org)
-     */
-    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
-        UtilProvider.setNewElement(this, value, value);
-    }
-
-    public SOAPFaultValue getValue() {
-        return (SOAPFaultValue) UtilProvider.getChildWithName(this,
-                SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);
-    }
-
-    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException {
-        UtilProvider.setNewElement(this, getSubCode(), value);
-    }
-
-    public SOAPFaultSubCode getSubCode() {
-        return (SOAPFaultSubCode) UtilProvider.getChildWithName(this,
-                SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);
-    }
-
-    protected void serialize(OMOutput omOutput, boolean cache) throws XMLStreamException {
-        // select the builder
-        short builderType = PULL_TYPE_BUILDER;    // default is pull type
-        if (builder != null) {
-            builderType = this.builder.getBuilderType();
-        }
-        if ((builderType == PUSH_TYPE_BUILDER)
-                && (builder.getRegisteredContentHandler() == null)) {
-            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
-        }
-
-
-        if (!cache) {
-            //No caching
-            if (this.firstChild != null) {
-                OMSerializerUtil.serializeStartpart(this, omOutput);
-                firstChild.serialize(omOutput);
-                OMSerializerUtil.serializeEndpart(omOutput);
-            } else if (!this.done) {
-                if (builderType == PULL_TYPE_BUILDER) {
-                    OMSerializerUtil.serializeByPullStream(this, omOutput);
-                } else {
-                    OMSerializerUtil.serializeStartpart(this, omOutput);
-                    builder.setCache(cache);
-                    builder.next();
-                    OMSerializerUtil.serializeEndpart(omOutput);
-                }
-            } else {
-                OMSerializerUtil.serializeNormal(this, omOutput, cache);
-            }
-            // do not serialise the siblings
-
-
-        } else {
-            //Cached
-            OMSerializerUtil.serializeNormal(this, omOutput, cache);
-
-            // do not serialise the siblings
-        }
-
-
-    }
-
-}
+package org.apache.axis2.soap.impl.llom;
+
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;
+import org.apache.axis2.om.impl.llom.OMSerializerUtil;
+import org.apache.axis2.soap.SOAPFault;
+import org.apache.axis2.soap.SOAPFaultCode;
+import org.apache.axis2.soap.SOAPFaultSubCode;
+import org.apache.axis2.soap.SOAPFaultValue;
+import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
+import org.apache.axis2.soap.impl.llom.util.UtilProvider;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * Licensed 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public abstract class SOAPFaultCodeImpl extends SOAPElement implements SOAPFaultCode {
+
+
+    /**
+     * Constructor OMElementImpl
+     *
+     * @param localName
+     * @param ns
+     * @param parent
+     * @param builder
+     */
+    public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {
+        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder);
+    }
+
+    /**
+     * @param parent
+     * @param parent
+     */
+    public SOAPFaultCodeImpl(SOAPFault parent,
+                             boolean extractNamespaceFromParent) throws SOAPProcessingException {
+        super(parent,
+                SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,
+                extractNamespaceFromParent);
+    }
+
+    /**
+     * Eran Chinthaka (chinthaka@apache.org)
+     */
+    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
+        UtilProvider.setNewElement(this, value, value);
+    }
+
+    public SOAPFaultValue getValue() {
+        return (SOAPFaultValue) UtilProvider.getChildWithName(this,
+                SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);
+    }
+
+    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException {
+        UtilProvider.setNewElement(this, getSubCode(), value);
+    }
+
+    public SOAPFaultSubCode getSubCode() {
+        return (SOAPFaultSubCode) UtilProvider.getChildWithName(this,
+                SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);
+    }
+
+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
+        // select the builder
+        short builderType = PULL_TYPE_BUILDER;    // default is pull type
+        if (builder != null) {
+            builderType = this.builder.getBuilderType();
+        }
+        if ((builderType == PUSH_TYPE_BUILDER)
+                && (builder.getRegisteredContentHandler() == null)) {
+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
+        }
+
+
+        if (!cache) {
+            //No caching
+            if (this.firstChild != null) {
+                OMSerializerUtil.serializeStartpart(this, omOutput);
+                firstChild.serialize(omOutput);
+                OMSerializerUtil.serializeEndpart(omOutput);
+            } else if (!this.done) {
+                if (builderType == PULL_TYPE_BUILDER) {
+                    OMSerializerUtil.serializeByPullStream(this, omOutput);
+                } else {
+                    OMSerializerUtil.serializeStartpart(this, omOutput);
+                    builder.setCache(cache);
+                    builder.next();
+                    OMSerializerUtil.serializeEndpart(omOutput);
+                }
+            } else {
+                OMSerializerUtil.serializeNormal(this, omOutput, cache);
+            }
+            // do not serialise the siblings
+
+
+        } else {
+            //Cached
+            OMSerializerUtil.serializeNormal(this, omOutput, cache);
+
+            // do not serialise the siblings
+        }
+
+
+    }
+
+}

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultDetailImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultDetailImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultDetailImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPFaultDetailImpl.java Wed Jul 13 17:30:55 2005
@@ -1,98 +1,97 @@
-package org.apache.axis2.soap.impl.llom;
-
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.OMXMLParserWrapper;
-import org.apache.axis2.om.OMOutput;
-import org.apache.axis2.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;
-import org.apache.axis2.om.impl.llom.OMSerializerUtil;
-import org.apache.axis2.soap.SOAPFault;
-import org.apache.axis2.soap.SOAPFaultDetail;
-import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
-
-import javax.xml.stream.XMLStreamException;
-import java.util.Iterator;
-
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed 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.
- *
- * author : Eran Chinthaka (chinthaka@apache.org)
- */
-
-public abstract class SOAPFaultDetailImpl extends SOAPElement implements SOAPFaultDetail {
-
-    protected SOAPFaultDetailImpl(SOAPFault parent,
-                                  boolean extractNamespaceFromParent) throws SOAPProcessingException {
-        super(parent,
-                SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
-                extractNamespaceFromParent);
-    }
-
-    protected SOAPFaultDetailImpl(SOAPFault parent,
-                                  OMXMLParserWrapper builder) {
-        super(parent, SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, builder);
-    }
-
-    public void addDetailEntry(OMElement detailElement) {
-        this.addChild(detailElement);
-    }
-
-    public Iterator getAllDetailEntries() {
-        return this.getChildren();
-    }
-
-    protected void serialize(OMOutput omOutput, boolean cache) throws XMLStreamException {
-        // select the builder
-        short builderType = PULL_TYPE_BUILDER;    // default is pull type
-        if (builder != null) {
-            builderType = this.builder.getBuilderType();
-        }
-        if ((builderType == PUSH_TYPE_BUILDER)
-                && (builder.getRegisteredContentHandler() == null)) {
-            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
-        }
-
-
-        if (!cache) {
-            //No caching
-            if (this.firstChild != null) {
-                OMSerializerUtil.serializeStartpart(this, omOutput);
-                firstChild.serialize(omOutput);
-                OMSerializerUtil.serializeEndpart(omOutput);
-            } else if (!this.done) {
-                if (builderType == PULL_TYPE_BUILDER) {
-                    OMSerializerUtil.serializeByPullStream(this, omOutput);
-                } else {
-                    OMSerializerUtil.serializeStartpart(this, omOutput);
-                    builder.setCache(cache);
-                    builder.next();
-                    OMSerializerUtil.serializeEndpart(omOutput);
-                }
-            } else {
-                OMSerializerUtil.serializeNormal(this, omOutput, cache);
-            }
-            // do not serialise the siblings
-
-
-        } else {
-            //Cached
-            OMSerializerUtil.serializeNormal(this, omOutput, cache);
-
-            // do not serialise the siblings
-        }
-
-
-    }
-
-}
+package org.apache.axis2.soap.impl.llom;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;
+import org.apache.axis2.om.impl.llom.OMSerializerUtil;
+import org.apache.axis2.soap.SOAPFault;
+import org.apache.axis2.soap.SOAPFaultDetail;
+import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
+
+import javax.xml.stream.XMLStreamException;
+import java.util.Iterator;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public abstract class SOAPFaultDetailImpl extends SOAPElement implements SOAPFaultDetail {
+
+    protected SOAPFaultDetailImpl(SOAPFault parent,
+                                  boolean extractNamespaceFromParent) throws SOAPProcessingException {
+        super(parent,
+                SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
+                extractNamespaceFromParent);
+    }
+
+    protected SOAPFaultDetailImpl(SOAPFault parent,
+                                  OMXMLParserWrapper builder) {
+        super(parent, SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, builder);
+    }
+
+    public void addDetailEntry(OMElement detailElement) {
+        this.addChild(detailElement);
+    }
+
+    public Iterator getAllDetailEntries() {
+        return this.getChildren();
+    }
+
+    protected void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
+        // select the builder
+        short builderType = PULL_TYPE_BUILDER;    // default is pull type
+        if (builder != null) {
+            builderType = this.builder.getBuilderType();
+        }
+        if ((builderType == PUSH_TYPE_BUILDER)
+                && (builder.getRegisteredContentHandler() == null)) {
+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
+        }
+
+
+        if (!cache) {
+            //No caching
+            if (this.firstChild != null) {
+                OMSerializerUtil.serializeStartpart(this, omOutput);
+                firstChild.serialize(omOutput);
+                OMSerializerUtil.serializeEndpart(omOutput);
+            } else if (!this.done) {
+                if (builderType == PULL_TYPE_BUILDER) {
+                    OMSerializerUtil.serializeByPullStream(this, omOutput);
+                } else {
+                    OMSerializerUtil.serializeStartpart(this, omOutput);
+                    builder.setCache(cache);
+                    builder.next();
+                    OMSerializerUtil.serializeEndpart(omOutput);
+                }
+            } else {
+                OMSerializerUtil.serializeNormal(this, omOutput, cache);
+            }
+            // do not serialise the siblings
+
+
+        } else {
+            //Cached
+            OMSerializerUtil.serializeNormal(this, omOutput, cache);
+
+            // do not serialise the siblings
+        }
+
+
+    }
+
+}



Mime
View raw message