jaxws/src/java.xml.soap/share/classes/com/sun/xml/internal/messaging/saaj/soap/SOAPDocumentImpl.java
changeset 28644 a70f5680dbab
parent 28643 a665e19ca007
parent 28642 a42fefc69922
child 28647 f44908f03772
equal deleted inserted replaced
28643:a665e19ca007 28644:a70f5680dbab
     1 /*
       
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 /**
       
    27 *
       
    28 * @author SAAJ RI Development Team
       
    29 */
       
    30 package com.sun.xml.internal.messaging.saaj.soap;
       
    31 
       
    32 import java.util.logging.Logger;
       
    33 
       
    34 import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
       
    35 import org.w3c.dom.*;
       
    36 
       
    37 import com.sun.xml.internal.messaging.saaj.soap.impl.*;
       
    38 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
       
    39 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
       
    40 
       
    41 public class SOAPDocumentImpl extends DocumentImpl implements SOAPDocument {
       
    42 
       
    43     private static final String XMLNS = "xmlns".intern();
       
    44     protected static final Logger log =
       
    45         Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
       
    46                          "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
       
    47 
       
    48     SOAPPartImpl enclosingSOAPPart;
       
    49 
       
    50     public SOAPDocumentImpl(SOAPPartImpl enclosingDocument) {
       
    51         this.enclosingSOAPPart = enclosingDocument;
       
    52     }
       
    53 
       
    54     //    public SOAPDocumentImpl(boolean grammarAccess) {
       
    55     //        super(grammarAccess);
       
    56     //    }
       
    57     //
       
    58     //    public SOAPDocumentImpl(DocumentType doctype) {
       
    59     //        super(doctype);
       
    60     //    }
       
    61     //
       
    62     //    public SOAPDocumentImpl(DocumentType doctype, boolean grammarAccess) {
       
    63     //        super(doctype, grammarAccess);
       
    64     //    }
       
    65 
       
    66     public SOAPPartImpl getSOAPPart() {
       
    67         if (enclosingSOAPPart == null) {
       
    68             log.severe("SAAJ0541.soap.fragment.not.bound.to.part");
       
    69             throw new RuntimeException("Could not complete operation. Fragment not bound to SOAP part.");
       
    70         }
       
    71         return enclosingSOAPPart;
       
    72     }
       
    73 
       
    74     public SOAPDocumentImpl getDocument() {
       
    75         return this;
       
    76     }
       
    77 
       
    78     public DocumentType getDoctype() {
       
    79         // SOAP means no DTD, No DTD means no doctype (SOAP 1.2 only?)
       
    80         return null;
       
    81     }
       
    82 
       
    83     public DOMImplementation getImplementation() {
       
    84         return super.getImplementation();
       
    85     }
       
    86 
       
    87     public Element getDocumentElement() {
       
    88         // This had better be an Envelope!
       
    89         getSOAPPart().doGetDocumentElement();
       
    90         return doGetDocumentElement();
       
    91     }
       
    92 
       
    93     protected Element doGetDocumentElement() {
       
    94         return super.getDocumentElement();
       
    95     }
       
    96 
       
    97     public Element createElement(String tagName) throws DOMException {
       
    98         return ElementFactory.createElement(
       
    99             this,
       
   100             NameImpl.getLocalNameFromTagName(tagName),
       
   101             NameImpl.getPrefixFromTagName(tagName),
       
   102             null);
       
   103     }
       
   104 
       
   105     public DocumentFragment createDocumentFragment() {
       
   106         return new SOAPDocumentFragment(this);
       
   107     }
       
   108 
       
   109     public org.w3c.dom.Text createTextNode(String data) {
       
   110         return new SOAPTextImpl(this, data);
       
   111     }
       
   112 
       
   113     public Comment createComment(String data) {
       
   114         return new SOAPCommentImpl(this, data);
       
   115     }
       
   116 
       
   117     public CDATASection createCDATASection(String data) throws DOMException {
       
   118         return new CDATAImpl(this, data);
       
   119     }
       
   120 
       
   121     public ProcessingInstruction createProcessingInstruction(
       
   122         String target,
       
   123         String data)
       
   124         throws DOMException {
       
   125         log.severe("SAAJ0542.soap.proc.instructions.not.allowed.in.docs");
       
   126         throw new UnsupportedOperationException("Processing Instructions are not allowed in SOAP documents");
       
   127     }
       
   128 
       
   129     public Attr createAttribute(String name) throws DOMException {
       
   130         boolean isQualifiedName = (name.indexOf(":") > 0);
       
   131         if (isQualifiedName) {
       
   132             String nsUri = null;
       
   133             String prefix = name.substring(0, name.indexOf(":"));
       
   134             //cannot do anything to resolve the URI if prefix is not
       
   135             //XMLNS.
       
   136             if (XMLNS.equals(prefix)) {
       
   137                 nsUri = ElementImpl.XMLNS_URI;
       
   138                 return createAttributeNS(nsUri, name);
       
   139             }
       
   140         }
       
   141 
       
   142         return super.createAttribute(name);
       
   143     }
       
   144 
       
   145     public EntityReference createEntityReference(String name)
       
   146         throws DOMException {
       
   147             log.severe("SAAJ0543.soap.entity.refs.not.allowed.in.docs");
       
   148             throw new UnsupportedOperationException("Entity References are not allowed in SOAP documents");
       
   149     }
       
   150 
       
   151     public NodeList getElementsByTagName(String tagname) {
       
   152         return super.getElementsByTagName(tagname);
       
   153     }
       
   154 
       
   155     public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
       
   156         throws DOMException {
       
   157         return super.importNode(importedNode, deep);
       
   158     }
       
   159 
       
   160     public Element createElementNS(String namespaceURI, String qualifiedName)
       
   161         throws DOMException {
       
   162         return ElementFactory.createElement(
       
   163             this,
       
   164             NameImpl.getLocalNameFromTagName(qualifiedName),
       
   165             NameImpl.getPrefixFromTagName(qualifiedName),
       
   166             namespaceURI);
       
   167     }
       
   168 
       
   169     public Attr createAttributeNS(String namespaceURI, String qualifiedName)
       
   170         throws DOMException {
       
   171         return super.createAttributeNS(namespaceURI, qualifiedName);
       
   172     }
       
   173 
       
   174     public NodeList getElementsByTagNameNS(
       
   175         String namespaceURI,
       
   176         String localName) {
       
   177         return super.getElementsByTagNameNS(namespaceURI, localName);
       
   178     }
       
   179 
       
   180     public Element getElementById(String elementId) {
       
   181         return super.getElementById(elementId);
       
   182     }
       
   183 
       
   184     public Node cloneNode(boolean deep) {
       
   185         SOAPPartImpl newSoapPart = getSOAPPart().doCloneNode();
       
   186         super.cloneNode(newSoapPart.getDocument(), deep);
       
   187         return newSoapPart;
       
   188     }
       
   189 
       
   190     public void cloneNode(SOAPDocumentImpl newdoc, boolean deep) {
       
   191         super.cloneNode(newdoc, deep);
       
   192     }
       
   193 }