FileDocCategorySizeDatePackage
SOAPDocumentImpl.javaAPI DocApache Axis 1.421895Sat Apr 22 18:57:28 BST 2006org.apache.axis.message

SOAPDocumentImpl

public class SOAPDocumentImpl extends Object implements Document, Serializable
SOAPDcoumentImpl implements the Document API for SOAPPART. At the moment, it again delgate the XERCES DOM Implementation Here is my argument on it: I guess that there is 3 way to implement this. - fully implement the DOM API here myself. => This is too much and duplicated work. - extends XERCES Implementation => this makes we are fixed to one Implementation - choose delgate depends on the user's parser preference => This is the practically best solution I have now
author
Heejune Ahn (cityboy@tmax.co.kr)

Fields Summary
protected Document
delegate
protected org.apache.axis.SOAPPart
soapPart
private String[]
features
private String
version
Constructors Summary
public SOAPDocumentImpl(org.apache.axis.SOAPPart sp)
Construct the Document

param
sp the soap part


                  
       
        try {
            delegate = XMLUtils.newDocument();
        } catch (ParserConfigurationException e) {
            // Do nothing
        }
        soapPart = sp;
    
Methods Summary
public org.w3c.dom.NodeappendChild(org.w3c.dom.Node newChild)

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public org.w3c.dom.NodecloneNode(boolean deep)

todo:
Study it more.... to implement the deep mode correctly.

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public org.w3c.dom.AttrcreateAttribute(java.lang.String name)

todo:
How Axis will maintain the Attribute representation ?

        return delegate.createAttribute(name);
    
public org.w3c.dom.AttrcreateAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
Attribute is not particularly dealt with in SAAJ.

        return delegate.createAttributeNS(namespaceURI, qualifiedName);
    
public org.w3c.dom.CDATASectioncreateCDATASection(java.lang.String data)
Creates a CDATASection node whose value is the specified string.

param
data The data for the CDATASection contents.
return
The new CDATASection object.
exception
DOMException NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

        return new CDATAImpl(data);
    
public org.w3c.dom.CommentcreateComment(java.lang.String data)
Creates a Comment node given the specified string.

param
data The data for the node.
return
The new Comment object.

        return new org.apache.axis.message.CommentImpl(data);
    
public org.w3c.dom.DocumentFragmentcreateDocumentFragment()
Creates an empty DocumentFragment object. @todo not implemented yet

return
A new DocumentFragment.

        return delegate.createDocumentFragment();
    
public org.w3c.dom.ElementcreateElement(java.lang.String tagName)
based on the tagName, we will make different kind SOAP Elements Instance Is really we can determine the Type by the Tagname???

todo
: verify this method
param
tagName
return
@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 {
            SOAPEnvelope soapenv =
                (org.apache.axis.message.SOAPEnvelope) soapPart.getEnvelope();
            if (soapenv != null) {
                if (tagName.equalsIgnoreCase(Constants.ELEM_ENVELOPE))
                    new SOAPEnvelope();
                if (tagName.equalsIgnoreCase(Constants.ELEM_HEADER))
                    return new SOAPHeader(soapenv, soapenv.getSOAPConstants());
                if (tagName.equalsIgnoreCase(Constants.ELEM_BODY))
                    return new SOAPBody(soapenv, soapenv.getSOAPConstants());
                if (tagName.equalsIgnoreCase(Constants.ELEM_FAULT))
                    return new SOAPEnvelope();
                if (tagName.equalsIgnoreCase(Constants.ELEM_FAULT_DETAIL))
                    return new SOAPFault(new AxisFault(tagName));
                else {
                    return new MessageElement("", prefix, localname);
                }
            } else {
                return new MessageElement("", prefix, localname);
            }

        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }
    
public org.w3c.dom.ElementcreateElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
Return SOAPElements (what if they want SOAPEnvelope or Header/Body?)

param
namespaceURI
param
qualifiedName
return
@throws DOMException

        org.apache.axis.soap.SOAPConstants soapConstants = null;
        if (Constants.URI_SOAP11_ENV.equals(namespaceURI)) {
            soapConstants = org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS;
        } else if (Constants.URI_SOAP12_ENV.equals(namespaceURI)) {
            soapConstants = org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS;
        }

        // For special SOAP Element
        MessageElement me = null;
        if (soapConstants != null) {
            if (qualifiedName.equals(Constants.ELEM_ENVELOPE)) {
                // TODO: confirm SOAP 1.1!
                me = new SOAPEnvelope(soapConstants); 
            } else if (qualifiedName.equals(Constants.ELEM_HEADER)) {
                me = new SOAPHeader(null, soapConstants);
                // Dummy SOAPEnv required?
            } else if (qualifiedName.equals(Constants.ELEM_BODY)) {
                me = new SOAPBody(null, soapConstants);
            } else if (qualifiedName.equals(Constants.ELEM_FAULT)) {
                me = null;
            } else if (qualifiedName.equals(Constants.ELEM_FAULT_DETAIL)) {
                // TODO:
                me = null;
            } else {
                throw new DOMException(
                        DOMException.INVALID_STATE_ERR,
                "No such Localname for SOAP URI");
            }
            // TODO:
            return null;
            // general Elements
        } else {
            me = new MessageElement(namespaceURI, qualifiedName);
        }

        if (me != null)
            me.setOwnerDocument(soapPart);

        return me;

    
public org.w3c.dom.EntityReferencecreateEntityReference(java.lang.String name)

param
name
return
@throws DOMException

        throw new java.lang.UnsupportedOperationException(
        "createEntityReference");
    
public org.w3c.dom.ProcessingInstructioncreateProcessingInstruction(java.lang.String target, java.lang.String data)
Creates a ProcessingInstruction node given the specified name and data strings.

param
target The target part of the processing instruction.
param
data The data for the node.
return
The new ProcessingInstruction object.
exception
DOMException INVALID_CHARACTER_ERR: Raised if the specified target contains an illegal character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

        throw new java.lang.UnsupportedOperationException(
        "createProcessingInstruction");
    
public org.w3c.dom.TextcreateTextNode(java.lang.String data)
Creates a Text node given the specified string.

param
data The data for the node.
return
The new Text object.

        org.apache.axis.message.Text me =
            new org.apache.axis.message.Text(delegate.createTextNode(data));
        me.setOwnerDocument(soapPart);
        return me;

    
public org.w3c.dom.NamedNodeMapgetAttributes()

        return null;
    
public org.w3c.dom.NodeListgetChildNodes()

        try {
            if (soapPart != null) {
                NodeListImpl children = new NodeListImpl();
                children.addNode(soapPart.getEnvelope());
                return children;
            } else {
                return NodeListImpl.EMPTY_NODELIST;
            }
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }

    
public org.w3c.dom.DocumentTypegetDoctype()

todo
: link with SOAP
return

        return delegate.getDoctype();
    
public org.w3c.dom.ElementgetDocumentElement()
should not be called, the method will be handled in SOAPPart

return

        return soapPart.getDocumentElement();
    
public org.w3c.dom.ElementgetElementById(java.lang.String elementId)
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID. The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.

param
elementId The unique id value for an element.
return
The matching element.
since
DOM Level 2

        return delegate.getElementById(elementId);
    
public org.w3c.dom.NodeListgetElementsByTagName(java.lang.String localName)
search the SOAPPart in order of SOAPHeader and SOAPBody for the requested Element name


        try {
            NodeListImpl list = new NodeListImpl();
            if (soapPart != null) {
                SOAPEnvelope soapEnv =
                    (org.apache.axis.message.SOAPEnvelope) soapPart
                    .getEnvelope();
                SOAPHeader header =
                    (org.apache.axis.message.SOAPHeader) soapEnv.getHeader();
                if (header != null) {
                    list.addNodeList(header.getElementsByTagName(localName));
                }
                SOAPBody body =
                    (org.apache.axis.message.SOAPBody) soapEnv.getBody();
                if (body != null) {
                    list.addNodeList(body.getElementsByTagName(localName));
                }
            }
            return list;
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }
    
public org.w3c.dom.NodeListgetElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
search the SOAPPart in order of SOAPHeader and SOAPBody for the requested Element name

        try {
        	NodeListImpl list = new NodeListImpl();
            if (soapPart != null) {
                SOAPEnvelope soapEnv =
                    (org.apache.axis.message.SOAPEnvelope) soapPart
                    .getEnvelope();
                SOAPHeader header =
                    (org.apache.axis.message.SOAPHeader) soapEnv.getHeader();
                if (header != null) {
                	list.addNodeList(header.getElementsByTagNameNS(
                            namespaceURI,
                            localName));
                }
                SOAPBody body =
                    (org.apache.axis.message.SOAPBody) soapEnv.getBody();
                if (body != null) {
                	list.addNodeList(body.getElementsByTagNameNS(
                            namespaceURI,
                            localName));
                }
            }
            return list;
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }
    
public org.w3c.dom.NodegetFirstChild()
Do we have to count the Attributes as node ????

return

        try {
            if (soapPart != null)
                return (org.apache.axis.message.SOAPEnvelope) soapPart
                .getEnvelope();
            else
                return null;
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }

    
public org.w3c.dom.DOMImplementationgetImplementation()

        return delegate.getImplementation();
    
public org.w3c.dom.NodegetLastChild()

return

        try {
            if (soapPart != null)
                return (org.apache.axis.message.SOAPEnvelope) soapPart
                .getEnvelope();
            else
                return null;
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }

    
public java.lang.StringgetLocalName()

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public java.lang.StringgetNamespaceURI()

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public org.w3c.dom.NodegetNextSibling()


        return null;
    
public java.lang.StringgetNodeName()
Node Implementation

        return null;
    
public shortgetNodeType()
override it in sub-classes

return

        return Node.DOCUMENT_NODE;
    
public java.lang.StringgetNodeValue()

        throw new DOMException(
                DOMException.NO_DATA_ALLOWED_ERR,
                "Cannot use TextNode.get in " + this);
    
public org.w3c.dom.DocumentgetOwnerDocument()
we have to have a link to them...

        return null;
    
public org.w3c.dom.NodegetParentNode()

        return null;
    
public java.lang.StringgetPrefix()

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public org.w3c.dom.NodegetPreviousSibling()

        return null;
    
public booleanhasAttributes()

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public booleanhasChildNodes()

        try {
            if (soapPart != null) {
                if (soapPart.getEnvelope() != null) {
                    return true;
                }
            }
            return false;
        } catch (SOAPException se) {
            throw new DOMException(DOMException.INVALID_STATE_ERR, "");
        }

    
public org.w3c.dom.NodeimportNode(org.w3c.dom.Node importedNode, boolean deep)

    	Node targetNode = null;
    
    	int type = importedNode.getNodeType();
    	switch (type) {
    	case ELEMENT_NODE :
    	    Element el = (Element) importedNode;
    	    if (deep) {
        		targetNode = new SOAPBodyElement(el);
        		break;
    	    }
    
    	    SOAPBodyElement target = new SOAPBodyElement();
    	    org.w3c.dom.NamedNodeMap attrs = el.getAttributes();
    	    for (int i = 0; i < attrs.getLength(); i++) {
        		org.w3c.dom.Node att = attrs.item(i);
        		if (att.getNamespaceURI() != null &&
        		    att.getPrefix() != null &&
        		    att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) &&
        		    att.getPrefix().equals("xmlns")) {
        		    Mapping map = new Mapping(att.getNodeValue(), att.getLocalName());
        		    target.addMapping(map);
        		}
        		if (att.getLocalName() != null) {
        		    target.addAttribute(att.getPrefix(),
        					att.getNamespaceURI(),
        					att.getLocalName(),
        					att.getNodeValue());
        		} else if (att.getNodeName() != null) {
        		    target.addAttribute(att.getPrefix(),
        					att.getNamespaceURI(),
        					att.getNodeName(),
        					att.getNodeValue());
        		}
    	    }
    
    	    if (el.getLocalName() == null) {
    	        target.setName(el.getNodeName());
    	    } else {
    	        target.setQName(new QName(el.getNamespaceURI(), el.getLocalName()));
    	    }
    	    targetNode = target;
    	    break;
    
    	case ATTRIBUTE_NODE :
    	    if (importedNode.getLocalName() == null) {
    	        targetNode = createAttribute(importedNode.getNodeName());
    	    } else {
    	        targetNode = createAttributeNS(importedNode.getNamespaceURI(),
    					       importedNode.getLocalName());
    	    }
    	    break;
    
    	case TEXT_NODE :
    	    targetNode = createTextNode(importedNode.getNodeValue());
    	    break;
    
    	case CDATA_SECTION_NODE :
    	    targetNode = createCDATASection(importedNode.getNodeValue());
    	    break;
    
    	case COMMENT_NODE :
    	    targetNode = createComment(importedNode.getNodeValue());
    	    break;
    
    	case DOCUMENT_FRAGMENT_NODE :
    	    targetNode = createDocumentFragment();
    	    if (deep) {
        		org.w3c.dom.NodeList children = importedNode.getChildNodes();
        		for (int i = 0; i < children.getLength(); i++){
        		    targetNode.appendChild(importNode(children.item(i), true));
        		}
    	    }
    	    break;
    
    	case ENTITY_REFERENCE_NODE :
    	    targetNode = createEntityReference(importedNode.getNodeName());
    	    break;
    
    	case PROCESSING_INSTRUCTION_NODE :
    	    ProcessingInstruction pi = (ProcessingInstruction) importedNode;
    	    targetNode = createProcessingInstruction(pi.getTarget(), pi.getData());
    	    break;
    
    	case ENTITY_NODE :
    	    // TODO : ...
    	    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Entity nodes are not supported.");
    
    	case NOTATION_NODE :
    	    // TODO : any idea?
    	    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Notation nodes are not supported.");
    
    	case DOCUMENT_TYPE_NODE :
    	    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DocumentType nodes cannot be imported.");
    
    	case DOCUMENT_NODE :
    	    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Document nodes cannot be imported.");
    
    	default :
    	    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Node type (" + type + ") cannot be imported.");
    	}
    
    	return targetNode;
    
public org.w3c.dom.NodeinsertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public booleanisSupported(java.lang.String feature, java.lang.String version)


          
        if (!version.equalsIgnoreCase(version))
            return false;
        else
            return true;
    
public voidnormalize()

todo:
is it OK to simply call the superclass?

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public org.w3c.dom.NoderemoveChild(org.w3c.dom.Node oldChild)

        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 org.w3c.dom.NodereplaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public voidsetNamespaceURI(java.lang.String nsURI)

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    
public voidsetNodeValue(java.lang.String nodeValue)

        throw new DOMException(
                DOMException.NO_DATA_ALLOWED_ERR,
                "Cannot use TextNode.set in " + this);
    
public voidsetPrefix(java.lang.String prefix)

        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");