-
Notifications
You must be signed in to change notification settings - Fork 24
/
W3CEndpointReference.java
228 lines (201 loc) · 7.11 KB
/
W3CEndpointReference.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright (c) 2005, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package jakarta.xml.ws.wsaddressing;
import org.w3c.dom.Element;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.annotation.XmlAnyAttribute;
import jakarta.xml.bind.annotation.XmlAnyElement;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlValue;
import jakarta.xml.ws.EndpointReference;
import jakarta.xml.ws.WebServiceException;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
/**
* This class represents a W3C Addressing EndpointReference which is
* a remote reference to a web service endpoint that supports the
* W3C WS-Addressing 1.0 - Core Recommendation.
* <p>
* Developers should use this class in their SEIs if they want to
* pass/return endpoint references that represent the W3C WS-Addressing
* recommendation.
* <p>
* Jakarta XML Binding will use the Jakarta XML Binding annotations and bind this class to XML infoset
* that is consistent with that defined by WS-Addressing. See
* <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509/">
* WS-Addressing</a>
* for more information on WS-Addressing EndpointReferences.
*
* @since 1.6, JAX-WS 2.1
*/
// XmlRootElement allows this class to be marshalled on its own
@XmlRootElement(name="EndpointReference",namespace=W3CEndpointReference.NS)
@XmlType(name="EndpointReferenceType",namespace=W3CEndpointReference.NS)
public final class W3CEndpointReference extends EndpointReference {
private final JAXBContext w3cjc = getW3CJaxbContext();
/**
* Addressing namespace.
*/
static final String NS = "http://www.w3.org/2005/08/addressing";
// default constructor forbidden ...
/**
* Default constructor.
*/
private W3CEndpointReference() {
}
/**
* Creates an EPR from infoset representation
*
* @param source A source object containing valid XmlInfoset
* instance consistent with the W3C WS-Addressing Core
* recommendation.
*
* @throws WebServiceException
* If the source does NOT contain a valid W3C WS-Addressing
* EndpointReference.
* @throws NullPointerException
* If the {@code null} {@code source} value is given
*/
public W3CEndpointReference(Source source) {
try {
W3CEndpointReference epr = w3cjc.createUnmarshaller().unmarshal(source,W3CEndpointReference.class).getValue();
this.address = epr.address;
this.metadata = epr.metadata;
this.referenceParameters = epr.referenceParameters;
this.elements = epr.elements;
this.attributes = epr.attributes;
} catch (JAXBException e) {
throw new WebServiceException("Error unmarshalling W3CEndpointReference " ,e);
} catch (ClassCastException e) {
throw new WebServiceException("Source did not contain W3CEndpointReference", e);
}
}
/**
* Returns the {@code address} of the {@code W3CEndpointReference} instance's
* {@code wsa:Address} element.
*
* @return The {@code address} of the {@code wsa:Address}.
*/
String getAddressUri() {
return address.uri;
}
/**
* Returns a list of extension attributes of the
* {@code W3CEndpointReference} instance's
* {@code wsa:Address} element.
*
* @return The extension attributes of the {@code wsa:Address} element.
*/
Map<QName,String> getAddressAttributes() {
if (address == null) {
return null;
}
return address.attributes;
}
/**
* Returns a list of the {@code referenceParameter}s of the
* {@code W3CEndpointReference} instance's
* {@code wsa:ReferenceParameters} element.
*
* @return The {@code referenceParameter}s of the
* {@code wsa:ReferenceParameters} element.
*/
List<Element> getReferenceParameters () {
if (referenceParameters == null) {
return null;
}
return referenceParameters.elements;
}
/**
* Returns the list of {@code metadataElement}s of the
* {@code W3CEndpointReference} instance's
* of the {@code wsa:Metadata} element.
*
* @return The {@code metadataElement}s of the {@code wsa:Metadata} element.
*/
List<Element> getMetadata () {
if (metadata == null) {
return null;
}
return metadata.elements;
}
/**
* Returns a list of extension attributes of the
* {@code W3CEndpointReference} instance's
* {@code wsa:EndpointReference} element.
*
* @return The extension attributes of the {@code W3CEndpointReference}.
*/
Map<QName,String> getAttributes() {
return attributes;
}
/**
* Returns a list of an extension elements of the
* {@code W3CEndpointReference} instance's
* {@code wsa:EndpointReference} element.
*
* @return Extension {@code element}s of the {@code W3CEndpointReference} instance.
*/
List<Element> getElements() {
return elements;
}
@Override
public void writeTo(Result result){
try {
Marshaller marshaller = w3cjc.createMarshaller();
marshaller.marshal(this, result);
} catch (JAXBException e) {
throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
}
}
private static JAXBContext getW3CJaxbContext() {
try {
return JAXBContext.newInstance(W3CEndpointReference.class);
} catch (JAXBException e) {
throw new WebServiceException("Error creating JAXBContext for W3CEndpointReference. ", e);
}
}
// private but necessary properties for databinding
@XmlElement(name="Address",namespace=NS)
private Address address;
@XmlElement(name="ReferenceParameters",namespace=NS)
private Elements referenceParameters;
@XmlElement(name="Metadata",namespace=NS)
private Elements metadata;
// attributes and elements are not private for performance reasons
// (JAXB can bypass reflection)
@XmlAnyAttribute
Map<QName,String> attributes;
@XmlAnyElement
List<Element> elements;
@XmlType(name="address", namespace=W3CEndpointReference.NS)
private static class Address {
protected Address() {}
@XmlValue
String uri;
@XmlAnyAttribute
Map<QName,String> attributes;
}
@XmlType(name="elements", namespace=W3CEndpointReference.NS)
private static class Elements {
protected Elements() {}
@XmlAnyElement
List<Element> elements;
@XmlAnyAttribute
Map<QName,String> attributes;
}
}