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 javax.xml.namespace.QName;
29 import javax.xml.soap.*;
30
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
33
34 public abstract class HeaderElementImpl
35 extends ElementImpl
36 implements SOAPHeaderElement {
37
38 protected static Name RELAY_ATTRIBUTE_LOCAL_NAME =
39 NameImpl.createFromTagName("relay");
40 protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME =
41 NameImpl.createFromTagName("mustUnderstand");
42
43 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
44 super(ownerDoc, qname);
45 }
46 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
47 super(ownerDoc, qname);
48 }
49
50 protected abstract NameImpl getActorAttributeName();
51 protected abstract NameImpl getRoleAttributeName();
52 protected abstract NameImpl getMustunderstandAttributeName();
53 protected abstract boolean getMustunderstandAttributeValue(String str);
54 protected abstract String getMustunderstandLiteralValue(boolean mu);
55 protected abstract NameImpl getRelayAttributeName();
56 protected abstract boolean getRelayAttributeValue(String str);
57 protected abstract String getRelayLiteralValue(boolean mu);
58 protected abstract String getActorOrRole();
59
60
61 public void setParentElement(SOAPElement element) throws SOAPException {
62 if (!(element instanceof SOAPHeader)) {
63 log.severe("SAAJ0130.impl.header.elem.parent.mustbe.header");
64 throw new SOAPException("Parent of a SOAPHeaderElement has to be a SOAPHeader");
65 }
66
67 super.setParentElement(element);
68 }
69
70 public void setActor(String actorUri) {
71 try {
72 removeAttribute(getActorAttributeName());
73 addAttribute((Name) getActorAttributeName(), actorUri);
74 } catch (SOAPException ex) {
75 }
76 }
77
78 //SOAP 1.2 supports Role
79 public void setRole(String roleUri) throws SOAPException {
80 // runtime exception thrown if called for SOAP 1.1
81 removeAttribute(getRoleAttributeName());
82 addAttribute((Name) getRoleAttributeName(), roleUri);
83 }
84
85
86 Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor");
87
88 public String getActor() {
89 String actor = getAttributeValue(getActorAttributeName());
90 return actor;
91 }
92
93 Name roleAttNameWithoutNS = NameImpl.createFromTagName("role");
94
95 public String getRole() {
96 // runtime exception thrown for 1.1
97 String role = getAttributeValue(getRoleAttributeName());
98 return role;
99 }
100
101 public void setMustUnderstand(boolean mustUnderstand) {
102 try {
103 removeAttribute(getMustunderstandAttributeName());
104 addAttribute(
105 (Name) getMustunderstandAttributeName(),
106 getMustunderstandLiteralValue(mustUnderstand));
107 } catch (SOAPException ex) {
108 }
109 }
110
111 public boolean getMustUnderstand() {
112 String mu = getAttributeValue(getMustunderstandAttributeName());
113
114 if (mu != null)
115 return getMustunderstandAttributeValue(mu);
116
117 return false;
118 }
119
120 public void setRelay(boolean relay) throws SOAPException {
121 // runtime exception thrown for 1.1
122 removeAttribute(getRelayAttributeName());
123 addAttribute(
124 (Name) getRelayAttributeName(),
125 getRelayLiteralValue(relay));
126 }
127
128 public boolean getRelay() {
129 String mu = getAttributeValue(getRelayAttributeName());
130 if (mu != null)
131 return getRelayAttributeValue(mu);
132
133 return false;
134 }
135 }
|
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 javax.xml.namespace.QName;
29 import javax.xml.soap.*;
30
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
33 import org.w3c.dom.Element;
34
35 public abstract class HeaderElementImpl
36 extends ElementImpl
37 implements SOAPHeaderElement {
38
39 protected static Name RELAY_ATTRIBUTE_LOCAL_NAME =
40 NameImpl.createFromTagName("relay");
41 protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME =
42 NameImpl.createFromTagName("mustUnderstand");
43
44 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
45 super(ownerDoc, qname);
46 }
47 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
48 super(ownerDoc, qname);
49 }
50
51 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Element domElement) {
52 super(ownerDoc, domElement);
53 }
54
55 protected abstract NameImpl getActorAttributeName();
56 protected abstract NameImpl getRoleAttributeName();
57 protected abstract NameImpl getMustunderstandAttributeName();
58 protected abstract boolean getMustunderstandAttributeValue(String str);
59 protected abstract String getMustunderstandLiteralValue(boolean mu);
60 protected abstract NameImpl getRelayAttributeName();
61 protected abstract boolean getRelayAttributeValue(String str);
62 protected abstract String getRelayLiteralValue(boolean mu);
63 protected abstract String getActorOrRole();
64
65
66 @Override
67 public void setParentElement(SOAPElement element) throws SOAPException {
68 if (!(element instanceof SOAPHeader)) {
69 log.severe("SAAJ0130.impl.header.elem.parent.mustbe.header");
70 throw new SOAPException("Parent of a SOAPHeaderElement has to be a SOAPHeader");
71 }
72
73 super.setParentElement(element);
74 }
75
76 @Override
77 public void setActor(String actorUri) {
78 try {
79 removeAttribute(getActorAttributeName());
80 addAttribute((Name) getActorAttributeName(), actorUri);
81 } catch (SOAPException ex) {
82 }
83 }
84
85 //SOAP 1.2 supports Role
86 @Override
87 public void setRole(String roleUri) throws SOAPException {
88 // runtime exception thrown if called for SOAP 1.1
89 removeAttribute(getRoleAttributeName());
90 addAttribute((Name) getRoleAttributeName(), roleUri);
91 }
92
93
94 Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor");
95
96 @Override
97 public String getActor() {
98 String actor = getAttributeValue(getActorAttributeName());
99 return actor;
100 }
101
102 Name roleAttNameWithoutNS = NameImpl.createFromTagName("role");
103
104 @Override
105 public String getRole() {
106 // runtime exception thrown for 1.1
107 String role = getAttributeValue(getRoleAttributeName());
108 return role;
109 }
110
111 @Override
112 public void setMustUnderstand(boolean mustUnderstand) {
113 try {
114 removeAttribute(getMustunderstandAttributeName());
115 addAttribute(
116 (Name) getMustunderstandAttributeName(),
117 getMustunderstandLiteralValue(mustUnderstand));
118 } catch (SOAPException ex) {
119 }
120 }
121
122 @Override
123 public boolean getMustUnderstand() {
124 String mu = getAttributeValue(getMustunderstandAttributeName());
125
126 if (mu != null)
127 return getMustunderstandAttributeValue(mu);
128
129 return false;
130 }
131
132 @Override
133 public void setRelay(boolean relay) throws SOAPException {
134 // runtime exception thrown for 1.1
135 removeAttribute(getRelayAttributeName());
136 addAttribute(
137 (Name) getRelayAttributeName(),
138 getRelayLiteralValue(relay));
139 }
140
141 @Override
142 public boolean getRelay() {
143 String mu = getAttributeValue(getRelayAttributeName());
144 if (mu != null)
145 return getRelayAttributeValue(mu);
146
147 return false;
148 }
149 }
|