package org.jboss.axis.message;
import org.jboss.logging.Logger;
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.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import java.util.ArrayList;
import java.util.List;
public class NodeImpl implements javax.xml.soap.Node
{
private static Logger log = Logger.getLogger(NodeImpl.class.getName());
protected SOAPElementImpl soapParent;
protected org.w3c.dom.Node domNode;
private List soapChildren = new ArrayList();
NodeImpl(org.w3c.dom.Node node)
{
if (node.getNodeName().startsWith(":"))
throw new IllegalArgumentException("Illegal node name: " + node.getNodeName());
this.domNode = node;
}
public void detachNode()
{
assertSOAPParent();
org.w3c.dom.Node parent = domNode.getParentNode();
if (parent != null)
{
parent.removeChild(domNode);
((NodeImpl)soapParent).soapChildren.remove(this);
if (soapParent instanceof SOAPElementAxisImpl)
{
((SOAPElementAxisImpl)soapParent).removeChild(this);
}
soapParent = null;
}
}
public SOAPElement getParentElement()
{
return soapParent;
}
public void setParentElement(SOAPElement parent) throws SOAPException
{
if (soapParent != null)
detachNode();
soapParent = (SOAPElementImpl)parent;
}
public String getValue()
{
if (this instanceof javax.xml.soap.Text)
throw new IllegalStateException("javax.xml.soap.Text should take care of this");
org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild();
if (child instanceof org.w3c.dom.Text)
return ((org.w3c.dom.Text)child).getNodeValue();
return null;
}
public void setValue(String value)
{
if (this instanceof javax.xml.soap.Text)
throw new IllegalStateException("javax.xml.soap.Text should take care of this");
org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild();
if (child instanceof org.w3c.dom.Text)
((org.w3c.dom.Text)child).setNodeValue(value);
if (child == null && value != null)
{
child = domNode.getOwnerDocument().createTextNode(value);
appendChild(new TextImpl(child));
}
}
public void recycleNode()
{
}
public String getNodeName()
{
return domNode.getNodeName();
}
public String getNodeValue() throws DOMException
{
return domNode.getNodeValue();
}
public void setNodeValue(String nodeValue) throws DOMException
{
domNode.setNodeValue(nodeValue);
}
public short getNodeType()
{
return domNode.getNodeType();
}
public org.w3c.dom.Node getParentNode()
{
assertSOAPParent();
return domNode.getParentNode();
}
public NodeList getChildNodes()
{
return domNode.getChildNodes();
}
public org.w3c.dom.Node getFirstChild()
{
return domNode.getFirstChild();
}
public org.w3c.dom.Node getLastChild()
{
return domNode.getLastChild();
}
public org.w3c.dom.Node getPreviousSibling()
{
return domNode.getPreviousSibling();
}
public org.w3c.dom.Node getNextSibling()
{
return domNode.getNextSibling();
}
public NamedNodeMap getAttributes()
{
return domNode.getAttributes();
}
public Document getOwnerDocument()
{
return domNode.getOwnerDocument();
}
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException
{
assertSOAPNode(newChild);
assertSOAPNode(refChild);
int index = soapChildren.indexOf(refChild);
if (index < 0)
throw new IllegalArgumentException("Cannot find refChild in list of javax.xml.soap.Node children");
NodeImpl soapNewNode = (NodeImpl)newChild;
NodeImpl soapRefNode = (NodeImpl)refChild;
domNode.insertBefore(soapNewNode.domNode, soapRefNode.domNode);
soapChildren.add(index, soapNewNode);
return newChild;
}
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException
{
assertSOAPNode(newChild);
assertSOAPNode(oldChild);
int index = soapChildren.indexOf(oldChild);
if (index < 0)
throw new DOMException(DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children");
NodeImpl soapNewNode = (NodeImpl)newChild;
NodeImpl soapOldNode = (NodeImpl)oldChild;
domNode.replaceChild(soapNewNode.domNode, soapOldNode.domNode);
soapChildren.remove(index);
soapChildren.add(index, soapNewNode);
return newChild;
}
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException
{
assertSOAPNode(oldChild);
int index = soapChildren.indexOf(oldChild);
if (index < 0)
throw new DOMException(DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children");
NodeImpl soapOldNode = (NodeImpl)oldChild;
domNode.removeChild(soapOldNode.domNode);
soapChildren.remove(index);
return oldChild;
}
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException
{
assertSOAPNode(newChild);
if ((this instanceof SOAPElementImpl) == false)
throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Cannot append child to this node: " + this);
NodeImpl soapNode = (NodeImpl)newChild;
domNode.appendChild(soapNode.domNode);
soapNode.soapParent = (SOAPElementImpl)this;
soapChildren.add(soapNode);
return newChild;
}
public boolean hasChildNodes()
{
return domNode.hasChildNodes();
}
public org.w3c.dom.Node cloneNode(boolean deep)
{
NodeImpl soapNode = new NodeImpl(domNode.cloneNode(deep));
if (deep == true)
{
for (int i = 0; i < soapChildren.size(); i++)
{
NodeImpl node = (NodeImpl)soapChildren.get(i);
soapNode.soapChildren.add(node.cloneNode(deep));
}
}
return soapNode;
}
public void normalize()
{
domNode.normalize();
}
public boolean isSupported(String feature, String version)
{
return domNode.isSupported(feature, version);
}
public String getNamespaceURI()
{
return domNode.getNamespaceURI();
}
public String getPrefix()
{
return domNode.getPrefix();
}
public void setPrefix(String prefix) throws DOMException
{
domNode.setPrefix(prefix);
}
public String getLocalName()
{
return domNode.getLocalName();
}
public boolean hasAttributes()
{
return domNode.hasAttributes();
}
public int hashCode()
{
return domNode.hashCode();
}
public String toString()
{
return super.toString() + "[" + domNode.toString() + "]";
}
private void assertSOAPNode(org.w3c.dom.Node node)
{
if ((node instanceof NodeImpl) == false)
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Operation only supported for javax.xml.soap.Node, this is a " + node);
}
private void assertSOAPParent()
{
org.w3c.dom.Node domParent = domNode.getParentNode();
if (domParent != null && soapParent == null)
throw new IllegalStateException("Inconsistent node, has a DOM parent but no SOAP parent: " + this);
if (domParent == null && soapParent != null)
throw new IllegalStateException("Inconsistent node, has a SOAP parent but no DOM parent: " + this);
}
public String getBaseURI()
{
return null;
}
public short compareDocumentPosition(Node other) throws DOMException
{
return 0;
}
public String getTextContent() throws DOMException
{
return null;
}
public void setTextContent(String textContent) throws DOMException
{
}
public boolean isSameNode(Node other)
{
return false;
}
public String lookupPrefix(String namespaceURI)
{
return null;
}
public boolean isDefaultNamespace(String namespaceURI)
{
return false;
}
public String lookupNamespaceURI(String prefix)
{
return null;
}
public boolean isEqualNode(Node arg)
{
return false;
}
public Object getFeature(String feature, String version)
{
return null;
}
public Object setUserData(String key, Object data, UserDataHandler handler)
{
return null;
}
public Object getUserData(String key)
{
return null;
}
}