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 ch...@apache.org on 2006/02/01 10:05:11 UTC

svn commit: r374025 [3/8] - in /webservices/axis2/trunk/java: etc/ modules/adb/src/org/apache/axis2/databinding/ modules/adb/src/org/apache/axis2/databinding/deserializers/ modules/adb/test/org/apache/axis2/databinding/ modules/codegen/src/org/apache/a...

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ElementImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ElementImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ElementImpl.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,1293 @@
+/*
+ * 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.dom;
+
+import org.apache.ws.commons.om.OMAttribute;
+import org.apache.ws.commons.om.OMConstants;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.OMText;
+import org.apache.ws.commons.om.OMXMLParserWrapper;
+import org.apache.ws.commons.om.impl.OMNodeEx;
+import org.apache.ws.commons.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.dom.factory.OMDOMFactory;
+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.ws.commons.om.impl.llom.traverse.OMChildElementIterator;
+import org.apache.ws.commons.om.impl.llom.util.EmptyIterator;
+import org.apache.ws.commons.om.util.ElementHelper;
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.TypeInfo;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * Implementation of the org.w3c.dom.Element and org.apache.ws.commons.om.Element
+ * interfaces.
+ */
+public class ElementImpl extends ParentNode implements Element, OMElement,
+        OMConstants {
+
+    private int lineNumber;
+
+    protected OMNamespace namespace;
+
+    protected String localName;
+
+    private AttributeMap attributes;
+
+    private HashMap namespaces;
+
+    /**
+     * @param ownerDocument
+     */
+    public ElementImpl(DocumentImpl ownerDocument, String tagName) {
+        super(ownerDocument);
+        if (ownerDocument.firstChild == null)
+            ownerDocument.firstChild = this;
+        this.localName = tagName;
+        this.attributes = new AttributeMap(this);
+        this.done = true;
+    }
+
+    /**
+     * Creates a new element with the namespace.
+     * 
+     * @param ownerDocument
+     * @param tagName
+     * @param ns
+     */
+    public ElementImpl(DocumentImpl ownerDocument, String tagName,
+            NamespaceImpl ns) {
+        super(ownerDocument);
+        this.localName = tagName;
+        this.namespace = ns;
+        this.declareNamespace(ns);
+        this.attributes = new AttributeMap(this);
+        this.done = true;
+    }
+
+    public ElementImpl(DocumentImpl ownerDocument, String tagName,
+            NamespaceImpl ns, OMXMLParserWrapper builder) {
+        super(ownerDocument);
+        this.localName = tagName;
+        this.namespace = ns;
+        this.builder = builder;
+        this.declareNamespace(ns);
+        this.attributes = new AttributeMap(this);
+    }
+
+    public ElementImpl(ParentNode parentNode, String tagName, NamespaceImpl ns) {
+        this((DocumentImpl) parentNode.getOwnerDocument(), tagName, ns);
+        this.parentNode = parentNode;
+        this.parentNode.addChild(this);
+        this.done = true;
+    }
+
+    public ElementImpl(ParentNode parentNode, String tagName, NamespaceImpl ns,
+            OMXMLParserWrapper builder) {
+        this(tagName, ns, builder);
+        if (parentNode != null) {
+            this.ownerNode = (DocumentImpl) parentNode.getOwnerDocument();
+            this.isOwned(true);
+            this.parentNode = parentNode;
+            this.parentNode.addChild(this);
+        }
+
+    }
+
+    public ElementImpl(String tagName, NamespaceImpl ns,
+            OMXMLParserWrapper builder) {
+        this.localName = tagName;
+        this.namespace = ns;
+        this.builder = builder;
+        if (ns != null) {
+            this.declareNamespace(ns);
+        }
+        this.attributes = new AttributeMap(this);
+    }
+
+    // /
+    // /org.w3c.dom.Node methods
+    // /
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#getNodeType()
+     */
+    public short getNodeType() {
+        return Node.ELEMENT_NODE;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#getNodeName()
+     */
+    public String getNodeName() {
+        if (this.namespace != null) {
+            if (this.namespace.getPrefix() == null
+                    || "".equals(this.namespace.getPrefix())) {
+                return this.localName;
+            } else {
+                return this.namespace.getPrefix() + ":" + this.localName;
+            }
+        } else {
+            return this.localName;
+        }
+    }
+
+    /**
+     * Returns the value of the namespace URI.
+     */
+    public String getNamespaceURI() {
+        return (this.namespace != null) ? this.namespace.getName() : null;
+    }
+
+    // /
+    // /org.apache.ws.commons.om.OMNode methods
+    // /
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNode#getType()
+     */
+    public int getType() throws OMException {
+        return Node.ELEMENT_NODE;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNode#setType(int)
+     */
+    public void setType(int nodeType) throws OMException {
+        // Do nothing ...
+        // This is an Eement Node...
+    }
+
+    // /
+    // / org.w3c.dom.Element methods
+    // /
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#getTagName()
+     */
+    public String getTagName() {
+        return this.getNodeName();
+    }
+
+    /**
+     * Removes an attribute by name.
+     * 
+     * @param name
+     *            The name of the attribute to remove
+     * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
+     */
+    public void removeAttribute(String name) throws DOMException {
+        if (this.isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        if (name.startsWith(OMConstants.XMLNS_NS_PREFIX)) {
+            String namespacePrefix = DOMUtil.getLocalName(name);
+            if (this.findNamespaceURI(namespacePrefix) != null) {
+                this.removeNamespace(namespacePrefix);
+            }
+        }
+
+        if (this.attributes != null) {
+            this.attributes.removeNamedItem(name);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String,
+     *      java.lang.String)
+     */
+    public void removeAttributeNS(String namespaceURI, String localName)
+            throws DOMException {
+        if (this.isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        if (this.attributes != null) {
+            this.attributes.removeNamedItemNS(namespaceURI, localName);
+        }
+    }
+
+    /**
+     * Removes the specified attribute node.
+     * 
+     * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr)
+     */
+    public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
+        if (isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        if (this.attributes == null
+                || this.attributes.getNamedItem(oldAttr.getName()) == null) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+        }
+        AttrImpl tempAttr = (AttrImpl) this.attributes.removeNamedItem(oldAttr
+                .getName());
+        return tempAttr;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#hasAttribute(java.lang.String)
+     */
+    public boolean hasAttribute(String name) {
+        return this.getAttributeNode(name) != null;
+    }
+
+    /**
+     * Returns whether the given attribute is available or not.
+     * 
+     * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String,
+     *      java.lang.String)
+     */
+    public boolean hasAttributeNS(String namespaceURI, String localName) {
+        return this.getAttributeNodeNS(namespaceURI, localName) != null;
+    }
+
+    /**
+     * Looks in the local list of attributes and returns if found. If the local
+     * list is null, returns "".
+     * 
+     * @see org.w3c.dom.Element#getAttribute(java.lang.String)
+     */
+    public String getAttribute(String name) {
+        if (attributes == null) {
+            return "";
+        } else {
+            Attr attr = ((Attr) attributes.getNamedItem(name));
+            return (attr != null) ? attr.getValue() : "";
+        }
+    }
+
+    /**
+     * Retrieves an attribute node by name.
+     * 
+     * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
+     */
+    public Attr getAttributeNode(String name) {
+        return (this.attributes == null) ? null : (AttrImpl) this.attributes
+                .getNamedItem(name);
+    }
+
+    /**
+     * Retrieves an attribute value by local name and namespace URI.
+     * 
+     * @see org.w3c.dom.Element#getAttributeNS(java.lang.String,
+     *      java.lang.String)
+     */
+    public String getAttributeNS(String namespaceURI, String localName) {
+        if (this.attributes == null) {
+            return "";
+        }
+        Attr attributeNodeNS = this.getAttributeNodeNS(namespaceURI, localName);
+        return attributeNodeNS == null ? "" : attributeNodeNS.getValue();
+    }
+
+    /**
+     * Retrieves an attribute node by local name and namespace URI.
+     * 
+     * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String,
+     *      java.lang.String)
+     */
+    public Attr getAttributeNodeNS(String namespaceURI, String localName) {
+
+        if (namespaceURI == OMConstants.XMLNS_NS_URI) {
+            OMNamespace ns = this.findNamespaceURI(localName);
+            AttrImpl namespaceAttr = new AttrImpl(this.ownerNode, localName, ns
+                    .getName());
+            NamespaceImpl xmlNs = new NamespaceImpl(OMConstants.XMLNS_NS_URI);
+            namespaceAttr.setOMNamespace(xmlNs);
+            return namespaceAttr;
+        }
+
+        return (this.attributes == null) ? null : (Attr) this.attributes
+                .getNamedItemNS(namespaceURI, localName);
+
+    }
+
+    /**
+     * Adds a new attribute node.
+     * 
+     * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
+     */
+    public Attr setAttributeNode(Attr attr) throws DOMException {
+        AttrImpl attrImpl = (AttrImpl) attr;
+
+        if (attrImpl.isOwned()) {// check for ownership
+            if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
+                String msg = DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR",
+                        null);
+                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+            }
+        }
+
+        if (this.isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        // check whether the attr is in use
+        if (attrImpl.isUsed()) {
+            String msg = DOMMessageFormatter
+                    .formatMessage(DOMMessageFormatter.DOM_DOMAIN,
+                            "INUSE_ATTRIBUTE_ERR", null);
+            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+        }
+
+        if (attr.getName().startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
+            // This is a ns declaration
+            this.declareNamespace(attr.getNodeValue(), DOMUtil
+                    .getLocalName(attr.getName()));
+        }
+        if (this.attributes == null) {
+            this.attributes = new AttributeMap(this);
+        }
+
+        return (Attr) this.attributes.setNamedItem(attr);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String)
+     */
+    public void setAttribute(String name, String value) throws DOMException {
+        // Check for invalid charaters
+        if (!DOMUtil.isValidChras(name)) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR",
+                    null);
+            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+        }
+        if (name.startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
+            // This is a ns declaration
+            this.declareNamespace(value, DOMUtil.getLocalName(name));
+        } else {
+            this.setAttributeNode(new AttrImpl(this.ownerNode, name, value));
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr)
+     */
+    public Attr setAttributeNodeNS(Attr attr) throws DOMException {
+
+        // Check whether the attr is a namespace declaration
+        // if so add a namespace NOT an attribute
+        if (attr.getNamespaceURI() != null
+                && attr.getNamespaceURI().equals(OMConstants.XMLNS_NS_URI)) {
+            this.declareNamespace(attr.getName(), attr.getValue());
+            return attr;
+        } else {
+            AttrImpl attrImpl = (AttrImpl) attr;
+
+            if (attrImpl.isOwned()) {// check for ownership
+                if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
+                    String msg = DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "WRONG_DOCUMENT_ERR", null);
+                    throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+                }
+            }
+
+            if (this.isReadonly()) {
+                String msg = DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "NO_MODIFICATION_ALLOWED_ERR", null);
+                throw new DOMException(
+                        DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+            }
+
+            // check whether the attr is in use
+            if (attrImpl.isUsed()) {
+                String msg = DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN, "INUSE_ATTRIBUTE_ERR",
+                        null);
+                throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+            }
+
+            if (this.attributes == null) {
+                this.attributes = new AttributeMap(this);
+            }
+
+            // handle the namespaces
+            if (attr.getNamespaceURI() != null
+                    && findNamespace(attr.getNamespaceURI(), attr.getPrefix()) 
+                    == null) {
+                // TODO checkwhether the same ns is declared with a different
+                // prefix and remove it
+                this.declareNamespace(new NamespaceImpl(attr.getNamespaceURI(),
+                        attr.getPrefix()));
+            }
+
+            return (Attr) this.attributes.setNamedItemNS(attr);
+        }
+    }
+
+    /**
+     * Adds a new attribute.
+     * 
+     * @see org.w3c.dom.Element#setAttributeNS(java.lang.String,
+     *      java.lang.String, java.lang.String)
+     */
+    public void setAttributeNS(String namespaceURI, String qualifiedName,
+            String value) throws DOMException {
+
+        if (namespaceURI != null && !"".equals(namespaceURI)) {
+            if (namespaceURI.equals(OMConstants.XMLNS_NS_URI)) {
+                this.declareNamespace(value, DOMUtil
+                        .getLocalName(qualifiedName));
+            } else {
+                AttrImpl attr = new AttrImpl(this.ownerNode, DOMUtil
+                        .getLocalName(qualifiedName), value);
+                attr.setOMNamespace(new NamespaceImpl(namespaceURI, DOMUtil
+                        .getPrefix(qualifiedName)));
+
+                this.setAttributeNodeNS(attr);
+            }
+        } else {
+            // When the namespace is null, the attr name given better not be
+            // a qualified name
+            // But anyway check and set it
+            this.setAttribute(DOMUtil.getLocalName(qualifiedName), value);
+        }
+
+    }
+
+    private OMAttribute addAttribute(String namespaceURI, String qualifiedName,
+            String value) throws DOMException {
+        if (!DOMUtil.isValidChras(qualifiedName)) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR",
+                    null);
+            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+        }
+
+        if (this.isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        if (this.attributes == null) {
+            this.attributes = new AttributeMap(this);
+        }
+        if (namespaceURI != null) {
+            if (!DOMUtil.isValidNamespace(namespaceURI, qualifiedName)) {
+                String msg = DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
+                throw new DOMException(DOMException.NAMESPACE_ERR, msg);
+            }
+            // Check whether there's an existing Attr with same local name and
+            // namespace URI
+            Attr attributeNode = this.getAttributeNodeNS(namespaceURI, DOMUtil
+                    .getLocalName(qualifiedName));
+            if (attributeNode != null) {
+                AttrImpl tempAttr = ((AttrImpl) attributeNode);
+                tempAttr.setOMNamespace(new NamespaceImpl(namespaceURI, DOMUtil
+                        .getPrefix(qualifiedName)));
+                tempAttr.setAttributeValue(value);
+                this.attributes.setNamedItem(tempAttr);
+                return tempAttr;
+            } else {
+                NamespaceImpl ns = new NamespaceImpl(namespaceURI, DOMUtil
+                        .getPrefix(qualifiedName));
+                AttrImpl attr = new AttrImpl((DocumentImpl) this
+                        .getOwnerDocument(), DOMUtil
+                        .getLocalName(qualifiedName), ns, value);
+                this.attributes.setNamedItem(attr);
+                return attr;
+            }
+        } else {
+            Attr attributeNode = this.getAttributeNode(qualifiedName);
+            if (attributeNode != null) {
+                AttrImpl tempAttr = ((AttrImpl) attributeNode);
+                tempAttr.setAttributeValue(value);
+                this.attributes.setNamedItem(tempAttr);
+                return tempAttr;
+            } else {
+                AttrImpl attr = new AttrImpl((DocumentImpl) this
+                        .getOwnerDocument(), qualifiedName, value);
+                this.attributes.setNamedItem(attr);
+                return attr;
+            }
+        }
+    }
+
+    /**
+     * Returns whether this element contains any attribute or not.
+     */
+    public boolean hasAttributes() {
+
+        boolean flag = false;
+        if (this.attributes != null) {
+            flag = (this.attributes.getLength() > 0);
+        }
+
+        if (!flag) {
+            if (this.namespaces != null) {
+                flag = !this.namespaces.isEmpty();
+            } else if (this.namespace != null) {
+                flag = true;
+            }
+        }
+
+        return flag;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String,
+     *      java.lang.String)
+     */
+    public NodeList getElementsByTagNameNS(String namespaceURI, 
+                                            String localName) {
+        return new NodeListImpl(this, namespaceURI, localName);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
+     */
+    public NodeList getElementsByTagName(String name) {
+        return new NodeListImpl(this, name);
+    }
+
+    // /
+    // /OmElement methods
+    // /
+
+    /**
+     * @see org.apache.ws.commons.om.OMElement#addAttribute
+     * (org.apache.ws.commons.om.OMAttribute)
+     */
+    public OMAttribute addAttribute(OMAttribute attr) {
+        OMNamespace namespace = attr.getNamespace();
+        if (namespace != null
+                && this.findNamespace(namespace.getName(), namespace
+                        .getPrefix()) == null) {
+            this.declareNamespace(namespace.getName(), namespace.getPrefix());
+        }
+
+        if (attr.getNamespace() != null) { // If the attr has a namespace
+            return (AttrImpl) this.setAttributeNode((Attr) attr);
+        } else {
+            return (AttrImpl) this.setAttributeNodeNS((Attr) attr);
+        }
+    }
+
+    /**
+     * The behaviour of this is the same as org.w3c.dom.Element#setAttributeNS
+     * 
+     * @see org.apache.ws.commons.om.OMElement#addAttribute(java.lang.String,
+     *      java.lang.String, org.apache.ws.commons.om.OMNamespace)
+     */
+    public OMAttribute addAttribute(String attributeName, String value,
+            OMNamespace ns) {
+        if (ns != null && findNamespace(ns.getName(), ns.getPrefix()) != null) {
+            declareNamespace(ns);
+        }
+        if (ns != null) {
+            return this.addAttribute(ns.getName(), ns.getPrefix() + ":"
+                    + attributeName, value);
+        } else {
+            return this.addAttribute(null, attributeName, value);
+        }
+
+    }
+
+    /**
+     * Allows overriding an existing declaration if the same prefix was used.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#declareNamespace
+     * (org.apache.ws.commons.om.OMNamespace)
+     */
+    public OMNamespace declareNamespace(OMNamespace namespace) {
+        if (namespaces == null) {
+            this.namespaces = new HashMap(5);
+        }
+        if (namespace != null
+                && (namespace.getPrefix() != null || "".equals(namespace
+                        .getPrefix()))) {
+            if (!namespace.getPrefix().startsWith(OMConstants.XMLNS_NS_PREFIX)) {
+                namespaces.put(namespace.getPrefix(), namespace);
+            }
+        }
+        return namespace;
+    }
+
+    /**
+     * Allows overriding an existing declaration if the same prefix was used.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#declareNamespace(java.lang.String,
+     *      java.lang.String)
+     */
+    public OMNamespace declareNamespace(String uri, String prefix) {
+        NamespaceImpl ns = new NamespaceImpl(uri, prefix);
+        return declareNamespace(ns);
+    }
+
+    /**
+     * @see org.apache.ws.commons.om.OMElement#findNamespace(java.lang.String,
+     *      java.lang.String)
+     */
+    public OMNamespace findNamespace(String uri, String prefix) {
+
+        // check in the current element
+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
+        if (namespace != null) {
+            return namespace;
+        }
+
+        // go up to check with ancestors
+        if (this.parentNode != null) {
+            // For the OMDocumentImpl there won't be any explicit namespace
+            // declarations, so going up the parent chain till the document
+            // element should be enough.
+            if (parentNode instanceof OMElement) {
+                namespace = ((ElementImpl) parentNode).findNamespace(uri,
+                        prefix);
+            }
+        }
+
+        if (namespace == null && uri != null && prefix != null
+                && prefix.equals(OMConstants.XMLNS_PREFIX)
+                && uri.equals(OMConstants.XMLNS_URI)) {
+            declareNamespace(OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX);
+            namespace = findNamespace(uri, prefix);
+        }
+        return namespace;
+    }
+
+    public OMNamespace findNamespaceURI(String prefix) {
+        OMNamespace ns = (OMNamespace) this.namespaces.get(prefix);
+        if (ns == null && this.parentNode instanceof OMElement) {
+            // try with the parent
+            ns = ((OMElement) this.parentNode).findNamespaceURI(prefix);
+        }
+        return ns;
+    }
+
+    /**
+     * Checks for the namespace <B>only</B> in the current Element. This can
+     * also be used to retrieve the prefix of a known namespace URI.
+     */
+    private OMNamespace findDeclaredNamespace(String uri, String prefix) {
+
+        if (uri == null) {
+            return null;
+        }
+        // If the prefix is available and uri is available and its the xml
+        // namespace
+        if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX)
+                && uri.equals(OMConstants.XMLNS_URI)) {
+            return new NamespaceImpl(uri, prefix);
+        }
+
+        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() != null
+                        && omNamespace.getName().equals(uri)) {
+                    return omNamespace;
+                }
+            }
+            return null;
+        } else {
+            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
+            if (namespace != null && uri.equalsIgnoreCase(namespace.getName())) {
+                return namespace;
+            } else {
+                return null;
+            }
+        }
+    }
+
+    /**
+     * Returns a named attribute if present.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getAttribute
+     * (javax.xml.namespace.QName)
+     */
+    public OMAttribute getAttribute(QName qname) {
+        if (this.attributes == null) {
+            return null;
+        }
+
+        if (qname.getNamespaceURI() == null
+                || qname.getNamespaceURI().equals("")) {
+            return (AttrImpl) this.getAttributeNode(qname.getLocalPart());
+        } else {
+            return (AttrImpl) this.getAttributeNodeNS(qname.getNamespaceURI(),
+                    qname.getLocalPart());
+        }
+    }
+
+    /**
+     * Returns a named attribute's value, if present.
+     * 
+     * @param qname
+     *            the qualified name to search for
+     * @return Returns a String containing the attribute value, or null.
+     */
+    public String getAttributeValue(QName qname) {
+        OMAttribute attr = getAttribute(qname);
+        return (attr == null) ? null : attr.getAttributeValue();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getBuilder()
+     */
+    public OMXMLParserWrapper getBuilder() {
+        return this.builder;
+    }
+
+    /**
+     * Returns the first Element node.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getFirstElement()
+     */
+    public OMElement getFirstElement() {
+        OMNode node = getFirstOMChild();
+        while (node != null) {
+            if (node.getType() == Node.ELEMENT_NODE) {
+                return (OMElement) node;
+            } else {
+                node = node.getNextOMSibling();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the namespace of this element.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getNamespace()
+     */
+    public OMNamespace getNamespace() throws OMException {
+        return this.namespace;
+    }
+
+    /**
+     * Returns the QName of this element.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getQName()
+     */
+    public QName getQName() {
+        QName qName;
+        if (namespace != null) {
+            if (namespace.getPrefix() != null) {
+                qName = new QName(namespace.getName(), this.localName,
+                        namespace.getPrefix());
+            } else {
+                qName = new QName(namespace.getName(), this.localName);
+            }
+        } else {
+            qName = new QName(this.localName);
+        }
+        return qName;
+    }
+
+    /**
+     * Gets all the text children and concatinates them to a single string.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getText()
+     */
+    public String getText() {
+        String childText = "";
+        OMNode child = this.getFirstOMChild();
+        OMText textNode;
+
+        while (child != null) {
+            if (child.getType() == Node.TEXT_NODE) {
+                textNode = (OMText) child;
+                if (textNode.getText() != null
+                        && !"".equals(textNode.getText())) {
+                    childText += textNode.getText();
+                }
+            }
+            child = child.getNextOMSibling();
+        }
+
+        return childText;
+    }
+
+    /**
+     * Removes an attribute from the element.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#removeAttribute
+     * (org.apache.ws.commons.om.OMAttribute)
+     */
+    public void removeAttribute(OMAttribute attr) {
+        this.removeAttributeNode((AttrImpl) attr);
+    }
+
+    /**
+     * Sets the OM builder.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#setBuilder
+     * (org.apache.ws.commons.om.OMXMLParserWrapper)
+     */
+    public void setBuilder(OMXMLParserWrapper wrapper) {
+        this.builder = wrapper;
+    }
+
+    /**
+     * Sets the local name.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#setLocalName(java.lang.String)
+     */
+    public void setLocalName(String localName) {
+        this.localName = localName;
+    }
+
+    /**
+     * Sets the namespace.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#setNamespace
+     * (org.apache.ws.commons.om.OMNamespace)
+     */
+    public void setNamespace(OMNamespace namespace) {
+        this.namespace = namespace;
+    }
+
+    /**
+     * Creates a text node with the given value and adds it to the element.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#setText(java.lang.String)
+     */
+    public void setText(String text) {
+        if (this.isReadonly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        // if we already have other text nodes remove them
+        OMNode child = this.getFirstOMChild();
+        while (child != null) {
+            if (child.getType() == OMNode.TEXT_NODE) {
+                child.detach();
+            }
+            child = child.getNextOMSibling();
+        }
+
+        TextImpl textNode = (TextImpl) ((DocumentImpl) this.ownerNode)
+                .createTextNode(text);
+        this.addChild(textNode);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNode#serialize(org.apache.ws.commons.om.OMOutput)
+     */
+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
+        serialize(omOutput, true);
+    }
+
+    public void serializeAndConsume(OMOutputImpl omOutput)
+            throws XMLStreamException {
+        this.serialize(omOutput, false);
+    }
+
+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput,
+            boolean cache) throws XMLStreamException {
+
+        if (cache) {
+            // in this case we don't care whether the elements are built or not
+            // we just call the serializeAndConsume methods
+            OMSerializerUtil.serializeStartpart(this, omOutput);
+            // serilize children
+            Iterator children = this.getChildren();
+            while (children.hasNext()) {
+                ((OMNodeEx) children.next()).serialize(omOutput);
+            }
+            OMSerializerUtil.serializeEndpart(omOutput);
+
+        } else {
+            // Now the caching is supposed to be off. However caching been
+            // switched off
+            // has nothing to do if the element is already built!
+            if (this.done) {
+                OMSerializerUtil.serializeStartpart(this, omOutput);
+                ChildNode child = this.firstChild;
+                while (child != null
+                        && ((!(child instanceof OMElement)) || child
+                                .isComplete())) {
+                    child.serializeAndConsume(omOutput);
+                    child = child.nextSibling;
+                }
+                if (child != null) {
+                    OMElement element = (OMElement) child;
+                    element.getBuilder().setCache(false);
+                    OMSerializerUtil.serializeByPullStream(element, omOutput,
+                            cache);
+                }
+                OMSerializerUtil.serializeEndpart(omOutput);
+            } else {
+                // take the XMLStream reader and feed it to the stream
+                // serilizer.
+                // todo is this right ?????
+                OMSerializerUtil.serializeByPullStream(this, omOutput, cache);
+            }
+
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getXMLStreamReaderWithoutCaching()
+     */
+    public XMLStreamReader getXMLStreamReaderWithoutCaching() {
+        return getXMLStreamReader(false);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getXMLStreamReader()
+     */
+    public XMLStreamReader getXMLStreamReader() {
+        return getXMLStreamReader(true);
+    }
+
+    /**
+     * getXMLStreamReader
+     * 
+     * @return Returns reader.
+     */
+    private XMLStreamReader getXMLStreamReader(boolean cache) {
+        if ((builder == null) && !cache) {
+            throw new UnsupportedOperationException(
+                    "This element was not created in a manner to be switched");
+        }
+        if (builder != null && builder.isCompleted() && !cache) {
+            throw new UnsupportedOperationException(
+                    "The parser is already consumed!");
+        }
+        return new DOMStAXWrapper(builder, this, cache);
+    }
+
+    public String toStringWithConsume() throws XMLStreamException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        this.serializeAndConsume(baos);
+        return new String(baos.toByteArray());
+    }
+
+    /**
+     * Overridden toString() for ease of debugging.
+     * 
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return (this.namespace != null) ? namespace.getPrefix() + ":"
+                + this.localName : "" + this.localName;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMElement#getChildElements()
+     */
+    public Iterator getChildElements() {
+        return new OMChildElementIterator(getFirstElement());
+    }
+
+    /**
+     * @see org.apache.ws.commons.om.OMElement#getAllDeclaredNamespaces()
+     */
+    public Iterator getAllDeclaredNamespaces() throws OMException {
+        if (namespaces == null) {
+            return null;
+        }
+        return namespaces.values().iterator();
+    }
+
+    /**
+     * @see org.apache.ws.commons.om.OMElement#getAllAttributes()
+     */
+    public Iterator getAllAttributes() {
+        if (attributes == null) {
+            return new EmptyIterator();
+        }
+        ArrayList list = new ArrayList();
+        for (int i = 0; i < attributes.getLength(); i++) {
+            list.add(attributes.getItem(i));
+        }
+
+        return list.iterator();
+    }
+
+    /**
+     * Returns the local name of this element node
+     * 
+     * @see org.w3c.dom.Node#getLocalName()
+     */
+    public String getLocalName() {
+        return this.localName;
+    }
+
+    /**
+     * Returns the namespace prefix of this element node
+     * 
+     * @see org.w3c.dom.Node#getPrefix()
+     */
+    public String getPrefix() {
+        // TODO Error checking
+        return (this.namespace == null) ? null : this.namespace.getPrefix();
+    }
+
+    /**
+     * @see org.apache.axis2.om.impl.dom.NodeImpl#setOwnerDocument
+     * (org.apache.axis2.om.impl.dom.DocumentImpl)
+     */
+    protected void setOwnerDocument(DocumentImpl document) {
+        this.ownerNode = document;
+        this.isOwned(true);
+        if (document.firstChild == null)
+            document.firstChild = this;
+    }
+
+    /**
+     * Turn a prefix:local qname string into a proper QName, evaluating it in
+     * the OMElement context unprefixed qnames resolve to the local namespace
+     * 
+     * @param qname
+     *            prefixed qname string to resolve
+     * @return Returns null for any failure to extract a qname.
+     */
+    public QName resolveQName(String qname) {
+        ElementHelper helper = new ElementHelper(this);
+        return helper.resolveQName(qname);
+    }
+
+    /**
+     * Creates a clone which belongs to a new document.
+     * 
+     * @see org.apache.ws.commons.om.OMElement#cloneOMElement()
+     */
+    public OMElement cloneOMElement() {
+        ElementImpl elem = (ElementImpl) (new StAXOMBuilder(new OMDOMFactory(),
+                this.getXMLStreamReader(true))).getDocumentElement();
+        return elem;
+    }
+
+    public void setLineNumber(int lineNumber) {
+        this.lineNumber = lineNumber;
+    }
+
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    public Node cloneNode(boolean deep) {
+
+        ElementImpl newnode = (ElementImpl) super.cloneNode(deep);
+        // Replicate NamedNodeMap rather than sharing it.
+        if (attributes != null) {
+            newnode.attributes = (AttributeMap) attributes.cloneMap(newnode);
+        }
+        return newnode;
+
+    }
+
+    /**
+     * Returns the set of attributes of this node and the namespace declarations
+     * available.
+     */
+    public NamedNodeMap getAttributes() {
+        AttributeMap attributeMap = new AttributeMap(this);
+
+        // Add the set of existing attrs
+        for (int i = 0; i < this.attributes.getLength(); i++) {
+            attributeMap.addItem((Attr) this.attributes.getItem(i));
+        }
+
+        // Add the NS declarations
+        if (this.namespaces != null) {
+            Iterator nsDecls = this.namespaces.keySet().iterator();
+            while (nsDecls.hasNext()) {
+                String prefix = (String) nsDecls.next();
+                if (prefix != null && !"".equals(prefix)
+                        && !prefix.equals(OMConstants.XMLNS_NS_PREFIX)) {
+                    OMNamespace ns = (OMNamespace) this.namespaces.get(prefix);
+                    AttrImpl attr = new AttrImpl(this.ownerNode, prefix, ns
+                            .getName());
+                    attr.setOMNamespace(new NamespaceImpl(
+                            OMConstants.XMLNS_NS_URI,
+                            OMConstants.XMLNS_NS_PREFIX));
+                    attributeMap.addItem(attr);
+                }
+            }
+
+            // Set the default NS attr if any
+            if (this.namespace != null
+                    && (this.namespace.getPrefix() == null || ""
+                            .equals(this.namespace.getPrefix()))
+                    && this.namespace.getName() != null) {
+
+                // check if the parent of this element has the same namespace
+                // as the default and if NOT add the attr
+                if (this.parentNode.getNamespaceURI() != this.getNamespaceURI()) {
+                    AttrImpl attr = new AttrImpl(this.ownerNode, "xmlns",
+                            this.namespace.getName());
+                    attributeMap.addItem(attr);
+                }
+            }
+        }
+
+        return attributeMap;
+    }
+
+    /**
+     * Returns the namespace uri, given the prefix. If it is not found at this
+     * element, searches the parent.
+     * 
+     * @param prefix
+     * @return Returns namespace.
+     */
+    public String getNamespaceURI(String prefix) {
+        OMNamespace ns = this.findNamespaceURI(prefix);
+        return (ns != null) ? ns.getName() : null;
+    }
+
+    /**
+     * Removes a declared namespace given its prefix.
+     * 
+     * @param prefix
+     * @return Returns whether the namespace relevant to the given prefix was
+     *         removed or not
+     */
+    public boolean removeNamespace(String prefix) {
+        Object ns = this.namespaces.get(prefix);
+        if (ns != null) {
+            this.namespaces.remove(ns);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public OMNode getNextOMSibling() throws OMException {
+        while (!done) {
+            int token = builder.next();
+            if (token == XMLStreamConstants.END_DOCUMENT) {
+                throw new OMException();
+            }
+        }
+        return super.getNextOMSibling();
+    }
+
+    public void discard() throws OMException {
+        if (done) {
+            this.detach();
+        } else {
+            builder.discard(this);
+        }
+    }
+
+    /*
+     * DOM-Level 3 methods
+     */
+
+    public TypeInfo getSchemaTypeInfo() {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public void setIdAttribute(String arg0, boolean arg1) throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public void setIdAttributeNode(Attr arg0, boolean arg1) throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public void setIdAttributeNS(String arg0, String arg1, boolean arg2)
+            throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+}

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,466 @@
+/*
+ * 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.dom;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import java.util.Vector;
+
+/**
+ * 
+ * Most of the implementation is taken from
+ * org.apache.xerces.dom.NamedNodeMapImpl
+ */
+public class NamedNodeMapImpl implements NamedNodeMap {
+
+    Vector nodes;
+
+    ParentNode ownerNode;
+
+    //
+    // Data
+    //
+
+    protected short flags;
+
+    protected final static short READONLY = 0x1 << 0;
+
+    protected final static short CHANGED = 0x1 << 1;
+
+    protected final static short HASDEFAULTS = 0x1 << 2;
+
+    protected NamedNodeMapImpl(ParentNode ownerNode) {
+        this.ownerNode = ownerNode;
+    }
+
+    /**
+     * 
+     */
+    public Node getNamedItem(String name) {
+        int i = findNamePoint(name, 0);
+        return (i < 0) ? null : (Node) (nodes.elementAt(i));
+
+    }
+
+    /**
+     * From org.apache.xerces.dom.NamedNodeMapImpl
+     */
+    public Node item(int index) {
+        return (nodes != null && index < nodes.size()) ? (Node) (nodes
+                .elementAt(index)) : null;
+    }
+
+    /**
+     * From org.apache.xerces.dom.NamedNodeMapImpl
+     */
+    public int getLength() {
+        return (nodes != null) ? nodes.size() : 0;
+    }
+
+    /**
+     * Removes a node specified by name.
+     * 
+     * @param name
+     *            The name of a node to remove.
+     * @return Returns the node removed from the map if a node with such a name
+     *         exists.
+     */
+    /***/
+    public Node removeNamedItem(String name) throws DOMException {
+
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        int i = findNamePoint(name, 0);
+        if (i < 0) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+        }
+
+        NodeImpl n = (NodeImpl) nodes.elementAt(i);
+        nodes.removeElementAt(i);
+
+        return n;
+
+    } // removeNamedItem(String):Node
+
+    /**
+     * Introduced in DOM Level 2. Retrieves a node specified by local name and
+     * namespace URI.
+     * 
+     * @param namespaceURI
+     *            The namespace URI of the node to retrieve. When it is null or
+     *            an empty string, this method behaves like getNamedItem.
+     * @param localName
+     *            The local name of the node to retrieve.
+     * @return Returns s Node (of any type) with the specified name, or null if
+     *         the specified name did not identify any node in the map.
+     */
+    public Node getNamedItemNS(String namespaceURI, String localName) {
+
+        int i = findNamePoint(namespaceURI, localName);
+        return (i < 0) ? null : (Node) (nodes.elementAt(i));
+
+    } // getNamedItemNS(String,String):Node
+
+    /**
+     * Adds a node using its namespaceURI and localName.
+     * 
+     * @see org.w3c.dom.NamedNodeMap#setNamedItem
+     * @return Returns the replaced Node if the new Node replaces an existing
+     *         node else returns null.
+     * @param arg
+     *            A node to store in a named node map. The node will later be
+     *            accessible using the value of the namespaceURI and localName
+     *            attribute of the node. If a node with those namespace URI and
+     *            local name is already present in the map, it is replaced by
+     *            the new one.
+     */
+    public Node setNamedItemNS(Node arg) throws DOMException {
+
+        DocumentImpl ownerDocument = (DocumentImpl) ownerNode
+                .getOwnerDocument();
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        if (arg.getOwnerDocument() != ownerDocument) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+        }
+
+        int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
+        NodeImpl previous = null;
+        if (i >= 0) {
+            previous = (NodeImpl) nodes.elementAt(i);
+            nodes.setElementAt(arg, i);
+        } else {
+            // If we can't find by namespaceURI, localName, then we find by
+            // nodeName so we know where to insert.
+            i = findNamePoint(arg.getNodeName(), 0);
+            if (i >= 0) {
+                previous = (NodeImpl) nodes.elementAt(i);
+                nodes.insertElementAt(arg, i);
+            } else {
+                i = -1 - i; // Insert point (may be end of list)
+                if (null == nodes) {
+                    nodes = new Vector(5, 10);
+                }
+                nodes.insertElementAt(arg, i);
+            }
+        }
+        return previous;
+
+    } // setNamedItemNS(Node):Node
+
+    /**
+     * Introduced in DOM Level 2. Removes a node specified by local name and
+     * namespace URI.
+     * 
+     * @param namespaceURI
+     *            The namespace URI of the node to remove. When it is null or an
+     *            empty string, this method behaves like removeNamedItem.
+     * @param name
+     *            The local name of the node to remove.
+     * @return Returns the node removed from the map if a node with such a local
+     *         name and namespace URI exists.
+     * @throws NOT_FOUND_ERR:
+     *             Raised if there is no node named name in the map.
+     * 
+     */
+    public Node removeNamedItemNS(String namespaceURI, String name)
+            throws DOMException {
+
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        int i = findNamePoint(namespaceURI, name);
+        if (i < 0) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+        }
+
+        NodeImpl n = (NodeImpl) nodes.elementAt(i);
+        nodes.removeElementAt(i);
+
+        return n;
+
+    } // removeNamedItem(String):Node
+
+    /**
+     * Adds a node using its nodeName attribute. As the nodeName attribute is
+     * used to derive the name which the node must be stored under, multiple
+     * nodes of certain types (those that have a "special" string value) cannot
+     * be stored as the names would clash. This is seen as preferable to
+     * allowing nodes to be aliased.
+     * 
+     * @see org.w3c.dom.NamedNodeMap#setNamedItem
+     * @return Returns the replaced Node if the new Node replaces an existing
+     *         node, otherwise returns null.
+     * @param arg
+     *            A node to store in a named node map. The node will later be
+     *            accessible using the value of the namespaceURI and localName
+     *            attribute of the node. If a node with those namespace URI and
+     *            local name is already present in the map, it is replaced by
+     *            the new one.
+     * @exception org.w3c.dom.DOMException
+     *                The exception description.
+     */
+    public Node setNamedItem(Node arg) throws DOMException {
+
+        DocumentImpl ownerDocument = (DocumentImpl) ownerNode
+                .getOwnerDocument();
+
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        if (arg.getOwnerDocument() != ownerDocument) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+        }
+
+        int i = findNamePoint(arg.getNodeName(), 0);
+        NodeImpl previous = null;
+        if (i >= 0) {
+            previous = (NodeImpl) nodes.elementAt(i);
+            nodes.setElementAt(arg, i);
+        } else {
+            i = -1 - i; // Insert point (may be end of list)
+            if (null == nodes) {
+                nodes = new Vector(5, 10);
+            }
+            nodes.insertElementAt(arg, i);
+        }
+        return previous;
+
+    } // setNamedItem(Node):Node
+
+    final boolean isReadOnly() {
+        return (flags & READONLY) != 0;
+    }
+
+    final void isReadOnly(boolean value) {
+        flags = (short) (value ? flags | READONLY : flags & ~READONLY);
+    }
+
+    final boolean changed() {
+        return (flags & CHANGED) != 0;
+    }
+
+    final void changed(boolean value) {
+        flags = (short) (value ? flags | CHANGED : flags & ~CHANGED);
+    }
+
+    final boolean hasDefaults() {
+        return (flags & HASDEFAULTS) != 0;
+    }
+
+    final void hasDefaults(boolean value) {
+        flags = (short) (value ? flags | HASDEFAULTS : flags & ~HASDEFAULTS);
+    }
+
+    /**
+     * 
+     * From org.apache.xerces.dom.NamedNodeMapImpl
+     * 
+     * Subroutine: Locates the named item, or the point at which said item
+     * should be added.
+     * 
+     * @param name
+     *            Name of a node to look up.
+     * 
+     * @return If positive or zero, the index of the found item. If negative,
+     *         index of the appropriate point at which to insert the item,
+     *         encoded as -1-index and hence reconvertable by subtracting it
+     *         from -1. (Encoding because I don't want to recompare the strings
+     *         but don't want to burn bytes on a datatype to hold a flagged
+     *         value.)
+     */
+    protected int findNamePoint(String name, int start) {
+
+        // Binary search
+        int i = 0;
+        if (nodes != null) {
+            int first = start;
+            int last = nodes.size() - 1;
+
+            while (first <= last) {
+                i = (first + last) / 2;
+                int test = name.compareTo(((Node) (nodes.elementAt(i)))
+                        .getNodeName());
+                if (test == 0) {
+                    return i; // Name found
+                } else if (test < 0) {
+                    last = i - 1;
+                } else {
+                    first = i + 1;
+                }
+            }
+
+            if (first > i) {
+                i = first;
+            }
+        }
+
+        return -1 - i; // not-found has to be encoded.
+
+    } // findNamePoint(String):int
+
+    /**
+     * This findNamePoint is for DOM Level 2 Namespaces.
+     */
+    protected int findNamePoint(String namespaceURI, String name) {
+
+        if (nodes == null)
+            return -1;
+        if (name == null)
+            return -1;
+
+        // This is a linear search through the same nodes Vector.
+        // The Vector is sorted on the DOM Level 1 nodename.
+        // The DOM Level 2 NS keys are namespaceURI and Localname,
+        // so we must linear search thru it.
+        // In addition, to get this to work with nodes without any namespace
+        // (namespaceURI and localNames are both null) we then use the nodeName
+        // as a seconday key.
+        for (int i = 0; i < nodes.size(); i++) {
+            NodeImpl a = (NodeImpl) nodes.elementAt(i);
+            String aNamespaceURI = a.getNamespaceURI();
+            String aLocalName = a.getLocalName();
+            if (namespaceURI == null) {
+                if (aNamespaceURI == null && (name.equals(aLocalName) || 
+                        (aLocalName == null && name.equals(a.getNodeName()))))
+                    return i;
+            } else {
+                if (namespaceURI.equals(aNamespaceURI)
+                        && name.equals(aLocalName))
+                    return i;
+            }
+        }
+        return -1;
+    }
+
+    // Compare 2 nodes in the map. If a precedes b, return true, otherwise
+    // return false
+    protected boolean precedes(Node a, Node b) {
+
+        if (nodes != null) {
+            for (int i = 0; i < nodes.size(); i++) {
+                Node n = (Node) nodes.elementAt(i);
+                if (n == a)
+                    return true;
+                if (n == b)
+                    return false;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * NON-DOM: Remove attribute at specified index.
+     */
+    protected void removeItem(int index) {
+        if (nodes != null && index < nodes.size()) {
+            nodes.removeElementAt(index);
+        }
+    }
+
+    protected Object getItem(int index) {
+        if (nodes != null) {
+            return nodes.elementAt(index);
+        }
+        return null;
+    }
+
+    protected int addItem(Node arg) {
+        int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
+        if (i >= 0) {
+            nodes.setElementAt(arg, i);
+        } else {
+            // If we can't find by namespaceURI, localName, then we find by
+            // nodeName so we know where to insert.
+            i = findNamePoint(arg.getNodeName(), 0);
+            if (i >= 0) {
+                nodes.insertElementAt(arg, i);
+            } else {
+                i = -1 - i; // Insert point (may be end of list)
+                if (null == nodes) {
+                    nodes = new Vector(5, 10);
+                }
+                nodes.insertElementAt(arg, i);
+            }
+        }
+        return i;
+    }
+
+    /**
+     * NON-DOM: copy content of this map into the specified vector
+     * 
+     * @param list
+     *            Vector to copy information into.
+     * @return Returns a copy of this node named map.
+     */
+    protected Vector cloneMap(Vector list) {
+        if (list == null) {
+            list = new Vector(5, 10);
+        }
+        list.setSize(0);
+        if (nodes != null) {
+            for (int i = 0; i < nodes.size(); i++) {
+                list.insertElementAt(nodes.elementAt(i), i);
+            }
+        }
+
+        return list;
+    }
+
+    protected int getNamedItemIndex(String namespaceURI, String localName) {
+        return findNamePoint(namespaceURI, localName);
+    }
+
+    /**
+     * NON-DOM remove all elements from this map.
+     */
+    public void removeAll() {
+        if (nodes != null) {
+            nodes.removeAllElements();
+        }
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,63 @@
+/*
+ * 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.dom;
+
+import org.apache.ws.commons.om.OMNamespace;
+
+public class NamespaceImpl implements OMNamespace {
+
+    private String nsUri;
+
+    private String nsPrefix;
+
+    public NamespaceImpl(String uri) {
+        this.nsUri = uri;
+    }
+
+    public NamespaceImpl(String uri, String prefix) {
+        this.nsUri = uri;
+        this.nsPrefix = prefix;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNamespace#equals(java.lang.String,
+     *      java.lang.String)
+     */
+    public boolean equals(String uri, String prefix) {
+        return (this.nsUri == uri && this.nsPrefix == prefix);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNamespace#getPrefix()
+     */
+    public String getPrefix() {
+        return this.nsPrefix;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ws.commons.om.OMNamespace#getName()
+     */
+    public String getName() {
+        return this.nsUri;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,602 @@
+/*
+ * 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.dom;
+
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.OMOutputFormat;
+import org.apache.ws.commons.om.OMXMLParserWrapper;
+import org.apache.ws.commons.om.impl.OMNodeEx;
+import org.apache.ws.commons.om.impl.OMOutputImpl;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.UserDataHandler;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.OutputStream;
+import java.io.Writer;
+
+public abstract class NodeImpl implements Node, NodeList, OMNodeEx, Cloneable {
+
+    /**
+     * Field builder
+     */
+    protected OMXMLParserWrapper builder;
+
+    /**
+     * Field done
+     */
+    protected boolean done = false;
+
+    /**
+     * Field nodeType
+     */
+    protected int nodeType;
+
+    protected DocumentImpl ownerNode;
+
+    // data
+
+    protected short flags;
+
+    protected final static short OWNED = 0x1 << 1;
+
+    protected final static short FIRSTCHILD = 0x1 << 2;
+
+    protected final static short READONLY = 0x1 << 3;
+
+    protected final static short SPECIFIED = 0x1 << 4;
+
+    protected final static short NORMALIZED = 0x1 << 5;
+
+    //
+    // Constructors
+    //
+
+    protected NodeImpl(DocumentImpl ownerDocument) {
+
+        this.ownerNode = ownerDocument;
+        // this.isOwned(true);
+
+    }
+
+    protected NodeImpl() {
+    }
+
+    public void normalize() {
+        /*
+         * by default we do not have any children, ParentNode overrides this
+         * behavior
+         */
+    }
+
+    public boolean hasAttributes() {
+        return false; // overridden in ElementImpl
+    }
+
+    public boolean hasChildNodes() {
+        return false; // Override in ParentNode
+    }
+
+    public String getLocalName() {
+        return null; // Override in AttrImpl and ElementImpl
+    }
+
+    public String getNamespaceURI() {
+        return null; // Override in AttrImpl and ElementImpl
+    }
+
+    public String getNodeValue() throws DOMException {
+        return null;
+    }
+
+    /*
+     * Overidden in ElementImpl and AttrImpl.
+     */
+    public String getPrefix() {
+        return null;
+    }
+
+    public void setNodeValue(String arg0) throws DOMException {
+        // Don't do anything, to be overridden in SOME Child classes
+    }
+
+    public void setPrefix(String prefix) throws DOMException {
+        throw new DOMException(DOMException.NAMESPACE_ERR, DOMMessageFormatter
+                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR",
+                        null));
+    }
+
+    /**
+     * Finds the document that this Node belongs to (the document in whose
+     * context the Node was created). The Node may or may not
+     */
+    public Document getOwnerDocument() {
+        return (Document) this.ownerNode;
+    }
+
+    /**
+     * Returns the collection of attributes associated with this node, or null
+     * if none. At this writing, Element is the only type of node which will
+     * ever have attributes.
+     * 
+     * @see ElementImpl
+     */
+    public NamedNodeMap getAttributes() {
+        return null; // overridden in ElementImpl
+    }
+
+    /**
+     * Gets the first child of this Node, or null if none.
+     * <P>
+     * By default we do not have any children, ParentNode overrides this.
+     * 
+     * @see ParentNode
+     */
+    public Node getFirstChild() {
+        return null;
+    }
+
+    /**
+     * Gets the last child of this Node, or null if none.
+     * <P>
+     * By default we do not have any children, ParentNode overrides this.
+     * 
+     * @see ParentNode
+     */
+    public Node getLastChild() {
+        return null;
+    }
+
+    /** Returns the next child of this node's parent, or null if none. */
+    public Node getNextSibling() {
+        return null; // default behavior, overriden in ChildNode
+    }
+
+    public Node getParentNode() {
+        return null; // overriden by ChildNode
+        // Document, DocumentFragment, and Attribute will never have parents.
+    }
+
+    /*
+     * Same as getParentNode but returns internal type NodeImpl.
+     */
+    NodeImpl parentNode() {
+        return null;
+    }
+
+    /** Returns the previous child of this node's parent, or null if none. */
+    public Node getPreviousSibling() {
+        return null; // default behavior, overriden in ChildNode
+    }
+
+    // public Node cloneNode(boolean deep) {
+    // if(this instanceof OMElement) {
+    // return (Node)((OMElement)this).cloneOMElement();
+    // } else if(this instanceof OMText ){
+    // return ((TextImpl)this).cloneText();
+    // } else {
+    // throw new UnsupportedOperationException("Only elements can be cloned
+    // right now");
+    // }
+    // }
+    //    
+    public Node cloneNode(boolean deep) {
+        NodeImpl newnode;
+        try {
+            newnode = (NodeImpl) clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException("**Internal Error**" + e);
+        }
+        newnode.ownerNode = this.ownerNode;
+        newnode.isOwned(false);
+
+        newnode.isReadonly(false);
+
+        return newnode;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#getChildNodes()
+     */
+    public NodeList getChildNodes() {
+        return this;
+    }
+
+    public boolean isSupported(String feature, String version) {
+        throw new UnsupportedOperationException();
+        // TODO
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
+     */
+    public Node appendChild(Node newChild) throws DOMException {
+        return insertBefore(newChild, null);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
+     */
+    public Node removeChild(Node oldChild) throws DOMException {
+        throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
+                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR",
+                        null));
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
+     */
+    public Node insertBefore(Node newChild, Node refChild) throws DOMException {
+        // Overridden in ParentNode
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
+     */
+    public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+    }
+
+    //
+    // NodeList methods
+    //
+
+    /**
+     * NodeList method: Returns the number of immediate children of this node.
+     * <P>
+     * By default we do not have any children, ParentNode overrides this.
+     * 
+     * @see ParentNode
+     * 
+     * @return Returns int.
+     */
+    public int getLength() {
+        return 0;
+    }
+
+    /**
+     * NodeList method: Returns the Nth immediate child of this node, or null if
+     * the index is out of bounds.
+     * <P>
+     * By default we do not have any children, ParentNode overrides this.
+     * 
+     * @see ParentNode
+     * 
+     * @return Returns org.w3c.dom.Node
+     * @param index
+     */
+    public Node item(int index) {
+        return null;
+    }
+
+    /*
+     * Flags setters and getters
+     */
+
+    final boolean isOwned() {
+        return (flags & OWNED) != 0;
+    }
+
+    final void isOwned(boolean value) {
+        flags = (short) (value ? flags | OWNED : flags & ~OWNED);
+    }
+
+    final boolean isFirstChild() {
+        return (flags & FIRSTCHILD) != 0;
+    }
+
+    final void isFirstChild(boolean value) {
+        flags = (short) (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
+    }
+
+    final boolean isReadonly() {
+        return (flags & READONLY) != 0;
+    }
+
+    final void isReadonly(boolean value) {
+        flags = (short) (value ? flags | READONLY : flags & ~READONLY);
+    }
+
+    final boolean isSpecified() {
+        return (flags & SPECIFIED) != 0;
+    }
+
+    final void isSpecified(boolean value) {
+        flags = (short) (value ? flags | SPECIFIED : flags & ~SPECIFIED);
+    }
+
+    final boolean isNormalized() {
+        return (flags & NORMALIZED) != 0;
+    }
+
+    final void isNormalized(boolean value) {
+        // See if flag should propagate to parent.
+        if (!value && isNormalized() && ownerNode != null) {
+            ownerNode.isNormalized(false);
+        }
+        flags = (short) (value ? flags | NORMALIZED : flags & ~NORMALIZED);
+    }
+
+    // /
+    // /OM Methods
+    // /
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNode#getParent()
+     */
+    public OMContainer getParent() throws OMException {
+        return null; // overriden by ChildNode
+        // Document, DocumentFragment, and Attribute will never have parents.
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNode#isComplete()
+     */
+    public boolean isComplete() {
+        return this.done;
+    }
+
+    public void setComplete(boolean state) {
+        this.done = state;
+
+    }
+
+    /**
+     * There no concept of caching in this OM-DOM implementation.
+     */
+    public void serializeWithCache(OMOutputImpl omOutput)
+            throws XMLStreamException {
+        this.serialize(omOutput);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNode#insertSiblingAfter
+     * (org.apache.axis2.om.OMNode)
+     */
+    public void insertSiblingAfter(OMNode sibling) throws OMException {
+        // Overridden in ChildNode
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNode#insertSiblingBefore
+     * (org.apache.axis2.om.OMNode)
+     */
+    public void insertSiblingBefore(OMNode sibling) throws OMException {
+        // Overridden in ChildNode
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+
+    }
+
+    /**
+     * Default behavior returns null, overriden in ChildNode.
+     */
+    public OMNode getPreviousOMSibling() {
+        return null;
+    }
+
+    /**
+     * Default behavior returns null, overriden in ChildNode.
+     */
+    public OMNode getNextOMSibling() {
+        return null;
+    }
+
+    public void setPreviousOMSibling(OMNode previousSibling) {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+    }
+
+    public void setNextOMSibling(OMNode previousSibling) {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        "HIERARCHY_REQUEST_ERR", null));
+    }
+
+    /**
+     * Builds next element.
+     */
+    public void build() {
+        while (!done)
+            this.builder.next();
+    }
+
+    /**
+     * Sets the owner document.
+     * 
+     * @param document
+     */
+    protected void setOwnerDocument(DocumentImpl document) {
+        this.ownerNode = document;
+        this.isOwned(true);
+    }
+
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serialize(omOutput);
+        omOutput.flush();
+    }
+
+    public void serializeAndConsume(XMLStreamWriter xmlWriter)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serializeAndConsume(omOutput);
+        omOutput.flush();
+    }
+
+    public OMNode detach() {
+        throw new OMException(
+                "Elements that doesn't have a parent can not be detached");
+    }
+
+    /*
+     * DOM-Level 3 methods
+     */
+
+    public String getBaseURI() {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public short compareDocumentPosition(Node arg0) throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public String getTextContent() throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public void setTextContent(String arg0) throws DOMException {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public boolean isSameNode(Node arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public String lookupPrefix(String arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public boolean isDefaultNamespace(String arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public String lookupNamespaceURI(String arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public boolean isEqualNode(Node arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public Object getFeature(String arg0, String arg1) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public Object getUserData(String arg0) {
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public void serialize(OutputStream output) throws XMLStreamException {
+        serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
+    }
+
+    public void serialize(Writer writer) throws XMLStreamException {
+        serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+    }
+
+    public void serializeAndConsume(OutputStream output)
+            throws XMLStreamException {
+        serializeAndConsume(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(output));
+    }
+
+    public void serializeAndConsume(Writer writer) throws XMLStreamException {
+        serializeAndConsume(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
+    }
+
+    public void serialize(OutputStream output, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(output, format);
+        serialize(omOutput);
+        omOutput.flush();
+    }
+
+    public void serialize(Writer writer, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
+        omOutput.setOutputFormat(format);
+        serialize(omOutput);
+        omOutput.flush();
+    }
+
+    public void serializeAndConsume(OutputStream output, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(output, format);
+        serializeAndConsume(omOutput);
+        omOutput.flush();
+    }
+
+    public void serializeAndConsume(Writer writer, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
+        omOutput.setOutputFormat(format);
+        serializeAndConsume(omOutput);
+        omOutput.flush();
+    }
+}

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,131 @@
+/*
+ * 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.dom;
+
+import org.apache.ws.commons.om.impl.OMContainerEx;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * Implementation of org.w3c.dom.NodeList
+ */
+public class NodeListImpl implements NodeList {
+
+    protected NodeImpl rootNode;
+
+    protected String tagName;
+
+    protected Vector nodes;
+
+    protected String nsName;
+
+    protected boolean enableNS = false;
+
+    /** Constructor. */
+    public NodeListImpl(NodeImpl rootNode, String tagName) {
+        this.rootNode = rootNode;
+        this.tagName = (tagName != null && !tagName.equals("")) ? tagName
+                : null;
+        nodes = new Vector();
+    }
+
+    /** Constructor for Namespace support. */
+    public NodeListImpl(NodeImpl rootNode, String namespaceURI, 
+                                                    String localName) {
+        this(rootNode, localName);
+        this.nsName = (namespaceURI != null && !namespaceURI.equals("")) 
+                       ? namespaceURI
+                       : null;
+        if (this.nsName != null) {
+            enableNS = true;
+        }
+    }
+
+    /**
+     * Returns the number of nodes.
+     * 
+     * @see org.w3c.dom.NodeList#getLength()
+     */
+    public int getLength() {
+        Iterator children;
+        if (this.tagName == null) {
+            children = ((OMContainerEx) rootNode).getChildren();
+        } else if (!enableNS) {
+            children = ((OMContainerEx) rootNode)
+                    .getChildrenWithName(new QName(this.tagName));
+        } else {
+            if (DOMUtil.getPrefix(this.tagName) != null) {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName), DOMUtil
+                                .getPrefix(this.tagName)));
+            } else {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName)));
+            }
+        }
+        int count = 0;
+        while (children.hasNext()) {
+            count++;
+            children.next();
+        }
+        return count;
+    }
+
+    /**
+     * Returns the node at the given index. Returns null if the index is
+     * invalid.
+     * 
+     * @see org.w3c.dom.NodeList#item(int)
+     */
+    public Node item(int index) {
+        Iterator children;
+
+        if (this.tagName == null) {
+            children = ((OMContainerEx) rootNode).getChildren();
+        } else if (!enableNS) {
+            children = ((OMContainerEx) rootNode)
+                    .getChildrenWithName(new QName(this.tagName));
+        } else {
+            if (DOMUtil.getPrefix(this.tagName) != null) {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName), DOMUtil
+                                .getPrefix(this.tagName)));
+            } else {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName)));
+            }
+        }
+
+        int count = 0;
+        while (children.hasNext()) {
+            if (count == index) {
+                return (Node) children.next();
+            } else {
+                children.next();
+            }
+            count++;
+        }
+        return null;
+    }
+}

Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/OMDOMException.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/OMDOMException.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/OMDOMException.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/OMDOMException.java Wed Feb  1 00:58:23 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.dom;
+
+import org.apache.ws.commons.om.OMException;
+/**
+ * OMDOM specific exception
+ */
+public class OMDOMException extends OMException {
+
+	private static final long serialVersionUID = 8763119035210190906L;
+
+	public OMDOMException() {
+		super();
+	}
+
+	public OMDOMException(String arg0) {
+		super(arg0);
+	}
+
+	public OMDOMException(Throwable arg0) {
+		super(arg0);
+	}
+
+	public OMDOMException(String arg0, Throwable arg1) {
+		super(arg0, arg1);
+	}
+
+}