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

Mon, 04 May 2009 21:10:41 -0700

author
tbell
date
Mon, 04 May 2009 21:10:41 -0700
changeset 50
42dfec6871f6
parent 45
31822b475baa
child 78
860b95cc8d1d
permissions
-rw-r--r--

6658158: Mutable statics in SAAJ (findbugs)
6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs)
Reviewed-by: darcy

     1 /*
     2  * Copyright 2005-2006 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 /*
    26  *
    27  */
    31 /**
    32 *
    33 * @author SAAJ RI Development Team
    34 */
    35 package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
    37 import java.util.logging.Logger;
    38 import java.util.Locale;
    40 import javax.xml.namespace.QName;
    41 import javax.xml.soap.*;
    43 import org.w3c.dom.Node;
    45 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    46 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
    47 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    48 import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
    49 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    51 public class Body1_2Impl extends BodyImpl {
    53     protected static  final Logger log =
    54         Logger.getLogger(Body1_2Impl.class.getName(),
    55                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
    57     public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
    58             super(ownerDocument, NameImpl.createBody1_2Name(prefix));
    59     }
    61     protected NameImpl getFaultName(String name) {
    62         return NameImpl.createFault1_2Name(name, null);
    63     }
    65     protected SOAPBodyElement createBodyElement(Name name) {
    66         return new BodyElement1_2Impl(
    67             ((SOAPDocument) getOwnerDocument()).getDocument(),
    68             name);
    69     }
    70     protected SOAPBodyElement createBodyElement(QName name) {
    71         return new BodyElement1_2Impl(
    72             ((SOAPDocument) getOwnerDocument()).getDocument(),
    73             name);
    74     }
    76     protected QName getDefaultFaultCode() {
    77         return SOAPConstants.SOAP_RECEIVER_FAULT;
    78     }
    80     public SOAPFault addFault() throws SOAPException {
    81         if (hasAnyChildElement()) {
    82             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
    83             throw new SOAPExceptionImpl(
    84                 "No other element except Fault allowed in SOAPBody");
    85         }
    86         return super.addFault();
    87     }
    89     /*
    90      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
    91      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
    92      */
    93     public void setEncodingStyle(String encodingStyle) throws SOAPException {
    94         log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
    95         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
    96     }
    98     /*
    99      * Override addAttribute of ElementImpl to restrict adding encodingStyle
   100      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
   101      */
   102     public SOAPElement addAttribute(Name name, String value)
   103         throws SOAPException {
   104         if (name.getLocalName().equals("encodingStyle")
   105             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   107             setEncodingStyle(value);
   108         }
   109         return super.addAttribute(name, value);
   110     }
   112     public SOAPElement addAttribute(QName name, String value)
   113         throws SOAPException {
   114         if (name.getLocalPart().equals("encodingStyle")
   115             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   117             setEncodingStyle(value);
   118         }
   119         return super.addAttribute(name, value);
   120     }
   122     protected boolean isFault(SOAPElement child) {
   123         return (child.getElementName().getURI().equals(
   124                     SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
   125                 child.getElementName().getLocalName().equals(
   126                     "Fault"));
   127     }
   129     protected SOAPFault createFaultElement() {
   130         return new Fault1_2Impl(
   131             ((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
   132     }
   134     /*
   135      * section 5.4 of SOAP1.2 candidate recommendation says that a
   136      * SOAP message MUST contain a single Fault element as the only
   137      * child element of the SOAP Body.
   138      */
   139     public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
   140         if (hasFault()) {
   141             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   142             throw new SOAPExceptionImpl(
   143                 "No other element except Fault allowed in SOAPBody");
   144         }
   145         return super.addBodyElement(name);
   146     }
   148     public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
   149         if (hasFault()) {
   150             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   151             throw new SOAPExceptionImpl(
   152                 "No other element except Fault allowed in SOAPBody");
   153         }
   154         return super.addBodyElement(name);
   155     }
   157     protected SOAPElement addElement(Name name) throws SOAPException {
   158         if (hasFault()) {
   159             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   160             throw new SOAPExceptionImpl(
   161                 "No other element except Fault allowed in SOAPBody");
   162         }
   163         return super.addElement(name);
   164     }
   166     protected SOAPElement addElement(QName name) throws SOAPException {
   167         if (hasFault()) {
   168             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   169             throw new SOAPExceptionImpl(
   170                 "No other element except Fault allowed in SOAPBody");
   171         }
   172         return super.addElement(name);
   173     }
   175     public SOAPElement addChildElement(Name name) throws SOAPException {
   176         if (hasFault()) {
   177             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   178             throw new SOAPExceptionImpl(
   179                 "No other element except Fault allowed in SOAPBody");
   180         }
   181         return super.addChildElement(name);
   182     }
   184     public SOAPElement addChildElement(QName name) throws SOAPException {
   185         if (hasFault()) {
   186             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   187             throw new SOAPExceptionImpl(
   188                 "No other element except Fault allowed in SOAPBody");
   189         }
   190         return super.addChildElement(name);
   191     }
   193     private boolean hasAnyChildElement() {
   194         Node currentNode = getFirstChild();
   195         while (currentNode != null) {
   196             if (currentNode.getNodeType() == Node.ELEMENT_NODE)
   197                 return true;
   198             currentNode = currentNode.getNextSibling();
   199         }
   200         return false;
   201     }
   202 }

mercurial