001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.wsdl.parser;
038:
039: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
040: import com.sun.tools.ws.api.wsdl.TWSDLParserContext;
041: import com.sun.tools.ws.util.xml.XmlUtil;
042: import com.sun.tools.ws.wsdl.document.soap.*;
043: import com.sun.tools.ws.wsdl.framework.TWSDLParserContextImpl;
044: import org.w3c.dom.Element;
045: import org.xml.sax.Locator;
046:
047: import javax.xml.namespace.QName;
048: import java.util.Iterator;
049: import java.util.Map;
050:
051: /**
052: * The SOAP extension handler for WSDL.
053: *
054: * @author WS Development Team
055: */
056: public class SOAPExtensionHandler extends AbstractExtensionHandler {
057:
058: public SOAPExtensionHandler(
059: Map<String, AbstractExtensionHandler> extensionHandlerMap) {
060: super (extensionHandlerMap);
061: }
062:
063: public String getNamespaceURI() {
064: return Constants.NS_WSDL_SOAP;
065: }
066:
067: public boolean handleDefinitionsExtension(
068: TWSDLParserContext context, TWSDLExtensible parent,
069: Element e) {
070: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
071: .getNamespaceURI());
072: return false; // keep compiler happy
073: }
074:
075: public boolean handleTypesExtension(
076: com.sun.tools.ws.api.wsdl.TWSDLParserContext context,
077: TWSDLExtensible parent, Element e) {
078: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
079: .getNamespaceURI());
080: return false; // keep compiler happy
081: }
082:
083: protected SOAPBinding getSOAPBinding(Locator location) {
084: return new SOAPBinding(location);
085: }
086:
087: public boolean handleBindingExtension(TWSDLParserContext context,
088: TWSDLExtensible parent, Element e) {
089: if (XmlUtil.matchesTagNS(e, getBindingQName())) {
090: context.push();
091: context.registerNamespaces(e);
092:
093: SOAPBinding binding = getSOAPBinding(context.getLocation(e));
094:
095: // NOTE - the "transport" attribute is required according to section 3.3 of the WSDL 1.1 spec,
096: // but optional according to the schema in appendix A 4.2 of the same document!
097: String transport = Util.getRequiredAttribute(e,
098: Constants.ATTR_TRANSPORT);
099: binding.setTransport(transport);
100:
101: String style = XmlUtil.getAttributeOrNull(e,
102: Constants.ATTR_STYLE);
103: if (style != null) {
104: if (style.equals(Constants.ATTRVALUE_RPC)) {
105: binding.setStyle(SOAPStyle.RPC);
106: } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
107: binding.setStyle(SOAPStyle.DOCUMENT);
108: } else {
109: Util.fail("parsing.invalidAttributeValue",
110: Constants.ATTR_STYLE, style);
111: }
112: }
113: parent.addExtension(binding);
114: context.pop();
115: // context.fireDoneParsingEntity(getBindingQName(), binding);
116: return true;
117: } else {
118: Util.fail("parsing.invalidExtensionElement",
119: e.getTagName(), e.getNamespaceURI());
120: return false; // keep compiler happy
121: }
122: }
123:
124: public boolean handleOperationExtension(TWSDLParserContext context,
125: TWSDLExtensible parent, Element e) {
126: if (XmlUtil.matchesTagNS(e, getOperationQName())) {
127: context.push();
128: context.registerNamespaces(e);
129:
130: SOAPOperation operation = new SOAPOperation(context
131: .getLocation(e));
132:
133: String soapAction = XmlUtil.getAttributeOrNull(e,
134: Constants.ATTR_SOAP_ACTION);
135: if (soapAction != null) {
136: operation.setSOAPAction(soapAction);
137: }
138:
139: String style = XmlUtil.getAttributeOrNull(e,
140: Constants.ATTR_STYLE);
141: if (style != null) {
142: if (style.equals(Constants.ATTRVALUE_RPC)) {
143: operation.setStyle(SOAPStyle.RPC);
144: } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
145: operation.setStyle(SOAPStyle.DOCUMENT);
146: } else {
147: Util.fail("parsing.invalidAttributeValue",
148: Constants.ATTR_STYLE, style);
149: }
150: }
151: parent.addExtension(operation);
152: context.pop();
153: // context.fireDoneParsingEntity(
154: // getOperationQName(),
155: // operation);
156: return true;
157: } else {
158: Util.fail("parsing.invalidExtensionElement",
159: e.getTagName(), e.getNamespaceURI());
160: return false; // keep compiler happy
161: }
162: }
163:
164: public boolean handleInputExtension(TWSDLParserContext context,
165: TWSDLExtensible parent, Element e) {
166: return handleInputOutputExtension(context, parent, e);
167: }
168:
169: public boolean handleOutputExtension(TWSDLParserContext context,
170: TWSDLExtensible parent, Element e) {
171: return handleInputOutputExtension(context, parent, e);
172: }
173:
174: @Override
175: protected boolean handleMIMEPartExtension(
176: TWSDLParserContext context, TWSDLExtensible parent,
177: Element e) {
178: return handleInputOutputExtension(context, parent, e);
179: }
180:
181: protected boolean handleInputOutputExtension(
182: TWSDLParserContext contextif, TWSDLExtensible parent,
183: Element e) {
184: TWSDLParserContextImpl context = (TWSDLParserContextImpl) contextif;
185: if (XmlUtil.matchesTagNS(e, getBodyQName())) {
186: context.push();
187: context.registerNamespaces(e);
188:
189: SOAPBody body = new SOAPBody(context.getLocation(e));
190:
191: String use = XmlUtil.getAttributeOrNull(e,
192: Constants.ATTR_USE);
193: if (use != null) {
194: if (use.equals(Constants.ATTRVALUE_LITERAL)) {
195: body.setUse(SOAPUse.LITERAL);
196: } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
197: body.setUse(SOAPUse.ENCODED);
198: } else {
199: Util.fail("parsing.invalidAttributeValue",
200: Constants.ATTR_USE, use);
201: }
202: }
203:
204: String namespace = XmlUtil.getAttributeOrNull(e,
205: Constants.ATTR_NAMESPACE);
206: if (namespace != null) {
207: body.setNamespace(namespace);
208: }
209:
210: String encodingStyle = XmlUtil.getAttributeOrNull(e,
211: Constants.ATTR_ENCODING_STYLE);
212: if (encodingStyle != null) {
213: body.setEncodingStyle(encodingStyle);
214: }
215:
216: String parts = XmlUtil.getAttributeOrNull(e,
217: Constants.ATTR_PARTS);
218: if (parts != null) {
219: body.setParts(parts);
220: }
221:
222: parent.addExtension(body);
223: context.pop();
224: // context.fireDoneParsingEntity(getBodyQName(), body);
225: return true;
226: } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
227: context.push();
228: context.registerNamespaces(e);
229:
230: SOAPHeader header = new SOAPHeader(context.getLocation(e));
231:
232: String use = XmlUtil.getAttributeOrNull(e,
233: Constants.ATTR_USE);
234: if (use != null) {
235: if (use.equals(Constants.ATTRVALUE_LITERAL)) {
236: header.setUse(SOAPUse.LITERAL);
237: } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
238: header.setUse(SOAPUse.ENCODED);
239: } else {
240: Util.fail("parsing.invalidAttributeValue",
241: Constants.ATTR_USE, use);
242: }
243: }
244:
245: String namespace = XmlUtil.getAttributeOrNull(e,
246: Constants.ATTR_NAMESPACE);
247: if (namespace != null) {
248: header.setNamespace(namespace);
249: }
250:
251: String encodingStyle = XmlUtil.getAttributeOrNull(e,
252: Constants.ATTR_ENCODING_STYLE);
253: if (encodingStyle != null) {
254: header.setEncodingStyle(encodingStyle);
255: }
256:
257: String part = XmlUtil.getAttributeOrNull(e,
258: Constants.ATTR_PART);
259: if (part != null) {
260: header.setPart(part);
261: }
262:
263: String messageAttr = XmlUtil.getAttributeOrNull(e,
264: Constants.ATTR_MESSAGE);
265: if (messageAttr != null) {
266: header.setMessage(context.translateQualifiedName(
267: context.getLocation(e), messageAttr));
268: }
269:
270: for (Iterator iter = XmlUtil.getAllChildren(e); iter
271: .hasNext();) {
272: Element e2 = Util.nextElement(iter);
273: if (e2 == null)
274: break;
275:
276: if (XmlUtil.matchesTagNS(e2, getHeaderfaultQName())) {
277: context.push();
278: context.registerNamespaces(e);
279:
280: SOAPHeaderFault headerfault = new SOAPHeaderFault(
281: context.getLocation(e));
282:
283: String use2 = XmlUtil.getAttributeOrNull(e2,
284: Constants.ATTR_USE);
285: if (use2 != null) {
286: if (use2.equals(Constants.ATTRVALUE_LITERAL)) {
287: headerfault.setUse(SOAPUse.LITERAL);
288: } else if (use
289: .equals(Constants.ATTRVALUE_ENCODED)) {
290: headerfault.setUse(SOAPUse.ENCODED);
291: } else {
292: Util.fail("parsing.invalidAttributeValue",
293: Constants.ATTR_USE, use2);
294: }
295: }
296:
297: String namespace2 = XmlUtil.getAttributeOrNull(e2,
298: Constants.ATTR_NAMESPACE);
299: if (namespace2 != null) {
300: headerfault.setNamespace(namespace2);
301: }
302:
303: String encodingStyle2 = XmlUtil.getAttributeOrNull(
304: e2, Constants.ATTR_ENCODING_STYLE);
305: if (encodingStyle2 != null) {
306: headerfault.setEncodingStyle(encodingStyle2);
307: }
308:
309: String part2 = XmlUtil.getAttributeOrNull(e2,
310: Constants.ATTR_PART);
311: if (part2 != null) {
312: headerfault.setPart(part2);
313: }
314:
315: String messageAttr2 = XmlUtil.getAttributeOrNull(
316: e2, Constants.ATTR_MESSAGE);
317: if (messageAttr2 != null) {
318: headerfault
319: .setMessage(context
320: .translateQualifiedName(context
321: .getLocation(e2),
322: messageAttr2));
323: }
324:
325: header.add(headerfault);
326: context.pop();
327: } else {
328: Util.fail("parsing.invalidElement",
329: e2.getTagName(), e2.getNamespaceURI());
330: }
331: }
332:
333: parent.addExtension(header);
334: context.pop();
335: context.fireDoneParsingEntity(getHeaderQName(), header);
336: return true;
337: } else {
338: Util.fail("parsing.invalidExtensionElement",
339: e.getTagName(), e.getNamespaceURI());
340: return false; // keep compiler happy
341: }
342: }
343:
344: public boolean handleFaultExtension(TWSDLParserContext context,
345: TWSDLExtensible parent, Element e) {
346: if (XmlUtil.matchesTagNS(e, getFaultQName())) {
347: context.push();
348: context.registerNamespaces(e);
349:
350: SOAPFault fault = new SOAPFault(context.getLocation(e));
351:
352: String name = XmlUtil.getAttributeOrNull(e,
353: Constants.ATTR_NAME);
354: if (name != null) {
355: fault.setName(name);
356: }
357:
358: String use = XmlUtil.getAttributeOrNull(e,
359: Constants.ATTR_USE);
360: if (use != null) {
361: if (use.equals(Constants.ATTRVALUE_LITERAL)) {
362: fault.setUse(SOAPUse.LITERAL);
363: } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
364: fault.setUse(SOAPUse.ENCODED);
365: } else {
366: Util.fail("parsing.invalidAttributeValue",
367: Constants.ATTR_USE, use);
368: }
369: }
370:
371: String namespace = XmlUtil.getAttributeOrNull(e,
372: Constants.ATTR_NAMESPACE);
373: if (namespace != null) {
374: fault.setNamespace(namespace);
375: }
376:
377: String encodingStyle = XmlUtil.getAttributeOrNull(e,
378: Constants.ATTR_ENCODING_STYLE);
379: if (encodingStyle != null) {
380: fault.setEncodingStyle(encodingStyle);
381: }
382:
383: parent.addExtension(fault);
384: context.pop();
385: // context.fireDoneParsingEntity(getFaultQName(), fault);
386: return true;
387: } else {
388: Util.fail("parsing.invalidExtensionElement",
389: e.getTagName(), e.getNamespaceURI());
390: return false; // keep compiler happy
391: }
392: }
393:
394: public boolean handleServiceExtension(TWSDLParserContext context,
395: TWSDLExtensible parent, Element e) {
396: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
397: .getNamespaceURI());
398: return false; // keep compiler happy
399: }
400:
401: @Override
402: public boolean handlePortExtension(TWSDLParserContext context,
403: TWSDLExtensible parent, Element e) {
404: if (XmlUtil.matchesTagNS(e, getAddressQName())) {
405: context.push();
406: context.registerNamespaces(e);
407:
408: SOAPAddress address = new SOAPAddress(context
409: .getLocation(e));
410:
411: String location = Util.getRequiredAttribute(e,
412: Constants.ATTR_LOCATION);
413: address.setLocation(location);
414:
415: parent.addExtension(address);
416: context.pop();
417: // context.fireDoneParsingEntity(getAddressQName(), address);
418: return true;
419: } else {
420: Util.fail("parsing.invalidExtensionElement",
421: e.getTagName(), e.getNamespaceURI());
422: return false; // keep compiler happy
423: }
424: }
425:
426: public boolean handlePortTypeExtension(TWSDLParserContext context,
427: TWSDLExtensible parent, Element e) {
428: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
429: .getNamespaceURI());
430: return false; // keep compiler happy
431: }
432:
433: protected QName getBodyQName() {
434: return SOAPConstants.QNAME_BODY;
435: }
436:
437: protected QName getHeaderQName() {
438: return SOAPConstants.QNAME_HEADER;
439: }
440:
441: protected QName getHeaderfaultQName() {
442: return SOAPConstants.QNAME_HEADERFAULT;
443: }
444:
445: protected QName getOperationQName() {
446: return SOAPConstants.QNAME_OPERATION;
447: }
448:
449: protected QName getFaultQName() {
450: return SOAPConstants.QNAME_FAULT;
451: }
452:
453: protected QName getAddressQName() {
454: return SOAPConstants.QNAME_ADDRESS;
455: }
456:
457: protected QName getBindingQName() {
458: return SOAPConstants.QNAME_BINDING;
459: }
460: }
|