Search in sources :

Example 1 with BindingFault

use of com.sun.tools.ws.wsdl.document.BindingFault in project metro-jax-ws by eclipse-ee4j.

the class WSDLParser method parseBindingOperation.

private BindingOperation parseBindingOperation(TWSDLParserContextImpl context, Element e) {
    context.push();
    context.registerNamespaces(e);
    BindingOperation operation = new BindingOperation(forest.locatorTable.getStartLocation(e));
    String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
    operation.setName(name);
    boolean gotDocumentation = false;
    boolean gotInput = false;
    boolean gotOutput = false;
    boolean gotFault = false;
    boolean inputBeforeOutput = false;
    for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext(); ) {
        Element e2 = Util.nextElement(iter);
        if (e2 == null)
            break;
        if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) {
            if (gotDocumentation) {
                errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
            }
            gotDocumentation = true;
            operation.setDocumentation(getDocumentationFor(e2));
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_INPUT)) {
            if (gotInput) {
                errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, Constants.TAG_OPERATION, name));
            }
            /* Here we check for the use scenario */
            context.push();
            context.registerNamespaces(e2);
            BindingInput input = new BindingInput(forest.locatorTable.getStartLocation(e2));
            String nameAttr = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
            input.setName(nameAttr);
            operation.setInput(input);
            gotInput = true;
            if (gotOutput) {
                inputBeforeOutput = false;
            }
            // verify that there is at most one child element and it is a documentation element
            boolean gotDocumentation2 = false;
            for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2.hasNext(); ) {
                Element e3 = Util.nextElement(iter2);
                if (e3 == null)
                    break;
                if (XmlUtil.matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
                    if (gotDocumentation2) {
                        errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
                    }
                    gotDocumentation2 = true;
                    input.setDocumentation(getDocumentationFor(e3));
                } else {
                    // possible extensibility element -- must live outside the WSDL namespace
                    checkNotWsdlElement(e3);
                    if (!handleExtension(context, input, e3)) {
                        checkNotWsdlRequired(e3);
                    }
                }
            }
            context.pop();
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_OUTPUT)) {
            if (gotOutput) {
                errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_TOO_MANY_ELEMENTS(Constants.TAG_INPUT, Constants.TAG_OPERATION, name));
            }
            context.push();
            context.registerNamespaces(e2);
            BindingOutput output = new BindingOutput(forest.locatorTable.getStartLocation(e2));
            String nameAttr = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
            output.setName(nameAttr);
            operation.setOutput(output);
            gotOutput = true;
            if (gotInput) {
                inputBeforeOutput = true;
            }
            // verify that there is at most one child element and it is a documentation element
            boolean gotDocumentation2 = false;
            for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2.hasNext(); ) {
                Element e3 = Util.nextElement(iter2);
                if (e3 == null)
                    break;
                if (XmlUtil.matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
                    if (gotDocumentation2) {
                        errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
                    }
                    gotDocumentation2 = true;
                    output.setDocumentation(getDocumentationFor(e3));
                } else {
                    // possible extensibility element -- must live outside the WSDL namespace
                    checkNotWsdlElement(e3);
                    if (!handleExtension(context, output, e3)) {
                        checkNotWsdlRequired(e3);
                    }
                }
            }
            context.pop();
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) {
            context.push();
            context.registerNamespaces(e2);
            BindingFault fault = new BindingFault(forest.locatorTable.getStartLocation(e2));
            String nameAttr = Util.getRequiredAttribute(e2, Constants.ATTR_NAME);
            fault.setName(nameAttr);
            operation.addFault(fault);
            gotFault = true;
            // verify that there is at most one child element and it is a documentation element
            boolean gotDocumentation2 = false;
            for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2.hasNext(); ) {
                Element e3 = Util.nextElement(iter2);
                if (e3 == null)
                    break;
                if (XmlUtil.matchesTagNS(e3, WSDLConstants.QNAME_DOCUMENTATION)) {
                    if (gotDocumentation2) {
                        errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName()));
                    }
                    gotDocumentation2 = true;
                    if (fault.getDocumentation() == null)
                        fault.setDocumentation(getDocumentationFor(e3));
                } else {
                    // possible extensibility element -- must live outside the WSDL namespace
                    checkNotWsdlElement(e3);
                    if (!handleExtension(context, fault, e3)) {
                        checkNotWsdlRequired(e3);
                    }
                }
            }
            context.pop();
        } else {
            // possible extensibility element -- must live outside the WSDL namespace
            checkNotWsdlElement(e2);
            if (!handleExtension(context, operation, e2)) {
                checkNotWsdlRequired(e2);
            }
        }
    }
    if (gotInput && !gotOutput && !gotFault) {
        operation.setStyle(OperationStyle.ONE_WAY);
    } else if (gotInput && gotOutput && inputBeforeOutput) {
        operation.setStyle(OperationStyle.REQUEST_RESPONSE);
    } else if (gotInput && gotOutput && !inputBeforeOutput) {
        operation.setStyle(OperationStyle.SOLICIT_RESPONSE);
    } else if (gotOutput && !gotInput && !gotFault) {
        operation.setStyle(OperationStyle.NOTIFICATION);
    } else {
        errReceiver.error(forest.locatorTable.getStartLocation(e), WsdlMessages.PARSING_INVALID_OPERATION_STYLE(name));
    }
    context.pop();
    context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION, operation);
    return operation;
}
Also used : BindingOperation(com.sun.tools.ws.wsdl.document.BindingOperation) BindingOutput(com.sun.tools.ws.wsdl.document.BindingOutput) BindingFault(com.sun.tools.ws.wsdl.document.BindingFault) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) BindingInput(com.sun.tools.ws.wsdl.document.BindingInput)

Aggregations

BindingFault (com.sun.tools.ws.wsdl.document.BindingFault)1 BindingInput (com.sun.tools.ws.wsdl.document.BindingInput)1 BindingOperation (com.sun.tools.ws.wsdl.document.BindingOperation)1 BindingOutput (com.sun.tools.ws.wsdl.document.BindingOutput)1 Iterator (java.util.Iterator)1 Element (org.w3c.dom.Element)1