package org.jboss.axis.message;
import org.jboss.axis.AxisFault;
import org.jboss.axis.Constants;
import org.jboss.axis.MessagePart;
import org.jboss.axis.utils.XMLUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.UserDataHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.SOAPException;
public class SOAPDocumentImpl implements Document
{
Document delegate = null;
MessagePart soapPart = null;
public SOAPDocumentImpl(MessagePart sp)
{
try
{
delegate = XMLUtils.newDocument();
}
catch (ParserConfigurationException e)
{
}
soapPart = sp;
}
public DocumentType getDoctype()
{
return delegate.getDoctype();
}
public DOMImplementation getImplementation()
{
return delegate.getImplementation();
}
public Element getDocumentElement()
{
return soapPart.getDocumentElement();
}
public org.w3c.dom.Element createElement(String tagName)
throws DOMException
{
int index = tagName.indexOf(":");
String prefix, localname;
if (index < 0)
{
prefix = "";
localname = tagName;
}
else
{
prefix = tagName.substring(0, index);
localname = tagName.substring(index + 1);
}
try
{
SOAPEnvelopeAxisImpl soapenv =
(org.jboss.axis.message.SOAPEnvelopeAxisImpl)soapPart.getEnvelope();
if (soapenv != null)
{
if (tagName.equalsIgnoreCase(Constants.ELEM_ENVELOPE))
new SOAPEnvelopeAxisImpl();
if (tagName.equalsIgnoreCase(Constants.ELEM_HEADER))
return new SOAPHeaderAxisImpl(soapenv, soapenv.getSOAPConstants());
if (tagName.equalsIgnoreCase(Constants.ELEM_BODY))
return new SOAPBodyAxisImpl(soapenv, soapenv.getSOAPConstants());
if (tagName.equalsIgnoreCase(Constants.ELEM_FAULT))
return new SOAPEnvelopeAxisImpl();
if (tagName.equalsIgnoreCase(Constants.ELEM_FAULT_DETAIL))
return new SOAPFaultImpl(new AxisFault(tagName));
else
{
return new SOAPElementAxisImpl("", prefix, localname);
}
}
else
{
return new SOAPElementAxisImpl("", prefix, localname);
}
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public DocumentFragment createDocumentFragment()
{
return delegate.createDocumentFragment();
}
public org.w3c.dom.Text createTextNode(String data)
{
return new TextImpl(delegate.createTextNode(data));
}
public Comment createComment(String data)
{
return new CommentImpl(createTextNode(data));
}
public CDATASection createCDATASection(String data) throws DOMException
{
return new CDATAImpl(createTextNode(data));
}
public ProcessingInstruction createProcessingInstruction(String target,
String data)
throws DOMException
{
throw new java.lang.UnsupportedOperationException("createProcessingInstruction");
}
public Attr createAttribute(String name) throws DOMException
{
return delegate.createAttribute(name);
}
public EntityReference createEntityReference(String name)
throws DOMException
{
throw new java.lang.UnsupportedOperationException("createEntityReference");
}
public Node importNode(Node importedNode, boolean deep)
throws DOMException
{
throw new java.lang.UnsupportedOperationException("importNode");
}
public Element createElementNS(String namespaceURI, String qualifiedName)
throws DOMException
{
org.jboss.axis.soap.SOAPConstants soapConstants = null;
if (Constants.URI_SOAP11_ENV.equals(namespaceURI))
{
soapConstants = org.jboss.axis.soap.SOAPConstants.SOAP11_CONSTANTS;
}
else if (Constants.URI_SOAP12_ENV.equals(namespaceURI))
{
soapConstants = org.jboss.axis.soap.SOAPConstants.SOAP12_CONSTANTS;
}
SOAPElementAxisImpl me = null;
if (soapConstants != null)
{
if (qualifiedName.equals(Constants.ELEM_ENVELOPE))
{
me = new SOAPEnvelopeAxisImpl(soapConstants);
}
else if (qualifiedName.equals(Constants.ELEM_HEADER))
{
me = new SOAPHeaderAxisImpl(null, soapConstants);
}
else if (qualifiedName.equals(Constants.ELEM_BODY))
{
me = new SOAPBodyAxisImpl(null, soapConstants);
}
else if (qualifiedName.equals(Constants.ELEM_FAULT))
{
me = null;
}
else if (qualifiedName.equals(Constants.ELEM_FAULT_DETAIL))
{
me = null;
}
else
{
throw new DOMException(DOMException.INVALID_STATE_ERR,
"No such Localname for SOAP URI");
}
return null;
}
else
{
me = new SOAPElementAxisImpl(namespaceURI, qualifiedName);
}
if (me != null)
me.setOwnerDocument(soapPart);
return me;
}
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
throws DOMException
{
return delegate.createAttributeNS(namespaceURI, qualifiedName);
}
public NodeList getElementsByTagNameNS(String namespaceURI,
String localName)
{
try
{
if (soapPart != null)
{
SOAPEnvelopeAxisImpl soapEnv =
(org.jboss.axis.message.SOAPEnvelopeAxisImpl)soapPart
.getEnvelope();
SOAPHeaderAxisImpl header =
(org.jboss.axis.message.SOAPHeaderAxisImpl)soapEnv.getHeader();
if (header != null)
{
return header.getElementsByTagNameNS(namespaceURI,
localName);
}
SOAPBodyAxisImpl body =
(org.jboss.axis.message.SOAPBodyAxisImpl)soapEnv.getHeader();
if (body != null)
{
return header.getElementsByTagNameNS(namespaceURI,
localName);
}
}
return null;
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public NodeList getElementsByTagName(String localName)
{
try
{
if (soapPart != null)
{
SOAPEnvelopeAxisImpl soapEnv =
(org.jboss.axis.message.SOAPEnvelopeAxisImpl)soapPart
.getEnvelope();
SOAPHeaderAxisImpl header =
(org.jboss.axis.message.SOAPHeaderAxisImpl)soapEnv.getHeader();
if (header != null)
{
return header.getElementsByTagName(localName);
}
SOAPBodyAxisImpl body =
(org.jboss.axis.message.SOAPBodyAxisImpl)soapEnv.getHeader();
if (body != null)
{
return header.getElementsByTagName(localName);
}
}
return null;
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public Element getElementById(String elementId)
{
return delegate.getElementById(elementId);
}
public String getNodeName()
{
return null;
}
public String getNodeValue() throws DOMException
{
throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR,
"Cannot use TextNode.get in " + this);
}
public void setNodeValue(String nodeValue) throws DOMException
{
throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR,
"Cannot use TextNode.set in " + this);
}
public short getNodeType()
{
return Node.DOCUMENT_NODE;
}
public Node getParentNode()
{
return null;
}
public NodeList getChildNodes()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public Node getFirstChild()
{
try
{
if (soapPart != null)
return (org.jboss.axis.message.SOAPEnvelopeAxisImpl)soapPart
.getEnvelope();
else
return null;
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public Node getLastChild()
{
try
{
if (soapPart != null)
return (org.jboss.axis.message.SOAPEnvelopeAxisImpl)soapPart
.getEnvelope();
else
return null;
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public Node getPreviousSibling()
{
return null;
}
public Node getNextSibling()
{
return null;
}
public NamedNodeMap getAttributes()
{
return null;
}
public Document getOwnerDocument()
{
return null;
}
public Node insertBefore(Node newChild, Node refChild)
throws DOMException
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public Node replaceChild(Node newChild, Node oldChild)
throws DOMException
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public Node removeChild(Node oldChild) throws DOMException
{
try
{
Node envNode;
if (soapPart != null)
{
envNode = soapPart.getEnvelope();
if (envNode.equals(oldChild))
{
return envNode;
}
}
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public Node appendChild(Node newChild) throws DOMException
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public boolean hasChildNodes()
{
try
{
if (soapPart != null)
{
if (soapPart.getEnvelope() != null)
{
return true;
}
}
return false;
}
catch (SOAPException se)
{
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
}
public Node cloneNode(boolean deep)
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public void normalize()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
private String[] features = {"foo", "bar"};
private String version = "version 2.0";
public boolean isSupported(String feature, String version)
{
if (!version.equalsIgnoreCase(version))
return false;
else
return true;
}
public String getPrefix()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public void setPrefix(String prefix)
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public String getNamespaceURI()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public void setNamespaceURI(String nsURI)
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public String getLocalName()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public boolean hasAttributes()
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public String getInputEncoding()
{
return null;
}
public String getXmlEncoding()
{
return null;
}
public boolean getXmlStandalone()
{
return false;
}
public void setXmlStandalone(boolean xmlStandalone) throws DOMException
{
}
public String getXmlVersion()
{
return null;
}
public void setXmlVersion(String xmlVersion) throws DOMException
{
}
public boolean getStrictErrorChecking()
{
return false;
}
public void setStrictErrorChecking(boolean strictErrorChecking)
{
}
public String getDocumentURI()
{
return null;
}
public void setDocumentURI(String documentURI)
{
}
public Node adoptNode(Node source) throws DOMException
{
return null;
}
public DOMConfiguration getDomConfig()
{
return null;
}
public void normalizeDocument()
{
}
public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException
{
return null;
}
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;
}
}