1 /*
2 * Copyright (c) 1997, 2013, 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 package com.sun.xml.internal.messaging.saaj.soap.impl;
27
28 import java.util.*;
29 import java.util.logging.Level;
30
31 import javax.xml.namespace.QName;
32 import javax.xml.soap.*;
33
34 import org.w3c.dom.Element;
35
36 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
37 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
38 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
39 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
40
41 public abstract class HeaderImpl extends ElementImpl implements SOAPHeader {
42 protected static final boolean MUST_UNDERSTAND_ONLY = false;
43
44 protected HeaderImpl(SOAPDocumentImpl ownerDoc, NameImpl name) {
45 super(ownerDoc, name);
46 }
47
48 protected abstract SOAPHeaderElement createHeaderElement(Name name)
49 throws SOAPException;
50 protected abstract SOAPHeaderElement createHeaderElement(QName name)
51 throws SOAPException;
52 protected abstract NameImpl getNotUnderstoodName();
53 protected abstract NameImpl getUpgradeName();
54 protected abstract NameImpl getSupportedEnvelopeName();
55
56 public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
57 SOAPElement newHeaderElement =
58 ElementFactory.createNamedElement(
59 ((SOAPDocument) getOwnerDocument()).getDocument(),
60 name.getLocalName(),
61 name.getPrefix(),
62 name.getURI());
63 if (newHeaderElement == null
64 || !(newHeaderElement instanceof SOAPHeaderElement)) {
65 newHeaderElement = createHeaderElement(name);
66 }
67
259 log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
260 throw new SOAPException("List of supported URIs cannot be empty");
261 }
262 Name upgradeName = getUpgradeName();
263 SOAPHeaderElement upgradeHeaderElement =
264 (SOAPHeaderElement) addChildElement(upgradeName);
265 Name supportedEnvelopeName = getSupportedEnvelopeName();
266 for (int i = 0; i < supportedSoapUris.length; i ++) {
267 SOAPElement subElement =
268 upgradeHeaderElement.addChildElement(supportedEnvelopeName);
269 String ns = "ns" + Integer.toString(i);
270 subElement.addAttribute(
271 NameImpl.createFromUnqualifiedName("qname"),
272 ns + ":Envelope");
273 subElement.addNamespaceDeclaration(ns, supportedSoapUris[i]);
274 }
275 return upgradeHeaderElement;
276 }
277
278 protected SOAPElement convertToSoapElement(Element element) {
279 if (element instanceof SOAPHeaderElement) {
280 return (SOAPElement) element;
281 } else {
282 SOAPHeaderElement headerElement;
283 try {
284 headerElement =
285 createHeaderElement(NameImpl.copyElementName(element));
286 } catch (SOAPException e) {
287 throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage());
288 }
289 return replaceElementWithSOAPElement(
290 element,
291 (ElementImpl) headerElement);
292 }
293 }
294
295 public SOAPElement setElementQName(QName newName) throws SOAPException {
296 log.log(Level.SEVERE,
297 "SAAJ0146.impl.invalid.name.change.requested",
298 new Object[] {elementQName.getLocalPart(),
299 newName.getLocalPart()});
300 throw new SOAPException("Cannot change name for "
|
1 /*
2 * Copyright (c) 1997, 2017, 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 package com.sun.xml.internal.messaging.saaj.soap.impl;
27
28 import java.util.*;
29 import java.util.logging.Level;
30
31 import javax.xml.namespace.QName;
32 import javax.xml.soap.*;
33
34 import com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
35 import org.w3c.dom.Element;
36
37 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
38 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
39 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
40 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
41
42 public abstract class HeaderImpl extends ElementImpl implements SOAPHeader {
43 protected static final boolean MUST_UNDERSTAND_ONLY = false;
44
45 protected HeaderImpl(SOAPDocumentImpl ownerDoc, NameImpl name) {
46 super(ownerDoc, name);
47 }
48
49 public HeaderImpl(SOAPDocumentImpl ownerDoc, Element domElement) {
50 super(ownerDoc, domElement);
51 }
52
53 protected abstract SOAPHeaderElement createHeaderElement(Name name)
54 throws SOAPException;
55 protected abstract SOAPHeaderElement createHeaderElement(QName name)
56 throws SOAPException;
57 protected abstract NameImpl getNotUnderstoodName();
58 protected abstract NameImpl getUpgradeName();
59 protected abstract NameImpl getSupportedEnvelopeName();
60
61 public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
62 SOAPElement newHeaderElement =
63 ElementFactory.createNamedElement(
64 ((SOAPDocument) getOwnerDocument()).getDocument(),
65 name.getLocalName(),
66 name.getPrefix(),
67 name.getURI());
68 if (newHeaderElement == null
69 || !(newHeaderElement instanceof SOAPHeaderElement)) {
70 newHeaderElement = createHeaderElement(name);
71 }
72
264 log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
265 throw new SOAPException("List of supported URIs cannot be empty");
266 }
267 Name upgradeName = getUpgradeName();
268 SOAPHeaderElement upgradeHeaderElement =
269 (SOAPHeaderElement) addChildElement(upgradeName);
270 Name supportedEnvelopeName = getSupportedEnvelopeName();
271 for (int i = 0; i < supportedSoapUris.length; i ++) {
272 SOAPElement subElement =
273 upgradeHeaderElement.addChildElement(supportedEnvelopeName);
274 String ns = "ns" + Integer.toString(i);
275 subElement.addAttribute(
276 NameImpl.createFromUnqualifiedName("qname"),
277 ns + ":Envelope");
278 subElement.addNamespaceDeclaration(ns, supportedSoapUris[i]);
279 }
280 return upgradeHeaderElement;
281 }
282
283 protected SOAPElement convertToSoapElement(Element element) {
284 final org.w3c.dom.Node soapNode = getSoapDocument().findIfPresent(element);
285 if (soapNode instanceof SOAPHeaderElement) {
286 return (SOAPElement) soapNode;
287 } else {
288 SOAPHeaderElement headerElement;
289 try {
290 headerElement =
291 createHeaderElement(NameImpl.copyElementName(element));
292 } catch (SOAPException e) {
293 throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage());
294 }
295 return replaceElementWithSOAPElement(
296 element,
297 (ElementImpl) headerElement);
298 }
299 }
300
301 public SOAPElement setElementQName(QName newName) throws SOAPException {
302 log.log(Level.SEVERE,
303 "SAAJ0146.impl.invalid.name.change.requested",
304 new Object[] {elementQName.getLocalPart(),
305 newName.getLocalPart()});
306 throw new SOAPException("Cannot change name for "
|