1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.xml.ws.wsaddressing;
21
22 import javax.xml.bind.JAXBContext;
23 import javax.xml.bind.Marshaller;
24 import javax.xml.bind.Unmarshaller;
25 import javax.xml.bind.annotation.XmlAccessType;
26 import javax.xml.bind.annotation.XmlAccessorType;
27 import javax.xml.bind.annotation.XmlAnyAttribute;
28 import javax.xml.bind.annotation.XmlAnyElement;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import javax.xml.bind.annotation.XmlSchemaType;
32 import javax.xml.bind.annotation.XmlType;
33 import javax.xml.bind.annotation.XmlValue;
34 import javax.xml.namespace.QName;
35 import javax.xml.transform.Result;
36 import javax.xml.transform.Source;
37 import javax.xml.ws.EndpointReference;
38 import javax.xml.ws.WebServiceException;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 @XmlRootElement(name = "EndpointReference", namespace = W3CEndpointReference.NS)
66 @XmlType(name = "EndpointReferenceType", namespace = W3CEndpointReference.NS)
67 public final class W3CEndpointReference extends EndpointReference {
68 protected static final String NS = "http://www.w3.org/2005/08/addressing";
69 private static JAXBContext jaxbContext;
70
71 @XmlElement(name = "Address", namespace = NS, required = true)
72 private AttributedURIType address;
73 @XmlElement(name = "ReferenceParameters", namespace = NS)
74 private ReferenceParametersType referenceParameters;
75 @XmlElement(name = "Metadata", namespace = NS)
76 private MetadataType metadata;
77 @XmlAnyElement(lax = true)
78 private List<Object> any;
79 @XmlAnyAttribute
80 private Map<QName, String> otherAttributes = new HashMap<QName, String>();
81
82 static {
83 try {
84 jaxbContext = JAXBContext.newInstance(W3CEndpointReference.class);
85 }
86 catch (Exception e) {
87
88 throw new WebServiceException("JAXBContext creation failed.", e);
89 }
90 }
91
92 protected W3CEndpointReference() {
93 }
94
95 public W3CEndpointReference(Source eprInfoset) {
96 super();
97
98 try {
99 Unmarshaller um = jaxbContext.createUnmarshaller();
100 W3CEndpointReference w3cEPR = (W3CEndpointReference) um.unmarshal(eprInfoset);
101
102 address = w3cEPR.address;
103 referenceParameters = w3cEPR.referenceParameters;
104 metadata = w3cEPR.metadata;
105 any = w3cEPR.any;
106 otherAttributes.putAll(w3cEPR.otherAttributes);
107 }
108 catch (Exception e) {
109
110 throw new WebServiceException("Unable to create W3C endpoint reference.", e);
111 }
112 }
113
114 @Override
115 public void writeTo(Result result) {
116 if (result == null) {
117
118 throw new IllegalArgumentException("Null is not allowed.");
119 }
120
121 try {
122 Marshaller m = jaxbContext.createMarshaller();
123 m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
124 m.marshal(this, result);
125 }
126 catch (Exception e) {
127
128 throw new WebServiceException("writeTo failure.", e);
129 }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 @XmlAccessorType(XmlAccessType.FIELD)
149 @XmlType(name = "AttributedURIType", propOrder = {
150 "value"
151 })
152 private static class AttributedURIType {
153
154 @XmlValue
155 @XmlSchemaType(name = "anyURI")
156 protected String value;
157 @XmlAnyAttribute
158 private Map<QName, String> otherAttributes = new HashMap<QName, String>();
159
160 public AttributedURIType() {
161 }
162 }
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183 @XmlAccessorType(XmlAccessType.FIELD)
184 @XmlType(name = "ReferenceParametersType", propOrder = {
185 "any"
186 })
187 private static class ReferenceParametersType {
188
189 @XmlAnyElement(lax = true)
190 protected List<Object> any;
191 @XmlAnyAttribute
192 private Map<QName, String> otherAttributes = new HashMap<QName, String>();
193
194 public ReferenceParametersType() {
195 }
196 }
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 @XmlAccessorType(XmlAccessType.FIELD)
218 @XmlType(name = "MetadataType", propOrder = {
219 "any"
220 })
221 private static class MetadataType {
222
223 @XmlAnyElement(lax = true)
224 protected List<Object> any;
225 @XmlAnyAttribute
226 private Map<QName, String> otherAttributes = new HashMap<QName, String>();
227
228 public MetadataType() {
229 }
230 }
231 }