325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.tools.internal.ws.wsdl.parser;
325N/A
325N/Aimport com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
325N/Aimport com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
325N/Aimport com.sun.tools.internal.ws.util.xml.XmlUtil;
325N/Aimport com.sun.tools.internal.ws.wsdl.document.soap.*;
325N/Aimport com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
325N/Aimport org.w3c.dom.Element;
325N/Aimport org.xml.sax.Locator;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.Map;
325N/A
325N/A/**
325N/A * The SOAP extension handler for WSDL.
325N/A *
325N/A * @author WS Development Team
325N/A */
325N/Apublic class SOAPExtensionHandler extends AbstractExtensionHandler {
325N/A
325N/A public SOAPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
325N/A super(extensionHandlerMap);
325N/A }
325N/A
325N/A public String getNamespaceURI() {
325N/A return Constants.NS_WSDL_SOAP;
325N/A }
325N/A
325N/A public boolean handleDefinitionsExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A
325N/A public boolean handleTypesExtension(
325N/A com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A
325N/A protected SOAPBinding getSOAPBinding(Locator location){
325N/A return new SOAPBinding(location);
325N/A }
325N/A
325N/A public boolean handleBindingExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A if (XmlUtil.matchesTagNS(e, getBindingQName())) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPBinding binding = getSOAPBinding(context.getLocation(e));
325N/A
325N/A // NOTE - the "transport" attribute is required according to section 3.3 of the WSDL 1.1 spec,
325N/A // but optional according to the schema in appendix A 4.2 of the same document!
325N/A String transport =
325N/A Util.getRequiredAttribute(e, Constants.ATTR_TRANSPORT);
325N/A binding.setTransport(transport);
325N/A
325N/A String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
325N/A if (style != null) {
325N/A if (style.equals(Constants.ATTRVALUE_RPC)) {
325N/A binding.setStyle(SOAPStyle.RPC);
325N/A } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
325N/A binding.setStyle(SOAPStyle.DOCUMENT);
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidAttributeValue",
325N/A Constants.ATTR_STYLE,
325N/A style);
325N/A }
325N/A }
325N/A parent.addExtension(binding);
325N/A context.pop();
325N/A// context.fireDoneParsingEntity(getBindingQName(), binding);
325N/A return true;
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A }
325N/A
325N/A public boolean handleOperationExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A if (XmlUtil.matchesTagNS(e, getOperationQName())) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPOperation operation = new SOAPOperation(context.getLocation(e));
325N/A
325N/A String soapAction =
325N/A XmlUtil.getAttributeOrNull(e, Constants.ATTR_SOAP_ACTION);
325N/A if (soapAction != null) {
325N/A operation.setSOAPAction(soapAction);
325N/A }
325N/A
325N/A String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
325N/A if (style != null) {
325N/A if (style.equals(Constants.ATTRVALUE_RPC)) {
325N/A operation.setStyle(SOAPStyle.RPC);
325N/A } else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
325N/A operation.setStyle(SOAPStyle.DOCUMENT);
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidAttributeValue",
325N/A Constants.ATTR_STYLE,
325N/A style);
325N/A }
325N/A }
325N/A parent.addExtension(operation);
325N/A context.pop();
325N/A// context.fireDoneParsingEntity(
325N/A// getOperationQName(),
325N/A// operation);
325N/A return true;
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A }
325N/A
325N/A public boolean handleInputExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A return handleInputOutputExtension(context, parent, e);
325N/A }
325N/A public boolean handleOutputExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A return handleInputOutputExtension(context, parent, e);
325N/A }
325N/A
325N/A @Override
325N/A protected boolean handleMIMEPartExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A return handleInputOutputExtension(context, parent, e);
325N/A }
325N/A
325N/A protected boolean handleInputOutputExtension(
325N/A TWSDLParserContext contextif,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A TWSDLParserContextImpl context = (TWSDLParserContextImpl)contextif;
325N/A if (XmlUtil.matchesTagNS(e, getBodyQName())) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPBody body = new SOAPBody(context.getLocation(e));
325N/A
325N/A String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
325N/A if (use != null) {
325N/A if (use.equals(Constants.ATTRVALUE_LITERAL)) {
325N/A body.setUse(SOAPUse.LITERAL);
325N/A } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
325N/A body.setUse(SOAPUse.ENCODED);
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidAttributeValue",
325N/A Constants.ATTR_USE,
325N/A use);
325N/A }
325N/A }
325N/A
325N/A String namespace =
325N/A XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
325N/A if (namespace != null) {
325N/A body.setNamespace(namespace);
325N/A }
325N/A
325N/A String encodingStyle =
325N/A XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
325N/A if (encodingStyle != null) {
325N/A body.setEncodingStyle(encodingStyle);
325N/A }
325N/A
325N/A String parts = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARTS);
325N/A if (parts != null) {
325N/A body.setParts(parts);
325N/A }
325N/A
325N/A parent.addExtension(body);
325N/A context.pop();
325N/A// context.fireDoneParsingEntity(getBodyQName(), body);
325N/A return true;
325N/A } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
325N/A return handleHeaderElement(parent, e, context);
325N/A } else {
325N/A Util.fail("parsing.invalidExtensionElement", e.getTagName(), e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A }
325N/A
325N/A private boolean handleHeaderElement(TWSDLExtensible parent, Element e, TWSDLParserContextImpl context) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPHeader header = new SOAPHeader(context.getLocation(e));
325N/A
325N/A String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
325N/A if (use != null) {
325N/A if (use.equals(Constants.ATTRVALUE_LITERAL)) {
325N/A header.setUse(SOAPUse.LITERAL);
325N/A } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
325N/A header.setUse(SOAPUse.ENCODED);
325N/A } else {
325N/A Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use);
325N/A }
325N/A }
325N/A
325N/A String namespace = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
325N/A if (namespace != null) {
325N/A header.setNamespace(namespace);
325N/A }
325N/A
325N/A String encodingStyle = XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
325N/A if (encodingStyle != null) {
325N/A header.setEncodingStyle(encodingStyle);
325N/A }
325N/A
325N/A String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
325N/A if (part != null) {
325N/A header.setPart(part);
325N/A }
325N/A
325N/A String messageAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_MESSAGE);
325N/A if (messageAttr != null) {
325N/A header.setMessage(context.translateQualifiedName(context.getLocation(e), messageAttr));
325N/A }
325N/A
325N/A for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
325N/A Element e2 = Util.nextElement(iter);
325N/A if (e2 == null)
325N/A break;
325N/A
325N/A if (XmlUtil.matchesTagNS(e2, getHeaderfaultQName())) {
325N/A handleHeaderFaultElement(e, context, header, use, e2);
325N/A } else {
325N/A Util.fail("parsing.invalidElement", e2.getTagName(), e2.getNamespaceURI());
325N/A }
325N/A }
325N/A
325N/A parent.addExtension(header);
325N/A context.pop();
325N/A context.fireDoneParsingEntity(getHeaderQName(), header);
325N/A return true;
325N/A }
325N/A
325N/A private void handleHeaderFaultElement(Element e, TWSDLParserContextImpl context, SOAPHeader header, String use, Element e2) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPHeaderFault headerfault = new SOAPHeaderFault(context.getLocation(e));
325N/A
325N/A String use2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_USE);
325N/A if (use2 != null) {
325N/A if (use2.equals(Constants.ATTRVALUE_LITERAL)) {
325N/A headerfault.setUse(SOAPUse.LITERAL);
325N/A } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
325N/A headerfault.setUse(SOAPUse.ENCODED);
325N/A } else {
325N/A Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use2);
325N/A }
325N/A }
325N/A
325N/A String namespace2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAMESPACE);
325N/A if (namespace2 != null) {
325N/A headerfault.setNamespace(namespace2);
325N/A }
325N/A
325N/A String encodingStyle2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_ENCODING_STYLE);
325N/A if (encodingStyle2 != null) {
325N/A headerfault.setEncodingStyle(encodingStyle2);
325N/A }
325N/A
325N/A String part2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_PART);
325N/A if (part2 != null) {
325N/A headerfault.setPart(part2);
325N/A }
325N/A
325N/A String messageAttr2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_MESSAGE);
325N/A if (messageAttr2 != null) {
325N/A headerfault.setMessage(
325N/A context.translateQualifiedName(context.getLocation(e2), messageAttr2));
325N/A }
325N/A
325N/A header.add(headerfault);
325N/A context.pop();
325N/A }
325N/A
325N/A public boolean handleFaultExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A if (XmlUtil.matchesTagNS(e, getFaultQName())) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPFault fault = new SOAPFault(context.getLocation(e));
325N/A
325N/A String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
325N/A if (name != null) {
325N/A fault.setName(name);
325N/A }
325N/A
325N/A String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
325N/A if (use != null) {
325N/A if (use.equals(Constants.ATTRVALUE_LITERAL)) {
325N/A fault.setUse(SOAPUse.LITERAL);
325N/A } else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
325N/A fault.setUse(SOAPUse.ENCODED);
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidAttributeValue",
325N/A Constants.ATTR_USE,
325N/A use);
325N/A }
325N/A }
325N/A
325N/A String namespace =
325N/A XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
325N/A if (namespace != null) {
325N/A fault.setNamespace(namespace);
325N/A }
325N/A
325N/A String encodingStyle =
325N/A XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
325N/A if (encodingStyle != null) {
325N/A fault.setEncodingStyle(encodingStyle);
325N/A }
325N/A
325N/A parent.addExtension(fault);
325N/A context.pop();
325N/A// context.fireDoneParsingEntity(getFaultQName(), fault);
325N/A return true;
325N/A } else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
325N/A // although SOAP spec doesn't define meaning of this extension; it is allowed
325N/A // to be here, so we have to accept it, not fail (bug 13576977)
325N/A return handleHeaderElement(parent, e, (TWSDLParserContextImpl) context);
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A }
325N/A
325N/A public boolean handleServiceExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A
325N/A @Override
325N/A public boolean handlePortExtension(
325N/A TWSDLParserContext context,
325N/A TWSDLExtensible parent,
325N/A Element e) {
325N/A if (XmlUtil.matchesTagNS(e, getAddressQName())) {
325N/A context.push();
325N/A context.registerNamespaces(e);
325N/A
325N/A SOAPAddress address = new SOAPAddress(context.getLocation(e));
325N/A
325N/A String location =
325N/A Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
325N/A address.setLocation(location);
325N/A
325N/A parent.addExtension(address);
325N/A context.pop();
325N/A// context.fireDoneParsingEntity(getAddressQName(), address);
325N/A return true;
325N/A } else {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A }
325N/A
325N/A public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
325N/A Util.fail(
325N/A "parsing.invalidExtensionElement",
325N/A e.getTagName(),
325N/A e.getNamespaceURI());
325N/A return false; // keep compiler happy
325N/A }
325N/A
325N/A protected QName getBodyQName(){
325N/A return SOAPConstants.QNAME_BODY;
325N/A }
325N/A
325N/A protected QName getHeaderQName(){
325N/A return SOAPConstants.QNAME_HEADER;
325N/A }
325N/A
325N/A protected QName getHeaderfaultQName(){
325N/A return SOAPConstants.QNAME_HEADERFAULT;
325N/A }
325N/A
325N/A protected QName getOperationQName(){
325N/A return SOAPConstants.QNAME_OPERATION;
325N/A }
325N/A
325N/A protected QName getFaultQName(){
325N/A return SOAPConstants.QNAME_FAULT;
325N/A }
325N/A
325N/A protected QName getAddressQName(){
325N/A return SOAPConstants.QNAME_ADDRESS;
325N/A }
325N/A
325N/A protected QName getBindingQName(){
325N/A return SOAPConstants.QNAME_BINDING;
325N/A }
325N/A}