You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/07/14 02:30:59 UTC

svn commit: r216290 [4/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...

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Wed Jul 13 17:30:55 2005
@@ -1,817 +1,817 @@
-/*
-* 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.om.OMAbstractFactory;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMConstants;
-import org.apache.axis2.om.OMContainer;
-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.serialize.StreamWriterToContentHandlerConverter;
-import org.apache.axis2.om.impl.llom.traverse.OMChildrenIterator;
-import org.apache.axis2.om.impl.llom.traverse.OMChildrenQNameIterator;
-import org.apache.axis2.om.impl.llom.util.EmptyIterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.util.HashMap;
-import java.util.Iterator;
-
-/**
- * Class OMElementImpl
- */
-public class OMElementImpl extends OMNodeImpl
-        implements OMElement, OMConstants {
-    /**
-     * Field ns
-     */
-    protected OMNamespace ns;
-
-    /**
-     * Field localName
-     */
-    protected String localName;
-    /**
-     * Field firstChild
-     */
-    protected OMNode firstChild;
-
-    /**
-     * Field namespaces
-     */
-    protected HashMap namespaces = null;
-
-    /**
-     * Field attributes
-     */
-    protected HashMap attributes = null;
-
-    /**
-     * Field noPrefixNamespaceCounter
-     */
-    protected int noPrefixNamespaceCounter = 0;
-    private OMNode lastChild;
-
-    /**
-     * Constructor OMElementImpl
-     *
-     * @param localName
-     * @param ns
-     * @param parent
-     * @param builder
-     */
-    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent,
-                         OMXMLParserWrapper builder) {
-        super(parent);
-        this.localName = localName;
-        if (ns != null) {
-            setNamespace(handleNamespace(ns));
-        }
-        this.builder = builder;
-        firstChild = null;
-    }
-
-    /**
-     * @param parent
-     * @param parent
-     */
-    protected OMElementImpl(OMContainer parent) {
-        super(parent);
-        this.done = true;
-    }
-
-    /**
-     * Constructor OMElementImpl
-     *
-     * @param localName
-     * @param ns
-     */
-    public OMElementImpl(String localName, OMNamespace ns) {
-        super(null);
-        this.localName = localName;
-        this.done = true;
-        if (ns != null) {
-            setNamespace(handleNamespace(ns));
-        }
-    }
-
-    /**
-     * Constructor OMElementImpl
-     * @param localName
-     * @param ns
-     * @param parent
-     */
-    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent) {
-        super(parent);
-        this.localName = localName;
-        this.done = true;
-        if (ns != null) {
-            setNamespace(handleNamespace(ns));
-        }
-    }
-
-    /**
-     * Here it is assumed that this QName passed, at least contains the localName for this element
-     *
-     * @param qname
-     * @param parent
-     * @throws OMException
-     */
-    public OMElementImpl(QName qname, OMContainer parent) throws OMException {
-        super(parent);
-        this.localName = qname.getLocalPart();
-        this.done = true;
-        handleNamespace(qname);
-    }
-
-    /**
-     * Method handleNamespace
-     *
-     * @param qname
-     */
-    private void handleNamespace(QName qname) {
-        OMNamespace ns;
-
-        // first try to find a namespace from the scope
-        String namespaceURI = qname.getNamespaceURI();
-        if (!"".equals(namespaceURI)) {
-            ns = findNamespace(qname.getNamespaceURI(),
-                    qname.getPrefix());
-
-            /**
-             * What is left now is
-             *  1. nsURI = null & parent != null, but ns = null
-             *  2. nsURI != null, (parent doesn't have an ns with given URI), but ns = null
-             */
-            if ((ns == null) && !"".equals(namespaceURI)) {
-                String prefix = qname.getPrefix();
-                if (!"".equals(prefix)) {
-                    ns = declareNamespace(namespaceURI, prefix);
-                } else {
-                    ns =
-                            declareNamespace(namespaceURI,
-                                    getNextNamespacePrefix());
-                }
-            }
-            if (ns != null) {
-                this.setNamespace(ns);
-            }
-        }
-    }
-
-    /**
-     * Method handleNamespace
-     *
-     * @param ns
-     * @return namespace
-     */
-    private OMNamespace handleNamespace(OMNamespace ns) {
-        OMNamespace namespace = findNamespace(ns.getName(),
-                ns.getPrefix());
-        if (namespace == null) {
-            namespace = declareNamespace(ns);
-        }
-        return namespace;
-    }
-
-    /**
-     * This will add child to the element. One can decide whether he append the child or he adds to the
-     * front of the children list
-     *
-     * @param child
-     */
-    public void addChild(OMNode child) {
-        addChild((OMNodeImpl) child);
-    }
-
-    /**
-     * This will search for children with a given QName and will return an iterator to traverse through
-     * the OMNodes.
-     * This QName can contain any combination of prefix, localname and URI
-     *
-     * @param elementQName
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public Iterator getChildrenWithName(QName elementQName) throws OMException {
-        return new OMChildrenQNameIterator(getFirstChild(),
-                elementQName);
-    }
-
-    /**
-     * Method getFirstChildWithName
-     *
-     * @param elementQName
-     * @return
-     * @throws OMException
-     */
-    public OMElement getFirstChildWithName(QName elementQName) throws OMException {
-        OMChildrenQNameIterator omChildrenQNameIterator =
-                new OMChildrenQNameIterator(getFirstChild(),
-                        elementQName);
-        OMNode omNode = null;
-        if (omChildrenQNameIterator.hasNext()) {
-            omNode = (OMNode) omChildrenQNameIterator.next();
-        }
-
-        return ((omNode != null) && (OMNode.ELEMENT_NODE == omNode.getType())) ?
-                (OMElement) omNode : null;
-
-    }
-
-    /**
-     * Method addChild
-     *
-     * @param child
-     */
-    private void addChild(OMNodeImpl child) {
-        if (firstChild == null) {
-            firstChild = child;
-            child.setPreviousSibling(null);
-        } else {
-            child.setPreviousSibling(lastChild);
-            lastChild.setNextSibling(child);
-        }
-        child.setNextSibling(null);
-        child.setParent(this);
-        lastChild = child;
-
-    }
-
-    /**
-     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
-     *
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMNode getNextSibling() throws OMException {
-        while (!done) {
-            builder.next();
-        }
-        return super.getNextSibling();
-    }
-
-    /**
-     * This returns a collection of this element.
-     * Children can be of types OMElement, OMText.
-     *
-     * @return children
-     */
-    public Iterator getChildren() {
-        return new OMChildrenIterator(getFirstChild());
-    }
-
-    /**
-     * THis will create a namespace in the current element scope
-     *
-     * @param uri
-     * @param prefix
-     * @return namespace
-     */
-    public OMNamespace declareNamespace(String uri, String prefix) {
-        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
-        return declareNamespace(ns);
-    }
-
-
-    /**
-     * @param namespace
-     * @return namespace
-     */
-    public OMNamespace declareNamespace(OMNamespace namespace) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put(namespace.getPrefix(), namespace);
-        return namespace;
-    }
-
-    /**
-     * This will find a namespace with the given uri and prefix, in the scope of the docuemnt.
-     * This will start to find from the current element and goes up in the hiararchy until this finds one.
-     * If none is found, return null
-     *
-     * @param uri
-     * @param prefix
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMNamespace findNamespace(String uri, String prefix)
-            throws OMException {
-
-        // check in the current element
-        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
-        if (namespace != null) {
-            return namespace;
-        }
-
-        // go up to check with ancestors
-        if (parent != null) {
-            //For the OMDocument there won't be any explicit namespace
-            //declarations, so going up the parent chain till the document
-            //element should be enough.
-            if (parent instanceof OMElement) {
-                return ((OMElementImpl) parent).findNamespace(uri, prefix);
-            }
-        }
-        return null;
-    }
-
-    /**
-     * This will ckeck for the namespace <B>only</B> in the current Element
-     * This can also be used to retrieve the prefix of a known namespace URI
-     *
-     * @param uri
-     * @param prefix
-     * @return
-     * @throws OMException
-     */
-    private OMNamespace findDeclaredNamespace(String uri, String prefix)
-            throws OMException {
-        if (namespaces == null) {
-            return null;
-        }
-        if (prefix == null || "".equals(prefix)) {
-            Iterator namespaceListIterator = namespaces.values().iterator();
-            while (namespaceListIterator.hasNext()) {
-                OMNamespace omNamespace =
-                        (OMNamespace) namespaceListIterator.next();
-                if (omNamespace.getName().equals(uri)) {
-                    return omNamespace;
-                }
-            }
-            return null;
-        } else {
-            return (OMNamespace) namespaces.get(prefix);
-        }
-    }
-
-    /**
-     * Method getAllDeclaredNamespaces
-     *
-     * @return iterator
-     */
-    public Iterator getAllDeclaredNamespaces() {
-        if (namespaces == null) {
-            return null;
-        }
-        return namespaces.values().iterator();
-    }
-
-    /**
-     * This will help to search for an attribute with a given QName within this Element
-     *
-     * @param qname
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMAttribute getFirstAttribute(QName qname) throws OMException {
-        if (attributes == null) {
-            return null;
-        }
-        return (OMAttribute) attributes.get(qname);
-    }
-
-    /**
-     * This will return a List of OMAttributes
-     *
-     * @return iterator
-     */
-    public Iterator getAttributes() {
-        if (attributes == null) {
-            return new EmptyIterator();
-        }
-        return attributes.values().iterator();
-    }
-
-    public Iterator getAttributes(QName qname) {
-        //TODO: would there be multiple attributes with the same QName
-        return null;
-    }
-
-    /**
-     * This will insert attribute to this element. Implementor can decide as to insert this
-     * in the front or at the end of set of attributes
-     *
-     * @param attr
-     * @return attribute
-     */
-    public OMAttribute addAttribute(OMAttribute attr) {
-        if (attributes == null) {
-            this.attributes = new HashMap(5);
-        }
-        attributes.put(attr.getQName(), attr);
-        return attr;
-    }
-
-    /**
-     * Method removeAttribute
-     *
-     * @param attr
-     */
-    public void removeAttribute(OMAttribute attr) {
-        if (attributes != null) {
-            attributes.remove(attr.getQName());
-        }
-    }
-
-    /**
-     * Method addAttribute
-     *
-     * @param attributeName
-     * @param value
-     * @param ns
-     * @return attribute
-     */
-    public OMAttribute addAttribute(String attributeName, String value,
-                                    OMNamespace ns) {
-        OMNamespace namespace;
-        if (ns != null) {
-            namespace = findNamespace(ns.getName(), ns.getPrefix());
-            if (namespace == null) {
-                throw new OMException("Given OMNamespace(" + ns.getName() +
-                        ns.getPrefix()
-                        + ") for "
-                        +
-                        "this attribute is not declared in the scope of this element. First declare the namespace"
-                        + " and then use it with the attribute");
-            }
-        }
-        return addAttribute(new OMAttributeImpl(attributeName, ns, value));
-    }
-
-    /**
-     * Method setBuilder
-     *
-     * @param wrapper
-     */
-    public void setBuilder(OMXMLParserWrapper wrapper) {
-        this.builder = wrapper;
-    }
-
-    /**
-     * Method getBuilder
-     *
-     * @return builder
-     */
-    public OMXMLParserWrapper getBuilder() {
-        return builder;
-    }
-
-    /**
-     * This will force the parser to proceed, if parser has not yet finished with the XML input
-     */
-    public void buildNext() {
-        builder.next();
-    }
-
-    /**
-     * Method getFirstChild
-     *
-     * @return child
-     */
-    public OMNode getFirstChild() {
-        while ((firstChild == null) && !done) {
-            buildNext();
-        }
-        return firstChild;
-    }
-
-    /**
-     * Method setFirstChild
-     *
-     * @param firstChild
-     */
-    public void setFirstChild(OMNode firstChild) {
-        this.firstChild = firstChild;
-    }
-
-    /**
-     * This will remove this information item and its children, from the model completely
-     *
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMNode detach() throws OMException {
-        if (!done) {
-            build();
-        } else {
-            super.detach();
-        }
-        return this;
-    }
-
-    /**
-     * Method isComplete
-     *
-     * @return boolean
-     */
-    public boolean isComplete() {
-        return done;
-    }
-
-    /**
-     * This is to get the type of node, as this is the super class of all the nodes
-     *
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public int getType() throws OMException {
-        return OMNode.ELEMENT_NODE;
-    }
-
-    /**
-     * getXMLStreamReader
-     *
-     * @return
-     * @see org.apache.axis2.om.OMElement#getXMLStreamReader()
-     */
-    public XMLStreamReader getXMLStreamReader() {
-        return getXMLStreamReader(true);
-    }
-
-    /**
-     * getXMLStreamReaderWithoutCaching
-     *
-     * @return
-     * @see org.apache.axis2.om.OMElement#getXMLStreamReaderWithoutCaching()
-     */
-    public XMLStreamReader getXMLStreamReaderWithoutCaching() {
-        return getXMLStreamReader(false);
-    }
-
-    /**
-     * getXMLStreamReader
-     *
-     * @param cache
-     * @return reader
-     */
-    private XMLStreamReader getXMLStreamReader(boolean cache) {
-        if ((builder == null) && !cache) {
-            throw new UnsupportedOperationException(
-                    "This element was not created in a manner to be switched");
-        }
-        return new OMStAXWrapper(builder, this, cache);
-    }
-
-    /**
-     * Sets the text of the given element.
-     * caution - This method will wipe out all the text elements (and hence any
-     * moxed content) before setting the text
-     *
-     * @param text
-     */
-    public void setText(String text) {
-
-        OMNode child = this.getFirstChild();
-        while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
-                child.detach();
-            }
-            child = child.getNextSibling();
-        }
-
-        this.addChild(OMAbstractFactory.getOMFactory().createText(this, text));
-    }
-
-    /**
-     * select all the text children and concat them to a single string
-     *
-     * @return text
-     */
-    public String getText() {
-        String childText = "";
-        OMNode child = this.getFirstChild();
-        OMText textNode;
-
-        while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
-                textNode = (OMText) child;
-                if (textNode.getText() != null &&
-                        !"".equals(textNode.getText().trim())) {
-                    childText += textNode.getText().trim();
-                }
-            }
-            child = child.getNextSibling();
-        }
-
-        return childText;
-    }
-
-    /**
-     * Method serializeWithCache
-     *
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    public void serializeWithCache(OMOutput omOutput) throws XMLStreamException {
-        serialize(omOutput, true);
-    }
-
-    ///////////////////////////////////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////////////////////////////////
-
-    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);
-            }
-
-            //serilize siblings
-            if (this.nextSibling != null) {
-                nextSibling.serialize(omOutput);
-            } else if (this.parent != null) {
-                if (!this.parent.isComplete()) {
-                    builder.setCache(cache);
-                    builder.next();
-                }
-            }
-        } else {
-            //Cached
-            OMSerializerUtil.serializeNormal(this, omOutput, cache);
-            // serialize the siblings
-            OMNode nextSibling = this.getNextSibling();
-            if (nextSibling != null) {
-                nextSibling.serializeWithCache(omOutput);
-            }
-        }
-    }
-
-    ////////////////////////////////////////////////////////////////////////////////////////////////
-    ////////////////////////////////////////////////////////////////////////////////////////////////
-
-    /**
-     * This was requested during the second Axis2 summit. When one call this method, this will
-     * serialize without building the object structure in the memory. Misuse of this method will
-     * cause loss of data.So its advised to use populateYourSelf() method, before this,
-     * if you want to preserve data in the stream.
-     *
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    public void serialize(OMOutput omOutput) throws XMLStreamException {
-        this.serialize(omOutput, false);
-    }
-
-
-    /**
-     * Method getNextNamespacePrefix
-     *
-     * @return prefix
-     */
-    private String getNextNamespacePrefix() {
-        return "ns" + ++noPrefixNamespaceCounter;
-    }
-
-    /**
-     * Get first element
-     *
-     * @return element
-     */
-    public OMElement getFirstElement() {
-        OMNode node = getFirstChild();
-        while (node != null) {
-            if (node.getType() == OMNode.ELEMENT_NODE) {
-                return (OMElement) node;
-            } else {
-                node = node.getNextSibling();
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Method getLocalName
-     *
-     * @return local name
-     */
-    public String getLocalName() {
-        return localName;
-    }
-
-    /**
-     * Method setLocalName
-     *
-     * @param localName
-     */
-    public void setLocalName(String localName) {
-        this.localName = localName;
-    }
-
-    /**
-     * Method getNamespace
-     *
-     * @return
-     * @throws OMException
-     */
-    public OMNamespace getNamespace() throws OMException {
-        return ns;
-    }
-
-
-    /**
-     * Method setNamespace
-     *
-     * @param namespace
-     */
-    public void setNamespace(OMNamespace namespace) {
-        if (ns != null) {
-            OMNamespace ns = findNamespace(namespace.getName(),
-                    namespace.getPrefix());
-            if (ns == null) {
-                declareNamespace(namespace);
-            }
-        }
-        this.ns = namespace;
-    }
-
-    /**
-     * Method getQName
-     *
-     * @return qname
-     */
-    public QName getQName() {
-        QName qName;
-        if (ns != null) {
-            if (ns.getPrefix() != null) {
-                qName = new QName(ns.getName(), localName, ns.getPrefix());
-            } else {
-                qName = new QName(ns.getName(), localName);
-            }
-        } else {
-            qName = new QName(localName);
-        }
-        return qName;
-    }
-
-    /**
-     * Discard implementation
-     *
-     * @throws OMException
-     */
-    public void discard() throws OMException {
-        if (done) {
-            this.detach();
-        } else {
-            builder.discard(this);
-        }
-    }
-}
+/*
+* 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.om.OMAbstractFactory;
+import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMConstants;
+import org.apache.axis2.om.OMContainer;
+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.serialize.StreamWriterToContentHandlerConverter;
+import org.apache.axis2.om.impl.llom.traverse.OMChildrenIterator;
+import org.apache.axis2.om.impl.llom.traverse.OMChildrenQNameIterator;
+import org.apache.axis2.om.impl.llom.util.EmptyIterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * Class OMElementImpl
+ */
+public class OMElementImpl extends OMNodeImpl
+        implements OMElement, OMConstants {
+    /**
+     * Field ns
+     */
+    protected OMNamespace ns;
+
+    /**
+     * Field localName
+     */
+    protected String localName;
+    /**
+     * Field firstChild
+     */
+    protected OMNode firstChild;
+
+    /**
+     * Field namespaces
+     */
+    protected HashMap namespaces = null;
+
+    /**
+     * Field attributes
+     */
+    protected HashMap attributes = null;
+
+    /**
+     * Field noPrefixNamespaceCounter
+     */
+    protected int noPrefixNamespaceCounter = 0;
+    private OMNode lastChild;
+
+    /**
+     * Constructor OMElementImpl
+     *
+     * @param localName
+     * @param ns
+     * @param parent
+     * @param builder
+     */
+    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent,
+                         OMXMLParserWrapper builder) {
+        super(parent);
+        this.localName = localName;
+        if (ns != null) {
+            setNamespace(handleNamespace(ns));
+        }
+        this.builder = builder;
+        firstChild = null;
+    }
+
+    /**
+     * @param parent
+     * @param parent
+     */
+    protected OMElementImpl(OMContainer parent) {
+        super(parent);
+        this.done = true;
+    }
+
+    /**
+     * Constructor OMElementImpl
+     *
+     * @param localName
+     * @param ns
+     */
+    public OMElementImpl(String localName, OMNamespace ns) {
+        super(null);
+        this.localName = localName;
+        this.done = true;
+        if (ns != null) {
+            setNamespace(handleNamespace(ns));
+        }
+    }
+
+    /**
+     * Constructor OMElementImpl
+     * @param localName
+     * @param ns
+     * @param parent
+     */
+    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent) {
+        super(parent);
+        this.localName = localName;
+        this.done = true;
+        if (ns != null) {
+            setNamespace(handleNamespace(ns));
+        }
+    }
+
+    /**
+     * Here it is assumed that this QName passed, at least contains the localName for this element
+     *
+     * @param qname
+     * @param parent
+     * @throws OMException
+     */
+    public OMElementImpl(QName qname, OMContainer parent) throws OMException {
+        super(parent);
+        this.localName = qname.getLocalPart();
+        this.done = true;
+        handleNamespace(qname);
+    }
+
+    /**
+     * Method handleNamespace
+     *
+     * @param qname
+     */
+    private void handleNamespace(QName qname) {
+        OMNamespace ns;
+
+        // first try to find a namespace from the scope
+        String namespaceURI = qname.getNamespaceURI();
+        if (!"".equals(namespaceURI)) {
+            ns = findNamespace(qname.getNamespaceURI(),
+                    qname.getPrefix());
+
+            /**
+             * What is left now is
+             *  1. nsURI = null & parent != null, but ns = null
+             *  2. nsURI != null, (parent doesn't have an ns with given URI), but ns = null
+             */
+            if ((ns == null) && !"".equals(namespaceURI)) {
+                String prefix = qname.getPrefix();
+                if (!"".equals(prefix)) {
+                    ns = declareNamespace(namespaceURI, prefix);
+                } else {
+                    ns =
+                            declareNamespace(namespaceURI,
+                                    getNextNamespacePrefix());
+                }
+            }
+            if (ns != null) {
+                this.setNamespace(ns);
+            }
+        }
+    }
+
+    /**
+     * Method handleNamespace
+     *
+     * @param ns
+     * @return namespace
+     */
+    private OMNamespace handleNamespace(OMNamespace ns) {
+        OMNamespace namespace = findNamespace(ns.getName(),
+                ns.getPrefix());
+        if (namespace == null) {
+            namespace = declareNamespace(ns);
+        }
+        return namespace;
+    }
+
+    /**
+     * This will add child to the element. One can decide whether he append the child or he adds to the
+     * front of the children list
+     *
+     * @param child
+     */
+    public void addChild(OMNode child) {
+        addChild((OMNodeImpl) child);
+    }
+
+    /**
+     * This will search for children with a given QName and will return an iterator to traverse through
+     * the OMNodes.
+     * This QName can contain any combination of prefix, localname and URI
+     *
+     * @param elementQName
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public Iterator getChildrenWithName(QName elementQName) throws OMException {
+        return new OMChildrenQNameIterator(getFirstChild(),
+                elementQName);
+    }
+
+    /**
+     * Method getFirstChildWithName
+     *
+     * @param elementQName
+     * @return
+     * @throws OMException
+     */
+    public OMElement getFirstChildWithName(QName elementQName) throws OMException {
+        OMChildrenQNameIterator omChildrenQNameIterator =
+                new OMChildrenQNameIterator(getFirstChild(),
+                        elementQName);
+        OMNode omNode = null;
+        if (omChildrenQNameIterator.hasNext()) {
+            omNode = (OMNode) omChildrenQNameIterator.next();
+        }
+
+        return ((omNode != null) && (OMNode.ELEMENT_NODE == omNode.getType())) ?
+                (OMElement) omNode : null;
+
+    }
+
+    /**
+     * Method addChild
+     *
+     * @param child
+     */
+    private void addChild(OMNodeImpl child) {
+        if (firstChild == null) {
+            firstChild = child;
+            child.setPreviousSibling(null);
+        } else {
+            child.setPreviousSibling(lastChild);
+            lastChild.setNextSibling(child);
+        }
+        child.setNextSibling(null);
+        child.setParent(this);
+        lastChild = child;
+
+    }
+
+    /**
+     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+     *
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMNode getNextSibling() throws OMException {
+        while (!done) {
+            builder.next();
+        }
+        return super.getNextSibling();
+    }
+
+    /**
+     * This returns a collection of this element.
+     * Children can be of types OMElement, OMText.
+     *
+     * @return children
+     */
+    public Iterator getChildren() {
+        return new OMChildrenIterator(getFirstChild());
+    }
+
+    /**
+     * THis will create a namespace in the current element scope
+     *
+     * @param uri
+     * @param prefix
+     * @return namespace
+     */
+    public OMNamespace declareNamespace(String uri, String prefix) {
+        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
+        return declareNamespace(ns);
+    }
+
+
+    /**
+     * @param namespace
+     * @return namespace
+     */
+    public OMNamespace declareNamespace(OMNamespace namespace) {
+        if (namespaces == null) {
+            this.namespaces = new HashMap(5);
+        }
+        namespaces.put(namespace.getPrefix(), namespace);
+        return namespace;
+    }
+
+    /**
+     * This will find a namespace with the given uri and prefix, in the scope of the docuemnt.
+     * This will start to find from the current element and goes up in the hiararchy until this finds one.
+     * If none is found, return null
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMNamespace findNamespace(String uri, String prefix)
+            throws OMException {
+
+        // check in the current element
+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
+        if (namespace != null) {
+            return namespace;
+        }
+
+        // go up to check with ancestors
+        if (parent != null) {
+            //For the OMDocument there won't be any explicit namespace
+            //declarations, so going up the parent chain till the document
+            //element should be enough.
+            if (parent instanceof OMElement) {
+                return ((OMElementImpl) parent).findNamespace(uri, prefix);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * This will ckeck for the namespace <B>only</B> in the current Element
+     * This can also be used to retrieve the prefix of a known namespace URI
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     * @throws OMException
+     */
+    private OMNamespace findDeclaredNamespace(String uri, String prefix)
+            throws OMException {
+        if (namespaces == null) {
+            return null;
+        }
+        if (prefix == null || "".equals(prefix)) {
+            Iterator namespaceListIterator = namespaces.values().iterator();
+            while (namespaceListIterator.hasNext()) {
+                OMNamespace omNamespace =
+                        (OMNamespace) namespaceListIterator.next();
+                if (omNamespace.getName().equals(uri)) {
+                    return omNamespace;
+                }
+            }
+            return null;
+        } else {
+            return (OMNamespace) namespaces.get(prefix);
+        }
+    }
+
+    /**
+     * Method getAllDeclaredNamespaces
+     *
+     * @return iterator
+     */
+    public Iterator getAllDeclaredNamespaces() {
+        if (namespaces == null) {
+            return null;
+        }
+        return namespaces.values().iterator();
+    }
+
+    /**
+     * This will help to search for an attribute with a given QName within this Element
+     *
+     * @param qname
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMAttribute getFirstAttribute(QName qname) throws OMException {
+        if (attributes == null) {
+            return null;
+        }
+        return (OMAttribute) attributes.get(qname);
+    }
+
+    /**
+     * This will return a List of OMAttributes
+     *
+     * @return iterator
+     */
+    public Iterator getAttributes() {
+        if (attributes == null) {
+            return new EmptyIterator();
+        }
+        return attributes.values().iterator();
+    }
+
+    public Iterator getAttributes(QName qname) {
+        //TODO: would there be multiple attributes with the same QName
+        return null;
+    }
+
+    /**
+     * This will insert attribute to this element. Implementor can decide as to insert this
+     * in the front or at the end of set of attributes
+     *
+     * @param attr
+     * @return attribute
+     */
+    public OMAttribute addAttribute(OMAttribute attr) {
+        if (attributes == null) {
+            this.attributes = new HashMap(5);
+        }
+        attributes.put(attr.getQName(), attr);
+        return attr;
+    }
+
+    /**
+     * Method removeAttribute
+     *
+     * @param attr
+     */
+    public void removeAttribute(OMAttribute attr) {
+        if (attributes != null) {
+            attributes.remove(attr.getQName());
+        }
+    }
+
+    /**
+     * Method addAttribute
+     *
+     * @param attributeName
+     * @param value
+     * @param ns
+     * @return attribute
+     */
+    public OMAttribute addAttribute(String attributeName, String value,
+                                    OMNamespace ns) {
+        OMNamespace namespace;
+        if (ns != null) {
+            namespace = findNamespace(ns.getName(), ns.getPrefix());
+            if (namespace == null) {
+                throw new OMException("Given OMNamespace(" + ns.getName() +
+                        ns.getPrefix()
+                        + ") for "
+                        +
+                        "this attribute is not declared in the scope of this element. First declare the namespace"
+                        + " and then use it with the attribute");
+            }
+        }
+        return addAttribute(new OMAttributeImpl(attributeName, ns, value));
+    }
+
+    /**
+     * Method setBuilder
+     *
+     * @param wrapper
+     */
+    public void setBuilder(OMXMLParserWrapper wrapper) {
+        this.builder = wrapper;
+    }
+
+    /**
+     * Method getBuilder
+     *
+     * @return builder
+     */
+    public OMXMLParserWrapper getBuilder() {
+        return builder;
+    }
+
+    /**
+     * This will force the parser to proceed, if parser has not yet finished with the XML input
+     */
+    public void buildNext() {
+        builder.next();
+    }
+
+    /**
+     * Method getFirstChild
+     *
+     * @return child
+     */
+    public OMNode getFirstChild() {
+        while ((firstChild == null) && !done) {
+            buildNext();
+        }
+        return firstChild;
+    }
+
+    /**
+     * Method setFirstChild
+     *
+     * @param firstChild
+     */
+    public void setFirstChild(OMNode firstChild) {
+        this.firstChild = firstChild;
+    }
+
+    /**
+     * This will remove this information item and its children, from the model completely
+     *
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMNode detach() throws OMException {
+        if (!done) {
+            build();
+        } else {
+            super.detach();
+        }
+        return this;
+    }
+
+    /**
+     * Method isComplete
+     *
+     * @return boolean
+     */
+    public boolean isComplete() {
+        return done;
+    }
+
+    /**
+     * This is to get the type of node, as this is the super class of all the nodes
+     *
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public int getType() throws OMException {
+        return OMNode.ELEMENT_NODE;
+    }
+
+    /**
+     * getXMLStreamReader
+     *
+     * @return
+     * @see org.apache.axis2.om.OMElement#getXMLStreamReader()
+     */
+    public XMLStreamReader getXMLStreamReader() {
+        return getXMLStreamReader(true);
+    }
+
+    /**
+     * getXMLStreamReaderWithoutCaching
+     *
+     * @return
+     * @see org.apache.axis2.om.OMElement#getXMLStreamReaderWithoutCaching()
+     */
+    public XMLStreamReader getXMLStreamReaderWithoutCaching() {
+        return getXMLStreamReader(false);
+    }
+
+    /**
+     * getXMLStreamReader
+     *
+     * @param cache
+     * @return reader
+     */
+    private XMLStreamReader getXMLStreamReader(boolean cache) {
+        if ((builder == null) && !cache) {
+            throw new UnsupportedOperationException(
+                    "This element was not created in a manner to be switched");
+        }
+        return new OMStAXWrapper(builder, this, cache);
+    }
+
+    /**
+     * Sets the text of the given element.
+     * caution - This method will wipe out all the text elements (and hence any
+     * moxed content) before setting the text
+     *
+     * @param text
+     */
+    public void setText(String text) {
+
+        OMNode child = this.getFirstChild();
+        while (child != null) {
+            if (child.getType() == OMNode.TEXT_NODE) {
+                child.detach();
+            }
+            child = child.getNextSibling();
+        }
+
+        this.addChild(OMAbstractFactory.getOMFactory().createText(this, text));
+    }
+
+    /**
+     * select all the text children and concat them to a single string
+     *
+     * @return text
+     */
+    public String getText() {
+        String childText = "";
+        OMNode child = this.getFirstChild();
+        OMText textNode;
+
+        while (child != null) {
+            if (child.getType() == OMNode.TEXT_NODE) {
+                textNode = (OMText) child;
+                if (textNode.getText() != null &&
+                        !"".equals(textNode.getText().trim())) {
+                    childText += textNode.getText().trim();
+                }
+            }
+            child = child.getNextSibling();
+        }
+
+        return childText;
+    }
+
+    /**
+     * Method serializeWithCache
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    public void serializeWithCache(OMOutputImpl omOutput) throws XMLStreamException {
+        serialize(omOutput, true);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////////////////
+
+    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);
+            }
+
+            //serilize siblings
+            if (this.nextSibling != null) {
+                nextSibling.serialize(omOutput);
+            } else if (this.parent != null) {
+                if (!this.parent.isComplete()) {
+                    builder.setCache(cache);
+                    builder.next();
+                }
+            }
+        } else {
+            //Cached
+            OMSerializerUtil.serializeNormal(this, omOutput, cache);
+            // serialize the siblings
+            OMNode nextSibling = this.getNextSibling();
+            if (nextSibling != null) {
+                nextSibling.serializeWithCache(omOutput);
+            }
+        }
+    }
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////
+    ////////////////////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * This was requested during the second Axis2 summit. When one call this method, this will
+     * serialize without building the object structure in the memory. Misuse of this method will
+     * cause loss of data.So its advised to use populateYourSelf() method, before this,
+     * if you want to preserve data in the stream.
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        this.serialize(omOutput, false);
+    }
+
+
+    /**
+     * Method getNextNamespacePrefix
+     *
+     * @return prefix
+     */
+    private String getNextNamespacePrefix() {
+        return "ns" + ++noPrefixNamespaceCounter;
+    }
+
+    /**
+     * Get first element
+     *
+     * @return element
+     */
+    public OMElement getFirstElement() {
+        OMNode node = getFirstChild();
+        while (node != null) {
+            if (node.getType() == OMNode.ELEMENT_NODE) {
+                return (OMElement) node;
+            } else {
+                node = node.getNextSibling();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Method getLocalName
+     *
+     * @return local name
+     */
+    public String getLocalName() {
+        return localName;
+    }
+
+    /**
+     * Method setLocalName
+     *
+     * @param localName
+     */
+    public void setLocalName(String localName) {
+        this.localName = localName;
+    }
+
+    /**
+     * Method getNamespace
+     *
+     * @return
+     * @throws OMException
+     */
+    public OMNamespace getNamespace() throws OMException {
+        return ns;
+    }
+
+
+    /**
+     * Method setNamespace
+     *
+     * @param namespace
+     */
+    public void setNamespace(OMNamespace namespace) {
+        if (ns != null) {
+            OMNamespace ns = findNamespace(namespace.getName(),
+                    namespace.getPrefix());
+            if (ns == null) {
+                declareNamespace(namespace);
+            }
+        }
+        this.ns = namespace;
+    }
+
+    /**
+     * Method getQName
+     *
+     * @return qname
+     */
+    public QName getQName() {
+        QName qName;
+        if (ns != null) {
+            if (ns.getPrefix() != null) {
+                qName = new QName(ns.getName(), localName, ns.getPrefix());
+            } else {
+                qName = new QName(ns.getName(), localName);
+            }
+        } else {
+            qName = new QName(localName);
+        }
+        return qName;
+    }
+
+    /**
+     * Discard implementation
+     *
+     * @throws OMException
+     */
+    public void discard() throws OMException {
+        if (done) {
+            this.detach();
+        } else {
+            builder.discard(this);
+        }
+    }
+}

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMNodeImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMNodeImpl.java Wed Jul 13 17:30:55 2005
@@ -1,285 +1,339 @@
-/*
-* 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.om.OMContainer;
-import org.apache.axis2.om.OMException;
-import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.OMXMLParserWrapper;
-
-/**
- * Class OMNodeImpl
- */
-public abstract class OMNodeImpl implements OMNode {
-    /**
-     * Field parent
-     */
-    protected OMContainer parent;
-
-    /**
-     * Field nextSibling
-     */
-    protected OMNodeImpl nextSibling;
-
-    /**
-     * Field previousSibling
-     */
-    protected OMNodeImpl previousSibling;
-    /**
-     * Field builder
-     */
-    protected OMXMLParserWrapper builder;
-
-    /**
-     * Field done
-     */
-    protected boolean done = false;
-
-    /**
-     * Field nodeType
-     */
-    protected int nodeType;
-
-    /**
-     * Constructor OMNodeImpl
-     */
-    public OMNodeImpl() {
-    }
-
-    /**
-     * For a node to exist there must be a parent
-     *
-     * @param parent
-     */
-    public OMNodeImpl(OMContainer parent) {
-        if ((parent != null)) {
-            this.parent = parent;
-            parent.addChild(this);
-        }
-    }
-
-    /**
-     * This method should return the immediate parent of the node.
-     * Parent is always an Element
-     *
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMContainer getParent() throws OMException {
-        return parent;
-    }
-
-    /**
-     * Method setParent
-     *
-     * @param element
-     */
-    public void setParent(OMContainer element) {
-
-        if ((this.parent) == element) {
-            return;
-        }
-
-        //If we are asked to assign a new parent in place 
-        //of an existing one. We should detach this node
-        //from the aegis of previous parent.
-        if (this.parent != null) {
-            this.detach();
-        }
-        this.parent = element;
-    }
-
-    /**
-     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
-     *
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMNode getNextSibling() throws OMException {
-        if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {
-            parent.buildNext();
-        }
-        return nextSibling;
-    }
-
-    /**
-     * Method setNextSibling
-     *
-     * @param node
-     */
-    public void setNextSibling(OMNode node) {
-        this.nextSibling = (OMNodeImpl) node;
-    }
-
-
-    /**
-     * this will indicate whether parser has parsed this information item completely or not.
-     * If somethings info are not available in the item, one has to check this attribute to make sure that, this
-     * item has been parsed completely or not.
-     *
-     * @return
-     */
-    public boolean isComplete() {
-        return done;
-    }
-
-    /**
-     * Method setComplete
-     *
-     * @param state
-     */
-    public void setComplete(boolean state) {
-        this.done = state;
-    }
-
-    /**
-     * This will remove this information item and its children, from the model completely
-     *
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public OMNode detach() throws OMException {
-        if (parent == null) {
-            throw new OMException(
-                    "Elements that doesn't have a parent can not be detached");
-        }
-        OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling();
-        if (previousSibling == null) {
-            parent.setFirstChild(nextSibling);
-        } else {
-            getPreviousSibling().setNextSibling(nextSibling);
-        }
-        if (nextSibling != null) {
-            nextSibling.setPreviousSibling(getPreviousSibling());
-        }
-        this.parent = null;
-        return this;
-    }
-
-    /**
-     * This will insert a sibling just after the current information item.
-     *
-     * @param sibling
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public void insertSiblingAfter(OMNode sibling) throws OMException {
-        if (parent == null) {
-            throw new OMException();
-        }
-        sibling.setParent(parent);
-        if (sibling instanceof OMNodeImpl) {
-            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
-            if (nextSibling == null) {
-                getNextSibling();
-            }
-            siblingImpl.setPreviousSibling(this);
-            if (nextSibling != null) {
-                nextSibling.setPreviousSibling(sibling);
-            }
-            sibling.setNextSibling(nextSibling);
-            nextSibling = siblingImpl;
-        }
-    }
-
-    /**
-     * This will insert a sibling just before the current information item
-     *
-     * @param sibling
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public void insertSiblingBefore(OMNode sibling) throws OMException {
-        if (parent == null) {
-            throw new OMException();
-        }
-        sibling.setParent(parent);
-        if (sibling instanceof OMNodeImpl) {
-            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
-            siblingImpl.setPreviousSibling(previousSibling);
-            siblingImpl.setNextSibling(this);
-            if (previousSibling == null) {
-                parent.setFirstChild(siblingImpl);
-            } else {
-                previousSibling.setNextSibling(siblingImpl);
-            }
-            previousSibling = siblingImpl;
-        }
-    }
-
-    /**
-     * This is to get the type of node, as this is the super class of all the nodes
-     *
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public int getType() throws OMException {
-        return nodeType;
-    }
-
-    /**
-     * Method setType
-     *
-     * @param nodeType
-     * @throws OMException
-     */
-    public void setType(int nodeType) throws OMException {
-        this.nodeType = nodeType;
-    }
-
-    /**
-     * Method getPreviousSibling
-     *
-     * @return
-     */
-    public OMNode getPreviousSibling() {
-        return previousSibling;
-    }
-
-    /**
-     * Method setPreviousSibling
-     *
-     * @param previousSibling
-     */
-    public void setPreviousSibling(OMNode previousSibling) {
-        this.previousSibling = (OMNodeImpl) previousSibling;
-    }
-
-
-    /**
-     * This will completely parse this node and build the object structure in the memory.
-     * However a programmatically created node will have done set to true by default and will cause
-     * populateyourself not to work properly!
-     *
-     * @throws OMException
-     */
-    public void build() throws OMException {
-        while (!done) {
-            builder.next();
-        }
-    }
-
-
-}
+/*
+* 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.om.OMContainer;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.OMOutputImpl;
+
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * Class OMNodeImpl
+ */
+public abstract class OMNodeImpl implements OMNode {
+    /**
+     * Field parent
+     */
+    protected OMContainer parent;
+
+    /**
+     * Field nextSibling
+     */
+    protected OMNodeImpl nextSibling;
+
+    /**
+     * Field previousSibling
+     */
+    protected OMNodeImpl previousSibling;
+    /**
+     * Field builder
+     */
+    protected OMXMLParserWrapper builder;
+
+    /**
+     * Field done
+     */
+    protected boolean done = false;
+
+    /**
+     * Field nodeType
+     */
+    protected int nodeType;
+
+    /**
+     * Constructor OMNodeImpl
+     */
+    public OMNodeImpl() {
+    }
+
+    /**
+     * For a node to exist there must be a parent
+     *
+     * @param parent
+     */
+    public OMNodeImpl(OMContainer parent) {
+        if ((parent != null)) {
+            this.parent = parent;
+            parent.addChild(this);
+        }
+    }
+
+    /**
+     * This method should return the immediate parent of the node.
+     * Parent is always an Element
+     *
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMContainer getParent() throws OMException {
+        return parent;
+    }
+
+    /**
+     * Method setParent
+     *
+     * @param element
+     */
+    public void setParent(OMContainer element) {
+
+        if ((this.parent) == element) {
+            return;
+        }
+
+        //If we are asked to assign a new parent in place 
+        //of an existing one. We should detach this node
+        //from the aegis of previous parent.
+        if (this.parent != null) {
+            this.detach();
+        }
+        this.parent = element;
+    }
+
+    /**
+     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+     *
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMNode getNextSibling() throws OMException {
+        if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {
+            parent.buildNext();
+        }
+        return nextSibling;
+    }
+
+    /**
+     * Method setNextSibling
+     *
+     * @param node
+     */
+    public void setNextSibling(OMNode node) {
+        this.nextSibling = (OMNodeImpl) node;
+    }
+
+
+    /**
+     * this will indicate whether parser has parsed this information item completely or not.
+     * If somethings info are not available in the item, one has to check this attribute to make sure that, this
+     * item has been parsed completely or not.
+     *
+     * @return boolean
+     */
+    public boolean isComplete() {
+        return done;
+    }
+
+    /**
+     * Method setComplete
+     *
+     * @param state
+     */
+    public void setComplete(boolean state) {
+        this.done = state;
+    }
+
+    /**
+     * This will remove this information item and its children, from the model completely
+     *
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public OMNode detach() throws OMException {
+        if (parent == null) {
+            throw new OMException(
+                    "Elements that doesn't have a parent can not be detached");
+        }
+        OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling();
+        if (previousSibling == null) {
+            parent.setFirstChild(nextSibling);
+        } else {
+            getPreviousSibling().setNextSibling(nextSibling);
+        }
+        if (nextSibling != null) {
+            nextSibling.setPreviousSibling(getPreviousSibling());
+        }
+        this.parent = null;
+        return this;
+    }
+
+    /**
+     * This will insert a sibling just after the current information item.
+     *
+     * @param sibling
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public void insertSiblingAfter(OMNode sibling) throws OMException {
+        if (parent == null) {
+            throw new OMException();
+        }
+        sibling.setParent(parent);
+        if (sibling instanceof OMNodeImpl) {
+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+            if (nextSibling == null) {
+                getNextSibling();
+            }
+            siblingImpl.setPreviousSibling(this);
+            if (nextSibling != null) {
+                nextSibling.setPreviousSibling(sibling);
+            }
+            sibling.setNextSibling(nextSibling);
+            nextSibling = siblingImpl;
+        }
+    }
+
+    /**
+     * This will insert a sibling just before the current information item
+     *
+     * @param sibling
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public void insertSiblingBefore(OMNode sibling) throws OMException {
+        if (parent == null) {
+            throw new OMException();
+        }
+        sibling.setParent(parent);
+        if (sibling instanceof OMNodeImpl) {
+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+            siblingImpl.setPreviousSibling(previousSibling);
+            siblingImpl.setNextSibling(this);
+            if (previousSibling == null) {
+                parent.setFirstChild(siblingImpl);
+            } else {
+                previousSibling.setNextSibling(siblingImpl);
+            }
+            previousSibling = siblingImpl;
+        }
+    }
+
+    /**
+     * This is to get the type of node, as this is the super class of all the nodes
+     *
+     * @return
+     * @throws org.apache.axis2.om.OMException
+     *
+     * @throws OMException
+     */
+    public int getType() throws OMException {
+        return nodeType;
+    }
+
+    /**
+     * Method setType
+     *
+     * @param nodeType
+     * @throws OMException
+     */
+    public void setType(int nodeType) throws OMException {
+        this.nodeType = nodeType;
+    }
+
+    /**
+     * Method getPreviousSibling
+     *
+     * @return boolean
+     */
+    public OMNode getPreviousSibling() {
+        return previousSibling;
+    }
+
+    /**
+     * Method setPreviousSibling
+     *
+     * @param previousSibling
+     */
+    public void setPreviousSibling(OMNode previousSibling) {
+        this.previousSibling = (OMNodeImpl) previousSibling;
+    }
+
+
+    /**
+     * This will completely parse this node and build the object structure in the memory.
+     * However a programmatically created node will have done set to true by default and will cause
+     * populateyourself not to work properly!
+     *
+     * @throws OMException
+     */
+    public void build() throws OMException {
+        while (!done) {
+            builder.next();
+        }
+    }
+
+
+
+    /**
+     * Serialize the node with caching
+     *
+     * @param xmlWriter
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     * @see #serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl)
+     */
+    public void serializeWithCache(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serializeWithCache(omOutput);
+        omOutput.flush();
+    }
+
+    /**
+     * Serialize the node without caching
+     *
+     * @param xmlWriter
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     * @see #serialize(org.apache.axis2.om.impl.OMOutputImpl)
+     */
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serialize(omOutput);
+        omOutput.flush();
+    }
+
+    /**
+     * Serialize the node with caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl)
+     */
+    public void serializeWithCache(OMOutputImpl omOutput) throws XMLStreamException {
+        throw new RuntimeException("Not implemented yet!");
+    }
+
+    /**
+     * Serialize the node without caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serialize(org.apache.axis2.om.impl.OMOutputImpl)
+     */
+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
+        throw new RuntimeException("Not implemented yet!");
+    }
+}

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java Wed Jul 13 17:30:55 2005
@@ -19,7 +19,6 @@
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.OMOutput;
 import org.apache.axis2.om.OMProcessingInstruction;
 
 import javax.xml.stream.XMLStreamException;
@@ -57,9 +56,9 @@
      *
      * @param omOutput
      * @throws XMLStreamException
-     * @see #serializeWithCache(OMOutput)
+     * @see #serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl)
      */
-    public void serializeWithCache(OMOutput omOutput) throws XMLStreamException {
+    public void serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
         XMLStreamWriter writer = omOutput.getXmlStreamWriter();
         writer.writeCharacters("<?");
         writer.writeCharacters(this.target);
@@ -77,9 +76,9 @@
      *
      * @param omOutput
      * @throws XMLStreamException
-     * @see #serialize(OMOutput)
+     * @see #serialize(org.apache.axis2.om.impl.OMOutputImpl)
      */
-    public void serialize(OMOutput omOutput) throws XMLStreamException {
+    public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
         serializeWithCache(omOutput);
     }
 

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java?rev=216290&r1=216289&r2=216290&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java Wed Jul 13 17:30:55 2005
@@ -1,205 +1,205 @@
-package org.apache.axis2.om.impl.llom;
-
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMNamespace;
-import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.OMOutput;
-import org.apache.axis2.om.impl.llom.serialize.StreamingOMSerializer;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-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.
-*
-*
-*/
-
-public class OMSerializerUtil {
-
-    /**
-     * Method serializeEndpart
-     *
-     * @param writer
-     * @throws javax.xml.stream.XMLStreamException
-     *
-     */
-    public static void serializeEndpart(OMOutput omOutput)
-            throws XMLStreamException {
-        omOutput.getXmlStreamWriter().writeEndElement();
-    }
-
-    /**
-     * Method serializeAttribute
-     *
-     * @param attr
-     * @param writer
-     * @throws XMLStreamException
-     */
-    public static void serializeAttribute(OMAttribute attr, OMOutput omOutput)
-            throws XMLStreamException {
-
-        // first check whether the attribute is associated with a namespace
-        OMNamespace ns = attr.getNamespace();
-        String prefix = null;
-        String namespaceName = null;
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        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 writer
-     * @throws XMLStreamException
-     */
-    public static void serializeNamespace(OMNamespace namespace, OMOutput omOutput)
-            throws XMLStreamException {
-
-        if (namespace != null) {
-            XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-            String uri = namespace.getName();
-            String prefix = writer.getPrefix(uri);
-            String ns_prefix = namespace.getPrefix();
-            if (prefix == null) {
-                writer.writeNamespace(ns_prefix, namespace.getName());
-                writer.setPrefix(ns_prefix, uri);
-            }
-        }
-    }
-
-
-    /**
-     * Method serializeStartpart
-     *
-     * @param writer
-     * @throws XMLStreamException
-     */
-    public static void serializeStartpart(OMElementImpl element, OMOutput omOutput)
-            throws XMLStreamException {
-        String nameSpaceName = null;
-        String writer_prefix = null;
-        String prefix = null;
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        if (element.ns != null) {
-            nameSpaceName = element.ns.getName();
-            writer_prefix = writer.getPrefix(nameSpaceName);
-            prefix = element.ns.getPrefix();
-            if (nameSpaceName != null) {
-                if (writer_prefix != null) {
-                    writer.writeStartElement(nameSpaceName,
-                            element.getLocalName());
-                } else {
-                    if (prefix != null) {
-                        writer.writeStartElement(prefix, element.getLocalName(),
-                                nameSpaceName);
-                        writer.writeNamespace(prefix, nameSpaceName);
-                        writer.setPrefix(prefix, nameSpaceName);
-                    } else {
-                        writer.writeStartElement(nameSpaceName,
-                                element.getLocalName());
-                        writer.writeDefaultNamespace(nameSpaceName);
-                        writer.setDefaultNamespace(nameSpaceName);
-                    }
-                }
-            } else {
-                writer.writeStartElement(element.getLocalName());
-//                throw new OMException(
-//                        "Non namespace qualified elements are not allowed");
-            }
-        } else {
-            writer.writeStartElement(element.getLocalName());
-//            throw new OMException(
-//                    "Non namespace qualified elements are not allowed");
-        }
-
-        // add the elements attributes
-        serializeAttributes(element, omOutput);
-
-        // add the namespaces
-        serializeNamespaces(element, omOutput);
-    }
-
-    public static void serializeNamespaces(OMElementImpl element,
-                                           OMOutput omOutput) throws XMLStreamException {
-        Iterator namespaces = element.getAllDeclaredNamespaces();
-        if (namespaces != null) {
-            while (namespaces.hasNext()) {
-                serializeNamespace((OMNamespace) namespaces.next(), omOutput);
-            }
-        }
-    }
-
-    public static void serializeAttributes(OMElementImpl element,
-                                           OMOutput omOutput) throws XMLStreamException {
-        if (element.getAttributes() != null) {
-            Iterator attributesList = element.getAttributes();
-            while (attributesList.hasNext()) {
-                serializeAttribute((OMAttribute) attributesList.next(),
-                        omOutput);
-            }
-        }
-    }
-
-
-    /**
-     * Method serializeNormal
-     *
-     * @param writer
-     * @param cache
-     * @throws XMLStreamException
-     */
-    public static void serializeNormal(OMElementImpl element, OMOutput omOutput, boolean cache)
-            throws XMLStreamException {
-
-        if (cache) {
-            element.build();
-        }
-
-        serializeStartpart(element, omOutput);
-        OMNode firstChild = element.firstChild;
-        if (firstChild != null) {
-            if (cache) {
-                firstChild.serializeWithCache(omOutput);
-            } else {
-                firstChild.serialize(omOutput);
-            }
-        }
-        serializeEndpart(omOutput);
-    }
-
-    public static void serializeByPullStream(OMElementImpl element, OMOutput omOutput) throws XMLStreamException {
-        StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
-        streamingOMSerializer.serialize(element.getXMLStreamReaderWithoutCaching(),
-                omOutput);
-        return;
-    }
-}
+package org.apache.axis2.om.impl.llom;
+
+import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.serialize.StreamingOMSerializer;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+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.
+*
+*
+*/
+
+public class OMSerializerUtil {
+
+    /**
+     * Method serializeEndpart
+     *
+     * @param writer
+     * @throws javax.xml.stream.XMLStreamException
+     *
+     */
+    public static void serializeEndpart(OMOutputImpl omOutput)
+            throws XMLStreamException {
+        omOutput.getXmlStreamWriter().writeEndElement();
+    }
+
+    /**
+     * Method serializeAttribute
+     *
+     * @param attr
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)
+            throws XMLStreamException {
+
+        // first check whether the attribute is associated with a namespace
+        OMNamespace ns = attr.getNamespace();
+        String prefix = null;
+        String namespaceName = null;
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        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 writer
+     * @throws XMLStreamException
+     */
+    public static void serializeNamespace(OMNamespace namespace, org.apache.axis2.om.impl.OMOutputImpl omOutput)
+            throws XMLStreamException {
+
+        if (namespace != null) {
+            XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+            String uri = namespace.getName();
+            String prefix = writer.getPrefix(uri);
+            String ns_prefix = namespace.getPrefix();
+            if (prefix == null) {
+                writer.writeNamespace(ns_prefix, namespace.getName());
+                writer.setPrefix(ns_prefix, uri);
+            }
+        }
+    }
+
+
+    /**
+     * Method serializeStartpart
+     *
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public static void serializeStartpart(OMElementImpl element, OMOutputImpl omOutput)
+            throws XMLStreamException {
+        String nameSpaceName = null;
+        String writer_prefix = null;
+        String prefix = null;
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        if (element.ns != null) {
+            nameSpaceName = element.ns.getName();
+            writer_prefix = writer.getPrefix(nameSpaceName);
+            prefix = element.ns.getPrefix();
+            if (nameSpaceName != null) {
+                if (writer_prefix != null) {
+                    writer.writeStartElement(nameSpaceName,
+                            element.getLocalName());
+                } else {
+                    if (prefix != null) {
+                        writer.writeStartElement(prefix, element.getLocalName(),
+                                nameSpaceName);
+                        writer.writeNamespace(prefix, nameSpaceName);
+                        writer.setPrefix(prefix, nameSpaceName);
+                    } else {
+                        writer.writeStartElement(nameSpaceName,
+                                element.getLocalName());
+                        writer.writeDefaultNamespace(nameSpaceName);
+                        writer.setDefaultNamespace(nameSpaceName);
+                    }
+                }
+            } else {
+                writer.writeStartElement(element.getLocalName());
+//                throw new OMException(
+//                        "Non namespace qualified elements are not allowed");
+            }
+        } else {
+            writer.writeStartElement(element.getLocalName());
+//            throw new OMException(
+//                    "Non namespace qualified elements are not allowed");
+        }
+
+        // add the elements attributes
+        serializeAttributes(element, omOutput);
+
+        // add the namespaces
+        serializeNamespaces(element, omOutput);
+    }
+
+    public static void serializeNamespaces(OMElementImpl element,
+                                           org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        Iterator namespaces = element.getAllDeclaredNamespaces();
+        if (namespaces != null) {
+            while (namespaces.hasNext()) {
+                serializeNamespace((OMNamespace) namespaces.next(), omOutput);
+            }
+        }
+    }
+
+    public static void serializeAttributes(OMElementImpl element,
+                                           org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        if (element.getAttributes() != null) {
+            Iterator attributesList = element.getAttributes();
+            while (attributesList.hasNext()) {
+                serializeAttribute((OMAttribute) attributesList.next(),
+                        omOutput);
+            }
+        }
+    }
+
+
+    /**
+     * Method serializeNormal
+     *
+     * @param writer
+     * @param cache
+     * @throws XMLStreamException
+     */
+    public static void serializeNormal(OMElementImpl element, OMOutputImpl omOutput, boolean cache)
+            throws XMLStreamException {
+
+        if (cache) {
+            element.build();
+        }
+
+        serializeStartpart(element, omOutput);
+        OMNode firstChild = element.firstChild;
+        if (firstChild != null) {
+            if (cache) {
+                firstChild.serializeWithCache(omOutput);
+            } else {
+                firstChild.serialize(omOutput);
+            }
+        }
+        serializeEndpart(omOutput);
+    }
+
+    public static void serializeByPullStream(OMElementImpl element, org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+        StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
+        streamingOMSerializer.serialize(element.getXMLStreamReaderWithoutCaching(),
+                omOutput);
+        return;
+    }
+}