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  */
25 
26 /**
27 *
28 * @author SAAJ RI Development Team
29 */
30 package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
31 
32 import java.util.List;
33 import java.util.Iterator;
34 import java.util.logging.Logger;
35 import java.util.logging.Level;
36 
37 import javax.xml.namespace.QName;
38 import javax.xml.soap.*;
39 
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.HeaderElementImpl;
44 import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl;
45 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
46 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
47 
48 
49 public class Header1_2Impl extends HeaderImpl {
50 
51     protected static final Logger log =
52         Logger.getLogger(
53             LogDomainConstants.SOAP_VER1_2_DOMAIN,
54             "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
55 
Header1_2Impl(SOAPDocumentImpl ownerDocument, String prefix)56     public Header1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
57         super(ownerDocument, NameImpl.createHeader1_2Name(prefix));
58     }
59 
getNotUnderstoodName()60     protected NameImpl getNotUnderstoodName() {
61         return NameImpl.createNotUnderstood1_2Name(null);
62     }
63 
getUpgradeName()64     protected NameImpl getUpgradeName() {
65         return NameImpl.createUpgrade1_2Name(null);
66     }
67 
getSupportedEnvelopeName()68     protected NameImpl getSupportedEnvelopeName() {
69         return NameImpl.createSupportedEnvelope1_2Name(null);
70     }
71 
addNotUnderstoodHeaderElement(final QName sourceName)72     public SOAPHeaderElement addNotUnderstoodHeaderElement(final QName sourceName)
73         throws SOAPException {
74 
75         if (sourceName == null) {
76             log.severe("SAAJ0410.ver1_2.no.null.to.addNotUnderstoodHeader");
77             throw new SOAPException("Cannot pass NULL to addNotUnderstoodHeaderElement");
78         }
79         if ("".equals(sourceName.getNamespaceURI())) {
80             log.severe("SAAJ0417.ver1_2.qname.not.ns.qualified");
81             throw new SOAPException("The qname passed to addNotUnderstoodHeaderElement must be namespace-qualified");
82         }
83         String prefix = sourceName.getPrefix();
84         if ("".equals(prefix)) {
85             prefix = "ns1";
86         }
87         Name notunderstoodName = getNotUnderstoodName();
88         SOAPHeaderElement notunderstoodHeaderElement =
89             (SOAPHeaderElement) addChildElement(notunderstoodName);
90         notunderstoodHeaderElement.addAttribute(
91             NameImpl.createFromUnqualifiedName("qname"),
92             getQualifiedName(
93                 new QName(
94                     sourceName.getNamespaceURI(),
95                     sourceName.getLocalPart(),
96                     prefix)));
97         notunderstoodHeaderElement.addNamespaceDeclaration(
98             prefix,
99             sourceName.getNamespaceURI());
100         return notunderstoodHeaderElement;
101     }
102 
addTextNode(String text)103     public SOAPElement addTextNode(String text) throws SOAPException {
104         log.log(
105             Level.SEVERE,
106             "SAAJ0416.ver1_2.adding.text.not.legal",
107             getElementQName());
108         throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Header is not legal");
109     }
110 
createHeaderElement(Name name)111     protected SOAPHeaderElement createHeaderElement(Name name)
112         throws SOAPException {
113         String uri = name.getURI();
114         if (uri == null || uri.equals("")) {
115             log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified");
116             throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified");
117         }
118         return new HeaderElement1_2Impl(
119             ((SOAPDocument) getOwnerDocument()).getDocument(),
120             name);
121     }
122 
createHeaderElement(QName name)123     protected SOAPHeaderElement createHeaderElement(QName name)
124         throws SOAPException {
125         String uri = name.getNamespaceURI();
126         if (uri == null || uri.equals("")) {
127             log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified");
128             throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified");
129         }
130         return new HeaderElement1_2Impl(
131             ((SOAPDocument) getOwnerDocument()).getDocument(),
132             name);
133     }
134 
setEncodingStyle(String encodingStyle)135     public void setEncodingStyle(String encodingStyle) throws SOAPException {
136         log.severe("SAAJ0409.ver1_2.no.encodingstyle.in.header");
137         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Header");
138     }
139 
addAttribute(Name name, String value)140     public SOAPElement addAttribute(Name name, String value)
141         throws SOAPException {
142         if (name.getLocalName().equals("encodingStyle")
143             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
144 
145             setEncodingStyle(value);
146         }
147         return super.addAttribute(name, value);
148     }
149 
addAttribute(QName name, String value)150     public SOAPElement addAttribute(QName name, String value)
151         throws SOAPException {
152         if (name.getLocalPart().equals("encodingStyle")
153             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
154 
155             setEncodingStyle(value);
156         }
157         return super.addAttribute(name, value);
158     }
159 }
160