jaxws/src/share/classes/com/sun/xml/internal/messaging/saaj/soap/ver1_2/Envelope1_2Impl.java
author tbell
Mon, 04 May 2009 21:10:41 -0700
changeset 2719 99d59312294b
parent 2678 57cf2a1c1a05
child 3530 18fb7507984b
permissions -rw-r--r--
6658158: Mutable statics in SAAJ (findbugs) 6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
474761f14bca Initial load
duke
parents:
diff changeset
     1
/*
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
8
474761f14bca Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474761f14bca Initial load
duke
parents:
diff changeset
     4
 *
474761f14bca Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
474761f14bca Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
474761f14bca Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
474761f14bca Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
474761f14bca Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
474761f14bca Initial load
duke
parents:
diff changeset
    10
 *
474761f14bca Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
474761f14bca Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474761f14bca Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
474761f14bca Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
474761f14bca Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
474761f14bca Initial load
duke
parents:
diff changeset
    16
 *
474761f14bca Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
474761f14bca Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
474761f14bca Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474761f14bca Initial load
duke
parents:
diff changeset
    20
 *
474761f14bca Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474761f14bca Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
474761f14bca Initial load
duke
parents:
diff changeset
    23
 * have any questions.
474761f14bca Initial load
duke
parents:
diff changeset
    24
 */
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
    25
/*
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    26
 *
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
    27
 */
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
    28
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
    29
8
474761f14bca Initial load
duke
parents:
diff changeset
    30
474761f14bca Initial load
duke
parents:
diff changeset
    31
/**
474761f14bca Initial load
duke
parents:
diff changeset
    32
*
474761f14bca Initial load
duke
parents:
diff changeset
    33
* @author SAAJ RI Development Team
474761f14bca Initial load
duke
parents:
diff changeset
    34
*/
474761f14bca Initial load
duke
parents:
diff changeset
    35
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
474761f14bca Initial load
duke
parents:
diff changeset
    36
474761f14bca Initial load
duke
parents:
diff changeset
    37
import java.util.logging.Logger;
474761f14bca Initial load
duke
parents:
diff changeset
    38
import java.util.logging.Level;
474761f14bca Initial load
duke
parents:
diff changeset
    39
474761f14bca Initial load
duke
parents:
diff changeset
    40
import javax.xml.namespace.QName;
474761f14bca Initial load
duke
parents:
diff changeset
    41
import javax.xml.soap.*;
474761f14bca Initial load
duke
parents:
diff changeset
    42
474761f14bca Initial load
duke
parents:
diff changeset
    43
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
474761f14bca Initial load
duke
parents:
diff changeset
    44
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
474761f14bca Initial load
duke
parents:
diff changeset
    45
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
474761f14bca Initial load
duke
parents:
diff changeset
    46
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
474761f14bca Initial load
duke
parents:
diff changeset
    47
474761f14bca Initial load
duke
parents:
diff changeset
    48
public class Envelope1_2Impl extends EnvelopeImpl {
474761f14bca Initial load
duke
parents:
diff changeset
    49
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    50
    protected static final Logger log =
8
474761f14bca Initial load
duke
parents:
diff changeset
    51
        Logger.getLogger(Envelope1_2Impl.class.getName(),
474761f14bca Initial load
duke
parents:
diff changeset
    52
                         "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
474761f14bca Initial load
duke
parents:
diff changeset
    53
474761f14bca Initial load
duke
parents:
diff changeset
    54
    public Envelope1_2Impl(SOAPDocumentImpl ownerDoc, String prefix) {
474761f14bca Initial load
duke
parents:
diff changeset
    55
        super(ownerDoc, NameImpl.createEnvelope1_2Name(prefix));
474761f14bca Initial load
duke
parents:
diff changeset
    56
    }
474761f14bca Initial load
duke
parents:
diff changeset
    57
474761f14bca Initial load
duke
parents:
diff changeset
    58
    public Envelope1_2Impl(
474761f14bca Initial load
duke
parents:
diff changeset
    59
        SOAPDocumentImpl ownerDoc,
474761f14bca Initial load
duke
parents:
diff changeset
    60
        String prefix,
474761f14bca Initial load
duke
parents:
diff changeset
    61
        boolean createHeader,
474761f14bca Initial load
duke
parents:
diff changeset
    62
        boolean createBody)
474761f14bca Initial load
duke
parents:
diff changeset
    63
        throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
    64
        super(
474761f14bca Initial load
duke
parents:
diff changeset
    65
            ownerDoc,
474761f14bca Initial load
duke
parents:
diff changeset
    66
            NameImpl.createEnvelope1_2Name(prefix),
474761f14bca Initial load
duke
parents:
diff changeset
    67
            createHeader,
474761f14bca Initial load
duke
parents:
diff changeset
    68
            createBody);
474761f14bca Initial load
duke
parents:
diff changeset
    69
    }
474761f14bca Initial load
duke
parents:
diff changeset
    70
474761f14bca Initial load
duke
parents:
diff changeset
    71
    protected NameImpl getBodyName(String prefix) {
474761f14bca Initial load
duke
parents:
diff changeset
    72
        return NameImpl.createBody1_2Name(prefix);
474761f14bca Initial load
duke
parents:
diff changeset
    73
    }
474761f14bca Initial load
duke
parents:
diff changeset
    74
474761f14bca Initial load
duke
parents:
diff changeset
    75
    protected NameImpl getHeaderName(String prefix) {
474761f14bca Initial load
duke
parents:
diff changeset
    76
        return NameImpl.createHeader1_2Name(prefix);
474761f14bca Initial load
duke
parents:
diff changeset
    77
    }
474761f14bca Initial load
duke
parents:
diff changeset
    78
474761f14bca Initial load
duke
parents:
diff changeset
    79
    /*
474761f14bca Initial load
duke
parents:
diff changeset
    80
     * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
474761f14bca Initial load
duke
parents:
diff changeset
    81
     * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
474761f14bca Initial load
duke
parents:
diff changeset
    82
     */
474761f14bca Initial load
duke
parents:
diff changeset
    83
    public void setEncodingStyle(String encodingStyle) throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
    84
        log.severe("SAAJ0404.ver1_2.no.encodingStyle.in.envelope");
474761f14bca Initial load
duke
parents:
diff changeset
    85
        throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Envelope");
474761f14bca Initial load
duke
parents:
diff changeset
    86
    }
474761f14bca Initial load
duke
parents:
diff changeset
    87
474761f14bca Initial load
duke
parents:
diff changeset
    88
    /*
474761f14bca Initial load
duke
parents:
diff changeset
    89
     * Override addAttribute of ElementImpl to restrict adding encodingStyle
474761f14bca Initial load
duke
parents:
diff changeset
    90
     * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
474761f14bca Initial load
duke
parents:
diff changeset
    91
     */
474761f14bca Initial load
duke
parents:
diff changeset
    92
    public SOAPElement addAttribute(Name name, String value)
474761f14bca Initial load
duke
parents:
diff changeset
    93
        throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
    94
        if (name.getLocalName().equals("encodingStyle")
474761f14bca Initial load
duke
parents:
diff changeset
    95
            && name.getURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
474761f14bca Initial load
duke
parents:
diff changeset
    96
            setEncodingStyle(value);
474761f14bca Initial load
duke
parents:
diff changeset
    97
        }
474761f14bca Initial load
duke
parents:
diff changeset
    98
        return super.addAttribute(name, value);
474761f14bca Initial load
duke
parents:
diff changeset
    99
    }
474761f14bca Initial load
duke
parents:
diff changeset
   100
474761f14bca Initial load
duke
parents:
diff changeset
   101
    public SOAPElement addAttribute(QName name, String value)
474761f14bca Initial load
duke
parents:
diff changeset
   102
        throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
   103
        if (name.getLocalPart().equals("encodingStyle")
474761f14bca Initial load
duke
parents:
diff changeset
   104
            && name.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
474761f14bca Initial load
duke
parents:
diff changeset
   105
            setEncodingStyle(value);
474761f14bca Initial load
duke
parents:
diff changeset
   106
        }
474761f14bca Initial load
duke
parents:
diff changeset
   107
        return super.addAttribute(name, value);
474761f14bca Initial load
duke
parents:
diff changeset
   108
    }
474761f14bca Initial load
duke
parents:
diff changeset
   109
474761f14bca Initial load
duke
parents:
diff changeset
   110
474761f14bca Initial load
duke
parents:
diff changeset
   111
    /*
474761f14bca Initial load
duke
parents:
diff changeset
   112
     * Override addChildElement method to ensure that no element
474761f14bca Initial load
duke
parents:
diff changeset
   113
     * is added after body in SOAP 1.2.
474761f14bca Initial load
duke
parents:
diff changeset
   114
     */
474761f14bca Initial load
duke
parents:
diff changeset
   115
    public SOAPElement addChildElement(Name name) throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
   116
        // check if body already exists
474761f14bca Initial load
duke
parents:
diff changeset
   117
        if (getBody() != null) {
474761f14bca Initial load
duke
parents:
diff changeset
   118
            log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
474761f14bca Initial load
duke
parents:
diff changeset
   119
            throw new SOAPExceptionImpl(
474761f14bca Initial load
duke
parents:
diff changeset
   120
                "Body must be the last element in" + " SOAP Envelope");
474761f14bca Initial load
duke
parents:
diff changeset
   121
        }
474761f14bca Initial load
duke
parents:
diff changeset
   122
        return super.addChildElement(name);
474761f14bca Initial load
duke
parents:
diff changeset
   123
    }
474761f14bca Initial load
duke
parents:
diff changeset
   124
474761f14bca Initial load
duke
parents:
diff changeset
   125
    public SOAPElement addChildElement(QName name) throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
   126
        // check if body already exists
474761f14bca Initial load
duke
parents:
diff changeset
   127
        if (getBody() != null) {
474761f14bca Initial load
duke
parents:
diff changeset
   128
            log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
474761f14bca Initial load
duke
parents:
diff changeset
   129
            throw new SOAPExceptionImpl(
474761f14bca Initial load
duke
parents:
diff changeset
   130
                "Body must be the last element in" + " SOAP Envelope");
474761f14bca Initial load
duke
parents:
diff changeset
   131
        }
474761f14bca Initial load
duke
parents:
diff changeset
   132
        return super.addChildElement(name);
474761f14bca Initial load
duke
parents:
diff changeset
   133
    }
474761f14bca Initial load
duke
parents:
diff changeset
   134
474761f14bca Initial load
duke
parents:
diff changeset
   135
474761f14bca Initial load
duke
parents:
diff changeset
   136
    /*
474761f14bca Initial load
duke
parents:
diff changeset
   137
     * Ideally we should be overriding other addChildElement() methods as well
474761f14bca Initial load
duke
parents:
diff changeset
   138
     * but we are not adding them here since internally all those call the
474761f14bca Initial load
duke
parents:
diff changeset
   139
     * method addChildElement(Name name).
474761f14bca Initial load
duke
parents:
diff changeset
   140
     * In future, if this behaviour changes, then we would need to override
474761f14bca Initial load
duke
parents:
diff changeset
   141
     * all the rest of them as well.
474761f14bca Initial load
duke
parents:
diff changeset
   142
     *
474761f14bca Initial load
duke
parents:
diff changeset
   143
     */
474761f14bca Initial load
duke
parents:
diff changeset
   144
474761f14bca Initial load
duke
parents:
diff changeset
   145
    public SOAPElement addTextNode(String text) throws SOAPException {
474761f14bca Initial load
duke
parents:
diff changeset
   146
        log.log(
474761f14bca Initial load
duke
parents:
diff changeset
   147
            Level.SEVERE,
474761f14bca Initial load
duke
parents:
diff changeset
   148
            "SAAJ0416.ver1_2.adding.text.not.legal",
474761f14bca Initial load
duke
parents:
diff changeset
   149
            getElementQName());
474761f14bca Initial load
duke
parents:
diff changeset
   150
        throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Envelope is not legal");
474761f14bca Initial load
duke
parents:
diff changeset
   151
    }
474761f14bca Initial load
duke
parents:
diff changeset
   152
}