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

Sun, 15 Dec 2013 23:35:45 +0100

author
mkos
date
Sun, 15 Dec 2013 23:35:45 +0100
changeset 494
2fcd3ddb57a6
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025152: Enhance activation set up
8028388: 9 jaxws tests failed in nightly build with java.lang.ClassCastException
Summary: fix also reviewed by Bill Shannon, Alexander Fomin
Reviewed-by: dfuchs, hawtin, mgrebac
Contributed-by: bill.shannon@oracle.com

     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.Locale;
    35 import javax.xml.namespace.QName;
    36 import javax.xml.soap.*;
    38 import org.w3c.dom.Node;
    40 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    41 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
    42 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    43 import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
    44 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    46 public class Body1_2Impl extends BodyImpl {
    48     protected static final Logger log =
    49         Logger.getLogger(Body1_2Impl.class.getName(),
    50                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
    52     public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
    53             super(ownerDocument, NameImpl.createBody1_2Name(prefix));
    54     }
    56     protected NameImpl getFaultName(String name) {
    57         return NameImpl.createFault1_2Name(name, null);
    58     }
    60     protected SOAPBodyElement createBodyElement(Name name) {
    61         return new BodyElement1_2Impl(
    62             ((SOAPDocument) getOwnerDocument()).getDocument(),
    63             name);
    64     }
    65     protected SOAPBodyElement createBodyElement(QName name) {
    66         return new BodyElement1_2Impl(
    67             ((SOAPDocument) getOwnerDocument()).getDocument(),
    68             name);
    69     }
    71     protected QName getDefaultFaultCode() {
    72         return SOAPConstants.SOAP_RECEIVER_FAULT;
    73     }
    75     public SOAPFault addFault() throws SOAPException {
    76         if (hasAnyChildElement()) {
    77             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
    78             throw new SOAPExceptionImpl(
    79                 "No other element except Fault allowed in SOAPBody");
    80         }
    81         return super.addFault();
    82     }
    84     /*
    85      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
    86      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
    87      */
    88     public void setEncodingStyle(String encodingStyle) throws SOAPException {
    89         log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
    90         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
    91     }
    93     /*
    94      * Override addAttribute of ElementImpl to restrict adding encodingStyle
    95      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
    96      */
    97     public SOAPElement addAttribute(Name name, String value)
    98         throws SOAPException {
    99         if (name.getLocalName().equals("encodingStyle")
   100             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   102             setEncodingStyle(value);
   103         }
   104         return super.addAttribute(name, value);
   105     }
   107     public SOAPElement addAttribute(QName name, String value)
   108         throws SOAPException {
   109         if (name.getLocalPart().equals("encodingStyle")
   110             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   112             setEncodingStyle(value);
   113         }
   114         return super.addAttribute(name, value);
   115     }
   117     protected boolean isFault(SOAPElement child) {
   118         return (child.getElementName().getURI().equals(
   119                     SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
   120                 child.getElementName().getLocalName().equals(
   121                     "Fault"));
   122     }
   124     protected SOAPFault createFaultElement() {
   125         return new Fault1_2Impl(
   126             ((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
   127     }
   129     /*
   130      * section 5.4 of SOAP1.2 candidate recommendation says that a
   131      * SOAP message MUST contain a single Fault element as the only
   132      * child element of the SOAP Body.
   133      */
   134     public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
   135         if (hasFault()) {
   136             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   137             throw new SOAPExceptionImpl(
   138                 "No other element except Fault allowed in SOAPBody");
   139         }
   140         return super.addBodyElement(name);
   141     }
   143     public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
   144         if (hasFault()) {
   145             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   146             throw new SOAPExceptionImpl(
   147                 "No other element except Fault allowed in SOAPBody");
   148         }
   149         return super.addBodyElement(name);
   150     }
   152     protected SOAPElement addElement(Name name) throws SOAPException {
   153         if (hasFault()) {
   154             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   155             throw new SOAPExceptionImpl(
   156                 "No other element except Fault allowed in SOAPBody");
   157         }
   158         return super.addElement(name);
   159     }
   161     protected SOAPElement addElement(QName name) throws SOAPException {
   162         if (hasFault()) {
   163             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   164             throw new SOAPExceptionImpl(
   165                 "No other element except Fault allowed in SOAPBody");
   166         }
   167         return super.addElement(name);
   168     }
   170     public SOAPElement addChildElement(Name name) throws SOAPException {
   171         if (hasFault()) {
   172             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   173             throw new SOAPExceptionImpl(
   174                 "No other element except Fault allowed in SOAPBody");
   175         }
   176         return super.addChildElement(name);
   177     }
   179     public SOAPElement addChildElement(QName name) throws SOAPException {
   180         if (hasFault()) {
   181             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   182             throw new SOAPExceptionImpl(
   183                 "No other element except Fault allowed in SOAPBody");
   184         }
   185         return super.addChildElement(name);
   186     }
   188     private boolean hasAnyChildElement() {
   189         Node currentNode = getFirstChild();
   190         while (currentNode != null) {
   191             if (currentNode.getNodeType() == Node.ELEMENT_NODE)
   192                 return true;
   193             currentNode = currentNode.getNextSibling();
   194         }
   195         return false;
   196     }
   197 }

mercurial