src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/SOAPExtensionHandler.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2010, 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.tools.internal.ws.wsdl.parser;
27
28 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
29 import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
30 import com.sun.tools.internal.ws.util.xml.XmlUtil;
31 import com.sun.tools.internal.ws.wsdl.document.soap.*;
32 import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
33 import org.w3c.dom.Element;
34 import org.xml.sax.Locator;
35
36 import javax.xml.namespace.QName;
37 import java.util.Iterator;
38 import java.util.Map;
39
40 /**
41 * The SOAP extension handler for WSDL.
42 *
43 * @author WS Development Team
44 */
45 public class SOAPExtensionHandler extends AbstractExtensionHandler {
46
47 public SOAPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
48 super(extensionHandlerMap);
49 }
50
51 public String getNamespaceURI() {
52 return Constants.NS_WSDL_SOAP;
53 }
54
55 public boolean handleDefinitionsExtension(
56 TWSDLParserContext context,
57 TWSDLExtensible parent,
58 Element e) {
59 Util.fail(
60 "parsing.invalidExtensionElement",
61 e.getTagName(),
62 e.getNamespaceURI());
63 return false; // keep compiler happy
64 }
65
66 public boolean handleTypesExtension(
67 com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
68 TWSDLExtensible parent,
69 Element e) {
70 Util.fail(
71 "parsing.invalidExtensionElement",
72 e.getTagName(),
73 e.getNamespaceURI());
74 return false; // keep compiler happy
75 }
76
77 protected SOAPBinding getSOAPBinding(Locator location){
78 return new SOAPBinding(location);
79 }
80
81 public boolean handleBindingExtension(
82 TWSDLParserContext context,
83 TWSDLExtensible parent,
84 Element e) {
85 if (XmlUtil.matchesTagNS(e, getBindingQName())) {
86 context.push();
87 context.registerNamespaces(e);
88
89 SOAPBinding binding = getSOAPBinding(context.getLocation(e));
90
91 // NOTE - the "transport" attribute is required according to section 3.3 of the WSDL 1.1 spec,
92 // but optional according to the schema in appendix A 4.2 of the same document!
93 String transport =
94 Util.getRequiredAttribute(e, Constants.ATTR_TRANSPORT);
95 binding.setTransport(transport);
96
97 String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
98 if (style != null) {
99 if (style.equals(Constants.ATTRVALUE_RPC)) {
100 binding.setStyle(SOAPStyle.RPC);
101 } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
102 binding.setStyle(SOAPStyle.DOCUMENT);
103 } else {
104 Util.fail(
105 "parsing.invalidAttributeValue",
106 Constants.ATTR_STYLE,
107 style);
108 }
109 }
110 parent.addExtension(binding);
111 context.pop();
112 // context.fireDoneParsingEntity(getBindingQName(), binding);
113 return true;
114 } else {
115 Util.fail(
116 "parsing.invalidExtensionElement",
117 e.getTagName(),
118 e.getNamespaceURI());
119 return false; // keep compiler happy
120 }
121 }
122
123 public boolean handleOperationExtension(
124 TWSDLParserContext context,
125 TWSDLExtensible parent,
126 Element e) {
127 if (XmlUtil.matchesTagNS(e, getOperationQName())) {
128 context.push();
129 context.registerNamespaces(e);
130
131 SOAPOperation operation = new SOAPOperation(context.getLocation(e));
132
133 String soapAction =
134 XmlUtil.getAttributeOrNull(e, Constants.ATTR_SOAP_ACTION);
135 if (soapAction != null) {
136 operation.setSOAPAction(soapAction);
137 }
138
139 String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
140 if (style != null) {
141 if (style.equals(Constants.ATTRVALUE_RPC)) {
142 operation.setStyle(SOAPStyle.RPC);
143 } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
144 operation.setStyle(SOAPStyle.DOCUMENT);
145 } else {
146 Util.fail(
147 "parsing.invalidAttributeValue",
148 Constants.ATTR_STYLE,
149 style);
150 }
151 }
152 parent.addExtension(operation);
153 context.pop();
154 // context.fireDoneParsingEntity(
155 // getOperationQName(),
156 // operation);
157 return true;
158 } else {
159 Util.fail(
160 "parsing.invalidExtensionElement",
161 e.getTagName(),
162 e.getNamespaceURI());
163 return false; // keep compiler happy
164 }
165 }
166
167 public boolean handleInputExtension(
168 TWSDLParserContext context,
169 TWSDLExtensible parent,
170 Element e) {
171 return handleInputOutputExtension(context, parent, e);
172 }
173 public boolean handleOutputExtension(
174 TWSDLParserContext context,
175 TWSDLExtensible parent,
176 Element e) {
177 return handleInputOutputExtension(context, parent, e);
178 }
179
180 @Override
181 protected boolean handleMIMEPartExtension(
182 TWSDLParserContext context,
183 TWSDLExtensible parent,
184 Element e) {
185 return handleInputOutputExtension(context, parent, e);
186 }
187
188 protected boolean handleInputOutputExtension(
189 TWSDLParserContext contextif,
190 TWSDLExtensible parent,
191 Element e) {
192 TWSDLParserContextImpl context = (TWSDLParserContextImpl)contextif;
193 if (XmlUtil.matchesTagNS(e, getBodyQName())) {
194 context.push();
195 context.registerNamespaces(e);
196
197 SOAPBody body = new SOAPBody(context.getLocation(e));
198
199 String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
200 if (use != null) {
201 if (use.equals(Constants.ATTRVALUE_LITERAL)) {
202 body.setUse(SOAPUse.LITERAL);
203 } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
204 body.setUse(SOAPUse.ENCODED);
205 } else {
206 Util.fail(
207 "parsing.invalidAttributeValue",
208 Constants.ATTR_USE,
209 use);
210 }
211 }
212
213 String namespace =
214 XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
215 if (namespace != null) {
216 body.setNamespace(namespace);
217 }
218
219 String encodingStyle =
220 XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
221 if (encodingStyle != null) {
222 body.setEncodingStyle(encodingStyle);
223 }
224
225 String parts = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARTS);
226 if (parts != null) {
227 body.setParts(parts);
228 }
229
230 parent.addExtension(body);
231 context.pop();
232 // context.fireDoneParsingEntity(getBodyQName(), body);
233 return true;
234 } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
235 context.push();
236 context.registerNamespaces(e);
237
238 SOAPHeader header = new SOAPHeader(context.getLocation(e));
239
240 String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
241 if (use != null) {
242 if (use.equals(Constants.ATTRVALUE_LITERAL)) {
243 header.setUse(SOAPUse.LITERAL);
244 } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
245 header.setUse(SOAPUse.ENCODED);
246 } else {
247 Util.fail(
248 "parsing.invalidAttributeValue",
249 Constants.ATTR_USE,
250 use);
251 }
252 }
253
254 String namespace =
255 XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
256 if (namespace != null) {
257 header.setNamespace(namespace);
258 }
259
260 String encodingStyle =
261 XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
262 if (encodingStyle != null) {
263 header.setEncodingStyle(encodingStyle);
264 }
265
266 String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
267 if (part != null) {
268 header.setPart(part);
269 }
270
271 String messageAttr =
272 XmlUtil.getAttributeOrNull(e, Constants.ATTR_MESSAGE);
273 if (messageAttr != null) {
274 header.setMessage(context.translateQualifiedName(context.getLocation(e), messageAttr));
275 }
276
277 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
278 Element e2 = Util.nextElement(iter);
279 if (e2 == null)
280 break;
281
282 if (XmlUtil
283 .matchesTagNS(e2, getHeaderfaultQName())) {
284 context.push();
285 context.registerNamespaces(e);
286
287 SOAPHeaderFault headerfault = new SOAPHeaderFault(context.getLocation(e));
288
289 String use2 =
290 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_USE);
291 if (use2 != null) {
292 if (use2.equals(Constants.ATTRVALUE_LITERAL)) {
293 headerfault.setUse(SOAPUse.LITERAL);
294 } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
295 headerfault.setUse(SOAPUse.ENCODED);
296 } else {
297 Util.fail(
298 "parsing.invalidAttributeValue",
299 Constants.ATTR_USE,
300 use2);
301 }
302 }
303
304 String namespace2 =
305 XmlUtil.getAttributeOrNull(
306 e2,
307 Constants.ATTR_NAMESPACE);
308 if (namespace2 != null) {
309 headerfault.setNamespace(namespace2);
310 }
311
312 String encodingStyle2 =
313 XmlUtil.getAttributeOrNull(
314 e2,
315 Constants.ATTR_ENCODING_STYLE);
316 if (encodingStyle2 != null) {
317 headerfault.setEncodingStyle(encodingStyle2);
318 }
319
320 String part2 =
321 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_PART);
322 if (part2 != null) {
323 headerfault.setPart(part2);
324 }
325
326 String messageAttr2 =
327 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_MESSAGE);
328 if (messageAttr2 != null) {
329 headerfault.setMessage(
330 context.translateQualifiedName(context.getLocation(e2), messageAttr2));
331 }
332
333 header.add(headerfault);
334 context.pop();
335 } else {
336 Util.fail(
337 "parsing.invalidElement",
338 e2.getTagName(),
339 e2.getNamespaceURI());
340 }
341 }
342
343 parent.addExtension(header);
344 context.pop();
345 context.fireDoneParsingEntity(getHeaderQName(), header);
346 return true;
347 } else {
348 Util.fail(
349 "parsing.invalidExtensionElement",
350 e.getTagName(),
351 e.getNamespaceURI());
352 return false; // keep compiler happy
353 }
354 }
355
356 public boolean handleFaultExtension(
357 TWSDLParserContext context,
358 TWSDLExtensible parent,
359 Element e) {
360 if (XmlUtil.matchesTagNS(e, getFaultQName())) {
361 context.push();
362 context.registerNamespaces(e);
363
364 SOAPFault fault = new SOAPFault(context.getLocation(e));
365
366 String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
367 if (name != null) {
368 fault.setName(name);
369 }
370
371 String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
372 if (use != null) {
373 if (use.equals(Constants.ATTRVALUE_LITERAL)) {
374 fault.setUse(SOAPUse.LITERAL);
375 } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
376 fault.setUse(SOAPUse.ENCODED);
377 } else {
378 Util.fail(
379 "parsing.invalidAttributeValue",
380 Constants.ATTR_USE,
381 use);
382 }
383 }
384
385 String namespace =
386 XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
387 if (namespace != null) {
388 fault.setNamespace(namespace);
389 }
390
391 String encodingStyle =
392 XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
393 if (encodingStyle != null) {
394 fault.setEncodingStyle(encodingStyle);
395 }
396
397 parent.addExtension(fault);
398 context.pop();
399 // context.fireDoneParsingEntity(getFaultQName(), fault);
400 return true;
401 } else {
402 Util.fail(
403 "parsing.invalidExtensionElement",
404 e.getTagName(),
405 e.getNamespaceURI());
406 return false; // keep compiler happy
407 }
408 }
409
410 public boolean handleServiceExtension(
411 TWSDLParserContext context,
412 TWSDLExtensible parent,
413 Element e) {
414 Util.fail(
415 "parsing.invalidExtensionElement",
416 e.getTagName(),
417 e.getNamespaceURI());
418 return false; // keep compiler happy
419 }
420
421 @Override
422 public boolean handlePortExtension(
423 TWSDLParserContext context,
424 TWSDLExtensible parent,
425 Element e) {
426 if (XmlUtil.matchesTagNS(e, getAddressQName())) {
427 context.push();
428 context.registerNamespaces(e);
429
430 SOAPAddress address = new SOAPAddress(context.getLocation(e));
431
432 String location =
433 Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
434 address.setLocation(location);
435
436 parent.addExtension(address);
437 context.pop();
438 // context.fireDoneParsingEntity(getAddressQName(), address);
439 return true;
440 } else {
441 Util.fail(
442 "parsing.invalidExtensionElement",
443 e.getTagName(),
444 e.getNamespaceURI());
445 return false; // keep compiler happy
446 }
447 }
448
449 public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
450 Util.fail(
451 "parsing.invalidExtensionElement",
452 e.getTagName(),
453 e.getNamespaceURI());
454 return false; // keep compiler happy
455 }
456
457 protected QName getBodyQName(){
458 return SOAPConstants.QNAME_BODY;
459 }
460
461 protected QName getHeaderQName(){
462 return SOAPConstants.QNAME_HEADER;
463 }
464
465 protected QName getHeaderfaultQName(){
466 return SOAPConstants.QNAME_HEADERFAULT;
467 }
468
469 protected QName getOperationQName(){
470 return SOAPConstants.QNAME_OPERATION;
471 }
472
473 protected QName getFaultQName(){
474 return SOAPConstants.QNAME_FAULT;
475 }
476
477 protected QName getAddressQName(){
478 return SOAPConstants.QNAME_ADDRESS;
479 }
480
481 protected QName getBindingQName(){
482 return SOAPConstants.QNAME_BINDING;
483 }
484 }

mercurial