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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
0961a4a21176
child 45
31822b475baa
permissions
-rw-r--r--

Initial load

     1 /*
     2  * $Id: Body1_2Impl.java,v 1.32 2006/01/27 12:49:44 vj135062 Exp $
     3  */
     5 /*
     6  * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
     7  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8  *
     9  * This code is free software; you can redistribute it and/or modify it
    10  * under the terms of the GNU General Public License version 2 only, as
    11  * published by the Free Software Foundation.  Sun designates this
    12  * particular file as subject to the "Classpath" exception as provided
    13  * by Sun in the LICENSE file that accompanied this code.
    14  *
    15  * This code is distributed in the hope that it will be useful, but WITHOUT
    16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    17  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    18  * version 2 for more details (a copy is included in the LICENSE file that
    19  * accompanied this code).
    20  *
    21  * You should have received a copy of the GNU General Public License version
    22  * 2 along with this work; if not, write to the Free Software Foundation,
    23  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    24  *
    25  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    26  * CA 95054 USA or visit www.sun.com if you need additional information or
    27  * have any questions.
    28  */
    30 /**
    31 *
    32 * @author SAAJ RI Development Team
    33 */
    34 package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
    36 import java.util.logging.Logger;
    37 import java.util.Locale;
    39 import javax.xml.namespace.QName;
    40 import javax.xml.soap.*;
    42 import org.w3c.dom.Node;
    44 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    45 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
    46 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    47 import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
    48 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    50 public class Body1_2Impl extends BodyImpl {
    52     protected static Logger log =
    53         Logger.getLogger(Body1_2Impl.class.getName(),
    54                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
    56     public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
    57             super(ownerDocument, NameImpl.createBody1_2Name(prefix));
    58     }
    60     protected NameImpl getFaultName(String name) {
    61         return NameImpl.createFault1_2Name(name, null);
    62     }
    64     protected SOAPBodyElement createBodyElement(Name name) {
    65         return new BodyElement1_2Impl(
    66             ((SOAPDocument) getOwnerDocument()).getDocument(),
    67             name);
    68     }
    69     protected SOAPBodyElement createBodyElement(QName name) {
    70         return new BodyElement1_2Impl(
    71             ((SOAPDocument) getOwnerDocument()).getDocument(),
    72             name);
    73     }
    75     protected QName getDefaultFaultCode() {
    76         return SOAPConstants.SOAP_RECEIVER_FAULT;
    77     }
    79     public SOAPFault addFault() throws SOAPException {
    80         if (hasAnyChildElement()) {
    81             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
    82             throw new SOAPExceptionImpl(
    83                 "No other element except Fault allowed in SOAPBody");
    84         }
    85         return super.addFault();
    86     }
    88     /*
    89      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
    90      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
    91      */
    92     public void setEncodingStyle(String encodingStyle) throws SOAPException {
    93         log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
    94         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
    95     }
    97     /*
    98      * Override addAttribute of ElementImpl to restrict adding encodingStyle
    99      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
   100      */
   101     public SOAPElement addAttribute(Name name, String value)
   102         throws SOAPException {
   103         if (name.getLocalName().equals("encodingStyle")
   104             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   106             setEncodingStyle(value);
   107         }
   108         return super.addAttribute(name, value);
   109     }
   111     public SOAPElement addAttribute(QName name, String value)
   112         throws SOAPException {
   113         if (name.getLocalPart().equals("encodingStyle")
   114             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
   116             setEncodingStyle(value);
   117         }
   118         return super.addAttribute(name, value);
   119     }
   121     protected boolean isFault(SOAPElement child) {
   122         return (child.getElementName().getURI().equals(
   123                     SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
   124                 child.getElementName().getLocalName().equals(
   125                     "Fault"));
   126     }
   128     protected SOAPFault createFaultElement() {
   129         return new Fault1_2Impl(
   130             ((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
   131     }
   133     /*
   134      * section 5.4 of SOAP1.2 candidate recommendation says that a
   135      * SOAP message MUST contain a single Fault element as the only
   136      * child element of the SOAP Body.
   137      */
   138     public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
   139         if (hasFault()) {
   140             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   141             throw new SOAPExceptionImpl(
   142                 "No other element except Fault allowed in SOAPBody");
   143         }
   144         return super.addBodyElement(name);
   145     }
   147     public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
   148         if (hasFault()) {
   149             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   150             throw new SOAPExceptionImpl(
   151                 "No other element except Fault allowed in SOAPBody");
   152         }
   153         return super.addBodyElement(name);
   154     }
   156     protected SOAPElement addElement(Name name) throws SOAPException {
   157         if (hasFault()) {
   158             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   159             throw new SOAPExceptionImpl(
   160                 "No other element except Fault allowed in SOAPBody");
   161         }
   162         return super.addElement(name);
   163     }
   165     protected SOAPElement addElement(QName name) throws SOAPException {
   166         if (hasFault()) {
   167             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   168             throw new SOAPExceptionImpl(
   169                 "No other element except Fault allowed in SOAPBody");
   170         }
   171         return super.addElement(name);
   172     }
   174     public SOAPElement addChildElement(Name name) throws SOAPException {
   175         if (hasFault()) {
   176             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   177             throw new SOAPExceptionImpl(
   178                 "No other element except Fault allowed in SOAPBody");
   179         }
   180         return super.addChildElement(name);
   181     }
   183     public SOAPElement addChildElement(QName name) throws SOAPException {
   184         if (hasFault()) {
   185             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
   186             throw new SOAPExceptionImpl(
   187                 "No other element except Fault allowed in SOAPBody");
   188         }
   189         return super.addChildElement(name);
   190     }
   192     private boolean hasAnyChildElement() {
   193         Node currentNode = getFirstChild();
   194         while (currentNode != null) {
   195             if (currentNode.getNodeType() == Node.ELEMENT_NODE)
   196                 return true;
   197             currentNode = currentNode.getNextSibling();
   198         }
   199         return false;
   200     }
   201 }

mercurial