1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.axis.message.addressing;
17
18 import javax.xml.soap.Name;
19 import javax.xml.soap.SOAPEnvelope;
20 import javax.xml.soap.SOAPException;
21 import javax.xml.soap.SOAPHeader;
22 import javax.xml.soap.SOAPHeaderElement;
23
24 import org.apache.axis.message.addressing.util.AddressingUtils;
25 import org.apache.axis.message.addressing.util.TextExtractor;
26 import org.apache.axis.types.URI;
27 import org.w3c.dom.Document;
28 import org.w3c.dom.Element;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class AttributedURI extends URI
51 implements DOMAppendable, AddressingHeaderItem {
52
53
54
55
56 private static final long serialVersionUID = -3363815864897359681L;
57
58
59
60
61 public AttributedURI() {
62 }
63
64
65
66
67
68
69
70 public AttributedURI(SOAPHeaderElement el) throws URI.MalformedURIException {
71 this(TextExtractor.getText(el).trim());
72 }
73
74
75
76
77
78
79
80 public AttributedURI(String uri) throws MalformedURIException {
81 super(new URI(uri.trim()));
82 }
83
84
85
86
87
88
89 public AttributedURI(URI uri) {
90 super(uri);
91 }
92
93
94
95
96
97
98
99 public String getDefaultElementName() {
100 return "";
101 }
102
103
104
105
106 public final void append(Element parent) {
107 append(parent, getDefaultElementName());
108 }
109
110
111
112
113 public final void append(Element parent, String elementName) {
114 append(AddressingUtils.getAddressingVersion(), parent, elementName);
115 }
116
117
118
119
120 public final void append(AddressingVersion version, Element parent, String elemName) {
121 Document doc = parent.getOwnerDocument();
122 Element child = doc.createElementNS(version.getNamespace(), elemName);
123 child.appendChild(doc.createTextNode(this.toString()));
124 parent.appendChild(child);
125 }
126
127
128
129
130
131
132
133
134
135
136 public final SOAPHeaderElement toSOAPHeaderElement(AddressingVersion version,
137 SOAPEnvelope env, String actorURI) throws SOAPException {
138 return toSOAPHeaderElement(version, env, actorURI, getDefaultElementName());
139 }
140
141
142
143
144
145
146
147
148
149
150
151 protected SOAPHeaderElement toSOAPHeaderElement(AddressingVersion version,
152 SOAPEnvelope env, String actorURI, String name) throws SOAPException {
153
154 if (name == null) {
155 throw new IllegalArgumentException("A null name is not allowed.");
156 }
157 Name qname = env.createName(name, Constants.NS_PREFIX_ADDRESSING, version
158 .getNamespace());
159 SOAPHeader header = env.getHeader();
160 if (header == null) {
161 header = env.addHeader();
162 }
163
164
165 SOAPHeaderElement headerElement = header.addHeaderElement(qname);
166 headerElement.setActor(actorURI);
167 headerElement.addTextNode(this.toString());
168 return headerElement;
169 }
170
171
172
173
174 public final SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env, String actorURI)
175 throws SOAPException {
176 AddressingVersion version = AddressingUtils.getAddressingVersion();
177 return this.toSOAPHeaderElement(version, env, actorURI);
178 }
179
180 }