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.namespace.QName;
19 import javax.xml.soap.Name;
20 import javax.xml.soap.SOAPElement;
21 import javax.xml.soap.SOAPEnvelope;
22 import javax.xml.soap.SOAPException;
23 import javax.xml.soap.SOAPHeader;
24
25 import org.apache.axis.message.SOAPHeaderElement;
26 import org.apache.axis.message.addressing.util.AddressingUtils;
27 import org.apache.axis.message.addressing.util.TextExtractor;
28 import org.apache.axis.types.URI;
29 import org.apache.axis.types.URI.MalformedURIException;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class RelatesTo extends Relationship implements AddressingHeaderItem {
49
50
51
52
53
54
55
56 public RelatesTo(SOAPElement element) throws MalformedURIException {
57 super();
58 AddressingVersion version = AddressingUtils.getAddressingVersion(
59 element.getNamespaceURI());
60
61 this.setURI(new URI(TextExtractor.getText(element)));
62 String value = element.getAttribute(Constants.RELATIONSHIP_TYPE);
63 if (value != null && value.length() > 0) {
64 if (version.isW3C()) {
65 this.setTypeIRI(value);
66 } else {
67 int pos = value.indexOf(':');
68 if (pos == -1) {
69 this.setType(new QName(value));
70 } else {
71 String namespace = element.getNamespaceURI(value.substring(0, pos));
72 this.setType(new QName(namespace, value.substring(pos + 1)));
73 }
74 }
75 } else {
76 this.setType(version.getResponseRelationshipType());
77 }
78 }
79
80
81
82
83
84
85
86
87 public RelatesTo(String uri, QName type) throws URI.MalformedURIException {
88 super(new URI(uri), type);
89 }
90
91
92
93
94
95
96
97
98 public RelatesTo(String uri, String type) throws URI.MalformedURIException {
99 super(uri, type);
100 }
101
102
103
104
105
106
107
108 public RelatesTo(URI uri, QName type) {
109 super(uri, type);
110 }
111
112
113
114
115 public SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env, String actorURI)
116 throws SOAPException {
117 AddressingVersion version = AddressingUtils.getAddressingVersion();
118 return toSOAPHeaderElement(version, env, actorURI);
119 }
120
121
122
123
124 public SOAPHeaderElement toSOAPHeaderElement(AddressingVersion version,
125 SOAPEnvelope env, String actorURI) throws SOAPException {
126 Name nm = env.createName(Constants.RELATES_TO, Constants.NS_PREFIX_ADDRESSING,
127 version.getNamespace());
128 SOAPHeader header = env.getHeader();
129 if (header == null) {
130 header = env.addHeader();
131 }
132
133 SOAPHeaderElement headerElement = (SOAPHeaderElement) header.addHeaderElement(nm);
134 headerElement.setActor(actorURI);
135
136 String typeIRI = this.getTypeIRI();
137 QName type = this.getType();
138
139 if (typeIRI != null) {
140 headerElement.addAttribute("", Constants.RELATIONSHIP_TYPE, typeIRI);
141 } else if (type != null) {
142 headerElement.addAttribute("", Constants.RELATIONSHIP_TYPE, type);
143 }
144
145 headerElement.addTextNode(this.getURI().toString());
146
147 return headerElement;
148 }
149
150 }