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