Search in sources :

Example 1 with Fault

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

the class W3CAddressingJavaGeneratorExtension method writeMethodAnnotations.

@Override
public void writeMethodAnnotations(TWSDLOperation two, JMethod jMethod) {
    JAnnotationUse actionAnn = null;
    if (!(two instanceof Operation))
        return;
    Operation o = ((Operation) two);
    // explicit input action
    if (o.getInput().getAction() != null && !o.getInput().getAction().equals("")) {
        // explicitly specified
        actionAnn = jMethod.annotate(Action.class);
        actionAnn.param("input", o.getInput().getAction());
    }
    // explicit output action
    if (o.getOutput() != null && o.getOutput().getAction() != null && !o.getOutput().getAction().equals("")) {
        // explicitly specified
        if (actionAnn == null)
            actionAnn = jMethod.annotate(Action.class);
        actionAnn.param("output", o.getOutput().getAction());
    }
    // explicit fault action
    if (o.getFaults() != null && o.getFaults().size() > 0) {
        Map<String, JClass> map = o.getFaults();
        JAnnotationArrayMember jam = null;
        for (Fault f : o.faults()) {
            if (f.getAction() == null)
                continue;
            if (f.getAction().equals(""))
                continue;
            if (actionAnn == null) {
                actionAnn = jMethod.annotate(Action.class);
            }
            if (jam == null) {
                jam = actionAnn.paramArray("fault");
            }
            final JAnnotationUse faAnn = jam.annotate(FaultAction.class);
            faAnn.param("className", map.get(f.getName()));
            faAnn.param("value", f.getAction());
        }
    }
}
Also used : Action(jakarta.xml.ws.Action) FaultAction(jakarta.xml.ws.FaultAction) JClass(com.sun.codemodel.JClass) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JAnnotationArrayMember(com.sun.codemodel.JAnnotationArrayMember) Fault(com.sun.tools.ws.wsdl.document.Fault) TWSDLOperation(com.sun.tools.ws.api.wsdl.TWSDLOperation) Operation(com.sun.tools.ws.wsdl.document.Operation)

Example 2 with Fault

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

the class WSDLParser method parsePortTypeOperation.

private Operation parsePortTypeOperation(TWSDLParserContextImpl context, Element e) {
    context.push();
    context.registerNamespaces(e);
    Operation operation = new Operation(forest.locatorTable.getStartLocation(e));
    String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
    operation.setName(name);
    String parameterOrderAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARAMETER_ORDER);
    operation.setParameterOrder(parameterOrderAttr);
    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(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e2.getLocalName()));
            }
            gotDocumentation = true;
            if (operation.getDocumentation() == null)
                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));
            }
            context.push();
            context.registerNamespaces(e2);
            Input input = new Input(forest.locatorTable.getStartLocation(e2), errReceiver);
            input.setParent(operation);
            String messageAttr = Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
            input.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
            String nameAttr = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
            input.setName(nameAttr);
            operation.setInput(input);
            gotInput = true;
            if (gotOutput) {
                inputBeforeOutput = false;
            }
            // check for extensiblity attributes
            for (Iterator iter2 = XmlUtil.getAllAttributes(e2); iter2.hasNext(); ) {
                Attr e3 = (Attr) iter2.next();
                if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || e3.getLocalName().equals(Constants.ATTR_NAME))
                    continue;
                // possible extensibility element -- must live outside the WSDL namespace
                checkNotWsdlAttribute(e3);
                handleExtension(context, input, e3, e2);
            }
            // 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 {
                    errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(), e3.getNamespaceURI()));
                }
            }
            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);
            Output output = new Output(forest.locatorTable.getStartLocation(e2), errReceiver);
            output.setParent(operation);
            String messageAttr = Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
            output.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
            String nameAttr = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
            output.setName(nameAttr);
            operation.setOutput(output);
            gotOutput = true;
            if (gotInput) {
                inputBeforeOutput = true;
            }
            // check for extensiblity attributes
            for (Iterator iter2 = XmlUtil.getAllAttributes(e2); iter2.hasNext(); ) {
                Attr e3 = (Attr) iter2.next();
                if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || e3.getLocalName().equals(Constants.ATTR_NAME))
                    continue;
                // possible extensibility element -- must live outside the WSDL namespace
                checkNotWsdlAttribute(e3);
                handleExtension(context, output, e3, e2);
            }
            // 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 {
                    errReceiver.error(forest.locatorTable.getStartLocation(e3), WsdlMessages.PARSING_INVALID_ELEMENT(e3.getTagName(), e3.getNamespaceURI()));
                }
            }
            context.pop();
        } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_FAULT)) {
            context.push();
            context.registerNamespaces(e2);
            Fault fault = new Fault(forest.locatorTable.getStartLocation(e2));
            fault.setParent(operation);
            String messageAttr = Util.getRequiredAttribute(e2, Constants.ATTR_MESSAGE);
            fault.setMessage(context.translateQualifiedName(context.getLocation(e2), messageAttr));
            String nameAttr = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
            fault.setName(nameAttr);
            operation.addFault(fault);
            gotFault = true;
            // check for extensiblity attributes
            for (Iterator iter2 = XmlUtil.getAllAttributes(e2); iter2.hasNext(); ) {
                Attr e3 = (Attr) iter2.next();
                if (e3.getLocalName().equals(Constants.ATTR_MESSAGE) || e3.getLocalName().equals(Constants.ATTR_NAME))
                    continue;
                // possible extensibility element -- must live outside the WSDL namespace
                checkNotWsdlAttribute(e3);
                handleExtension(context, fault, e3, e2);
            }
            // 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);
                    }
                }
            /*else {
                        Util.fail(
                            "parsing.invalidElement",
                            e3.getTagName(),
                            e3.getNamespaceURI());
                    }*/
            }
            context.pop();
        } else {
            // possible extensibility element -- must live outside the WSDL namespace
            checkNotWsdlElement(e2);
            if (!handleExtension(context, operation, e2)) {
                checkNotWsdlRequired(e2);
            }
        }
    /*else {
                Util.fail(
                    "parsing.invalidElement",
                    e2.getTagName(),
                    e2.getNamespaceURI());
            }*/
    }
    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 : Input(com.sun.tools.ws.wsdl.document.Input) BindingInput(com.sun.tools.ws.wsdl.document.BindingInput) Element(org.w3c.dom.Element) Output(com.sun.tools.ws.wsdl.document.Output) BindingOutput(com.sun.tools.ws.wsdl.document.BindingOutput) Iterator(java.util.Iterator) BindingFault(com.sun.tools.ws.wsdl.document.BindingFault) Fault(com.sun.tools.ws.wsdl.document.Fault) BindingOperation(com.sun.tools.ws.wsdl.document.BindingOperation) Operation(com.sun.tools.ws.wsdl.document.Operation) Attr(org.w3c.dom.Attr)

Aggregations

Fault (com.sun.tools.ws.wsdl.document.Fault)2 Operation (com.sun.tools.ws.wsdl.document.Operation)2 JAnnotationArrayMember (com.sun.codemodel.JAnnotationArrayMember)1 JAnnotationUse (com.sun.codemodel.JAnnotationUse)1 JClass (com.sun.codemodel.JClass)1 TWSDLOperation (com.sun.tools.ws.api.wsdl.TWSDLOperation)1 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 Input (com.sun.tools.ws.wsdl.document.Input)1 Output (com.sun.tools.ws.wsdl.document.Output)1 Action (jakarta.xml.ws.Action)1 FaultAction (jakarta.xml.ws.FaultAction)1 Iterator (java.util.Iterator)1 Attr (org.w3c.dom.Attr)1 Element (org.w3c.dom.Element)1