|
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 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 } |