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

changeset 1
0961a4a21176
child 45
31822b475baa
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/xml/internal/messaging/saaj/soap/ver1_2/Envelope1_2Impl.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,151 @@
     1.4 +/*
     1.5 + * $Id: Envelope1_2Impl.java,v 1.26 2006/01/27 12:49:47 vj135062 Exp $
     1.6 + */
     1.7 +
     1.8 +/*
     1.9 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
    1.10 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    1.11 + *
    1.12 + * This code is free software; you can redistribute it and/or modify it
    1.13 + * under the terms of the GNU General Public License version 2 only, as
    1.14 + * published by the Free Software Foundation.  Sun designates this
    1.15 + * particular file as subject to the "Classpath" exception as provided
    1.16 + * by Sun in the LICENSE file that accompanied this code.
    1.17 + *
    1.18 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.19 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.20 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.21 + * version 2 for more details (a copy is included in the LICENSE file that
    1.22 + * accompanied this code).
    1.23 + *
    1.24 + * You should have received a copy of the GNU General Public License version
    1.25 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.26 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.27 + *
    1.28 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.29 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.30 + * have any questions.
    1.31 + */
    1.32 +
    1.33 +/**
    1.34 +*
    1.35 +* @author SAAJ RI Development Team
    1.36 +*/
    1.37 +package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
    1.38 +
    1.39 +import java.util.logging.Logger;
    1.40 +import java.util.logging.Level;
    1.41 +
    1.42 +import javax.xml.namespace.QName;
    1.43 +import javax.xml.soap.*;
    1.44 +
    1.45 +import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    1.46 +import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
    1.47 +import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
    1.48 +import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
    1.49 +
    1.50 +public class Envelope1_2Impl extends EnvelopeImpl {
    1.51 +
    1.52 +    protected static Logger log =
    1.53 +        Logger.getLogger(Envelope1_2Impl.class.getName(),
    1.54 +                         "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
    1.55 +
    1.56 +    public Envelope1_2Impl(SOAPDocumentImpl ownerDoc, String prefix) {
    1.57 +        super(ownerDoc, NameImpl.createEnvelope1_2Name(prefix));
    1.58 +    }
    1.59 +
    1.60 +    public Envelope1_2Impl(
    1.61 +        SOAPDocumentImpl ownerDoc,
    1.62 +        String prefix,
    1.63 +        boolean createHeader,
    1.64 +        boolean createBody)
    1.65 +        throws SOAPException {
    1.66 +        super(
    1.67 +            ownerDoc,
    1.68 +            NameImpl.createEnvelope1_2Name(prefix),
    1.69 +            createHeader,
    1.70 +            createBody);
    1.71 +    }
    1.72 +
    1.73 +    protected NameImpl getBodyName(String prefix) {
    1.74 +        return NameImpl.createBody1_2Name(prefix);
    1.75 +    }
    1.76 +
    1.77 +    protected NameImpl getHeaderName(String prefix) {
    1.78 +        return NameImpl.createHeader1_2Name(prefix);
    1.79 +    }
    1.80 +
    1.81 +    /*
    1.82 +     * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
    1.83 +     * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
    1.84 +     */
    1.85 +    public void setEncodingStyle(String encodingStyle) throws SOAPException {
    1.86 +        log.severe("SAAJ0404.ver1_2.no.encodingStyle.in.envelope");
    1.87 +        throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Envelope");
    1.88 +    }
    1.89 +
    1.90 +    /*
    1.91 +     * Override addAttribute of ElementImpl to restrict adding encodingStyle
    1.92 +     * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
    1.93 +     */
    1.94 +    public SOAPElement addAttribute(Name name, String value)
    1.95 +        throws SOAPException {
    1.96 +        if (name.getLocalName().equals("encodingStyle")
    1.97 +            && name.getURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
    1.98 +            setEncodingStyle(value);
    1.99 +        }
   1.100 +        return super.addAttribute(name, value);
   1.101 +    }
   1.102 +
   1.103 +    public SOAPElement addAttribute(QName name, String value)
   1.104 +        throws SOAPException {
   1.105 +        if (name.getLocalPart().equals("encodingStyle")
   1.106 +            && name.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
   1.107 +            setEncodingStyle(value);
   1.108 +        }
   1.109 +        return super.addAttribute(name, value);
   1.110 +    }
   1.111 +
   1.112 +
   1.113 +    /*
   1.114 +     * Override addChildElement method to ensure that no element
   1.115 +     * is added after body in SOAP 1.2.
   1.116 +     */
   1.117 +    public SOAPElement addChildElement(Name name) throws SOAPException {
   1.118 +        // check if body already exists
   1.119 +        if (getBody() != null) {
   1.120 +            log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
   1.121 +            throw new SOAPExceptionImpl(
   1.122 +                "Body must be the last element in" + " SOAP Envelope");
   1.123 +        }
   1.124 +        return super.addChildElement(name);
   1.125 +    }
   1.126 +
   1.127 +    public SOAPElement addChildElement(QName name) throws SOAPException {
   1.128 +        // check if body already exists
   1.129 +        if (getBody() != null) {
   1.130 +            log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
   1.131 +            throw new SOAPExceptionImpl(
   1.132 +                "Body must be the last element in" + " SOAP Envelope");
   1.133 +        }
   1.134 +        return super.addChildElement(name);
   1.135 +    }
   1.136 +
   1.137 +
   1.138 +    /*
   1.139 +     * Ideally we should be overriding other addChildElement() methods as well
   1.140 +     * but we are not adding them here since internally all those call the
   1.141 +     * method addChildElement(Name name).
   1.142 +     * In future, if this behaviour changes, then we would need to override
   1.143 +     * all the rest of them as well.
   1.144 +     *
   1.145 +     */
   1.146 +
   1.147 +    public SOAPElement addTextNode(String text) throws SOAPException {
   1.148 +        log.log(
   1.149 +            Level.SEVERE,
   1.150 +            "SAAJ0416.ver1_2.adding.text.not.legal",
   1.151 +            getElementQName());
   1.152 +        throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Envelope is not legal");
   1.153 +    }
   1.154 +}

mercurial