src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ver1_2/Envelope1_2Impl.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, 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  */
    26 /**
    27 *
    28 * @author SAAJ RI Development Team
    29 */
    30 package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
    32 import java.util.logging.Logger;
    33 import java.util.logging.Level;
    35 import javax.xml.namespace.QName;
    36 import javax.xml.soap.*;
    38 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    39 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    40 import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
    41 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    43 public class Envelope1_2Impl extends EnvelopeImpl {
    45     protected static final Logger log =
    46         Logger.getLogger(Envelope1_2Impl.class.getName(),
    47                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
    49     public Envelope1_2Impl(SOAPDocumentImpl ownerDoc, String prefix) {
    50         super(ownerDoc, NameImpl.createEnvelope1_2Name(prefix));
    51     }
    53     public Envelope1_2Impl(
    54         SOAPDocumentImpl ownerDoc,
    55         String prefix,
    56         boolean createHeader,
    57         boolean createBody)
    58         throws SOAPException {
    59         super(
    60             ownerDoc,
    61             NameImpl.createEnvelope1_2Name(prefix),
    62             createHeader,
    63             createBody);
    64     }
    66     protected NameImpl getBodyName(String prefix) {
    67         return NameImpl.createBody1_2Name(prefix);
    68     }
    70     protected NameImpl getHeaderName(String prefix) {
    71         return NameImpl.createHeader1_2Name(prefix);
    72     }
    74     /*
    75      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
    76      * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
    77      */
    78     public void setEncodingStyle(String encodingStyle) throws SOAPException {
    79         log.severe("SAAJ0404.ver1_2.no.encodingStyle.in.envelope");
    80         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Envelope");
    81     }
    83     /*
    84      * Override addAttribute of ElementImpl to restrict adding encodingStyle
    85      * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
    86      */
    87     public SOAPElement addAttribute(Name name, String value)
    88         throws SOAPException {
    89         if (name.getLocalName().equals("encodingStyle")
    90             && name.getURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
    91             setEncodingStyle(value);
    92         }
    93         return super.addAttribute(name, value);
    94     }
    96     public SOAPElement addAttribute(QName name, String value)
    97         throws SOAPException {
    98         if (name.getLocalPart().equals("encodingStyle")
    99             && name.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
   100             setEncodingStyle(value);
   101         }
   102         return super.addAttribute(name, value);
   103     }
   106     /*
   107      * Override addChildElement method to ensure that no element
   108      * is added after body in SOAP 1.2.
   109      */
   110     public SOAPElement addChildElement(Name name) throws SOAPException {
   111         // check if body already exists
   112         if (getBody() != null) {
   113             log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
   114             throw new SOAPExceptionImpl(
   115                 "Body must be the last element in" + " SOAP Envelope");
   116         }
   117         return super.addChildElement(name);
   118     }
   120     public SOAPElement addChildElement(QName name) throws SOAPException {
   121         // check if body already exists
   122         if (getBody() != null) {
   123             log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
   124             throw new SOAPExceptionImpl(
   125                 "Body must be the last element in" + " SOAP Envelope");
   126         }
   127         return super.addChildElement(name);
   128     }
   131     /*
   132      * Ideally we should be overriding other addChildElement() methods as well
   133      * but we are not adding them here since internally all those call the
   134      * method addChildElement(Name name).
   135      * In future, if this behaviour changes, then we would need to override
   136      * all the rest of them as well.
   137      *
   138      */
   140     public SOAPElement addTextNode(String text) throws SOAPException {
   141         log.log(
   142             Level.SEVERE,
   143             "SAAJ0416.ver1_2.adding.text.not.legal",
   144             getElementQName());
   145         throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Envelope is not legal");
   146     }
   147 }

mercurial