Search in sources :

Example 6 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class WrapperStyleNameCollisionValidator method mapElementName.

private String mapElementName(OperationInfo op, MessageInfo mi, WrapperElement element) {
    MessagePartInfo mpi = mi.getMessagePart(element.getElementName());
    JAXWSBinding bind = op.getExtensor(JAXWSBinding.class);
    if (bind != null && bind.getJaxwsParas() != null) {
        for (JAXWSParameter par : bind.getJaxwsParas()) {
            if (mi.getName().getLocalPart().equals(par.getMessageName()) && mpi.getName().getLocalPart().equals(par.getElementName().getLocalPart())) {
                return par.getName();
            }
        }
    }
    return mpi.getElementQName().getLocalPart();
}
Also used : JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 7 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class WrapperStyleNameCollisionValidator method isValidOperation.

private boolean isValidOperation(OperationInfo operation) {
    ToolContext context = service.getProperty(ToolContext.class.getName(), ToolContext.class);
    boolean c = context.optionSet(ToolConstants.CFG_AUTORESOLVE);
    boolean valid = false;
    if (operation.getUnwrappedOperation() == null) {
        valid = true;
    }
    String operationName = operation.getName().getLocalPart();
    operationName = ProcessorUtil.mangleNameToVariableName(operationName);
    JAXWSBinding binding = operation.getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    valid |= checkBare(context, operationName);
    if (valid) {
        return true;
    }
    MessagePartInfo input = null;
    MessagePartInfo output = null;
    if (operation.getInput() != null && operation.getInput().getMessagePartsNumber() == 1) {
        input = operation.getInput().getFirstMessagePart();
    }
    if (operation.getOutput() != null && operation.getOutput().getMessagePartsNumber() == 1) {
        output = operation.getOutput().getFirstMessagePart();
    }
    if (!c) {
        Map<String, QName> names = new HashMap<>();
        if (input != null) {
            for (WrapperElement element : ProcessorUtil.getWrappedElement(context, input.getElementQName())) {
                String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getInput(), element);
                if (names.containsKey(mappedName) && (names.get(mappedName) == element.getSchemaTypeName() || names.get(mappedName).equals(element.getSchemaTypeName()))) {
                    handleErrors(names.get(mappedName), element);
                    return false;
                }
                names.put(mappedName, element.getSchemaTypeName());
            }
        }
        if (output != null) {
            List<WrapperElement> els = ProcessorUtil.getWrappedElement(context, output.getElementQName());
            if (els.size() > 1) {
                for (WrapperElement element : els) {
                    String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getOutput(), element);
                    QName mn = names.get(mappedName);
                    if (names.containsKey(mappedName) && !(mn == element.getSchemaTypeName() || (mn != null && mn.equals(element.getSchemaTypeName())))) {
                        handleErrors(names.get(mappedName), element);
                        return false;
                    }
                    names.put(mappedName, element.getSchemaTypeName());
                }
            }
        }
    }
    return true;
}
Also used : WrapperElement(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.WrapperElement) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ToolContext(org.apache.cxf.tools.common.ToolContext) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 8 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class FaultProcessor method processFault.

private void processFault(JavaMethod method, FaultInfo faultMessage) throws ToolException {
    JavaModel model = method.getInterface().getJavaModel();
    String name = NameUtil.mangleNameToClassName(faultMessage.getName().getLocalPart());
    String namespace = faultMessage.getName().getNamespaceURI();
    String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
    if (namespace.equals(method.getInterface().getNamespace())) {
        packageName = method.getInterface().getPackageName();
    }
    JAXWSBinding jaxwsBinding = faultMessage.getExtensor(JAXWSBinding.class);
    if (jaxwsBinding != null) {
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        if (jaxwsBinding.getJaxwsClass() != null && jaxwsBinding.getJaxwsClass().getClassName() != null) {
            name = jaxwsBinding.getJaxwsClass().getClassName();
            if (name.contains(".")) {
                packageName = name.substring(0, name.lastIndexOf('.'));
                name = name.substring(name.lastIndexOf('.') + 1);
            }
        }
    }
    while (isNameCollision(packageName, name)) {
        name = name + "_Exception";
    }
    String fullClassName = packageName + "." + name;
    collector.addExceptionClassName(packageName, name, fullClassName);
    boolean samePackage = method.getInterface().getPackageName().equals(packageName);
    method.addException(new JavaException(faultMessage.getName().getLocalPart(), samePackage ? name : fullClassName, namespace));
    List<MessagePartInfo> faultParts = faultMessage.getMessageParts();
    JavaExceptionClass expClass = new JavaExceptionClass(model);
    expClass.setName(name);
    expClass.setNamespace(namespace);
    expClass.setPackageName(packageName);
    for (MessagePartInfo part : faultParts) {
        String fName = null;
        String fNamespace = null;
        if (part.getElementQName() != null) {
            fNamespace = part.getElementQName().getNamespaceURI();
            // fNamespace = part.getConcreteName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        } else {
            fNamespace = part.getTypeQName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        }
        if (StringUtils.isEmpty(fNamespace)) {
            fNamespace = namespace;
        }
        String fType = ProcessorUtil.getType(part, context, false);
        // REVISIT - custom JAXB package names
        String fPackageName = method.getInterface().getPackageName();
        JavaField fField = new JavaField(fName, fType, fNamespace);
        fField.setQName(ProcessorUtil.getElementName(part));
        if (!method.getInterface().getPackageName().equals(fPackageName)) {
            fField.setClassName(ProcessorUtil.getFullClzName(part, context, false));
        }
        if (!fType.equals(ProcessorUtil.resolvePartType(part))) {
            fField.setClassName(ProcessorUtil.getType(part, context, true));
        }
        expClass.addField(fField);
    }
    model.addExceptionClass(packageName + "." + name, expClass);
    expClass.setClassJavaDoc(faultMessage.getDocumentation());
}
Also used : JavaException(org.apache.cxf.tools.common.model.JavaException) JavaField(org.apache.cxf.tools.common.model.JavaField) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 9 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class ParameterProcessor method processOutput.

private void processOutput(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    Map<QName, MessagePartInfo> inputPartsMap = inputMessage.getMessagePartsMap();
    List<MessagePartInfo> outputParts = outputMessage == null ? new ArrayList<>() : outputMessage.getMessageParts();
    // figure out output parts that are not present in input parts
    List<MessagePartInfo> outParts = new ArrayList<>();
    int numHeader = 0;
    if (isRequestResponse(method)) {
        for (MessagePartInfo outpart : outputParts) {
            boolean oob = false;
            if (isOutOfBandHeader(outpart)) {
                if (!requireOutOfBandHeader()) {
                    continue;
                }
                oob = true;
            }
            MessagePartInfo inpart = inputPartsMap.get(outpart.getName());
            if (inpart == null) {
                outParts.add(outpart);
                if (oob) {
                    numHeader++;
                }
                continue;
            } else if (isSamePart(inpart, outpart)) {
                boolean found = false;
                for (JavaParameter p : method.getParameters()) {
                    if (p.getQName().equals(ProcessorUtil.getElementName(outpart)) && p.getPartName().equals(outpart.getName().getLocalPart())) {
                        p.setHolder(true);
                        p.setHolderName(javax.xml.ws.Holder.class.getName());
                        String holderClass = p.getClassName();
                        if (JAXBUtils.holderClass(holderClass) != null) {
                            holderClass = JAXBUtils.holderClass(holderClass).getName();
                        }
                        p.setClassName(holderClass);
                        p.getAnnotations().clear();
                        p.setStyle(JavaType.Style.INOUT);
                        p.annotate(new WebParamAnnotator(isOutOfBandHeader(outpart)));
                        found = true;
                    }
                }
                if (!found) {
                    addParameter(outpart, method, getParameterFromPart(method, outpart, JavaType.Style.INOUT));
                }
                continue;
            } else if (!isSamePart(inpart, outpart)) {
                if (oob) {
                    numHeader++;
                }
                outParts.add(outpart);
                continue;
            }
        }
    }
    if (isRequestResponse(method)) {
        if (outParts.size() - numHeader == 1 && !isHeader(outParts.get(0))) {
            processReturn(method, outParts.get(0));
            outParts.remove(0);
        } else {
            processReturn(method, null);
        }
        JAXWSBinding mBinding = outputMessage.getOperation().getExtensor(JAXWSBinding.class);
        for (MessagePartInfo part : outParts) {
            JavaParameter param = getParameterFromPart(method, part, JavaType.Style.OUT);
            if (mBinding != null && mBinding.getJaxwsParas() != null) {
                for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
                    if (part.getName().getLocalPart().equals(jwp.getPart())) {
                        param.setName(jwp.getName());
                    }
                }
            }
            addParameter(part, method, param);
        }
    } else {
        processReturn(method, null);
    }
}
Also used : QName(javax.xml.namespace.QName) JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) ArrayList(java.util.ArrayList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) WebParamAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebParamAnnotator) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)

Example 10 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class ServiceProcessor method processService.

private void processService(JavaModel model) throws ToolException {
    JavaServiceClass sclz = (JavaServiceClass) service.getProperty("JavaServiceClass");
    if (sclz != null) {
        return;
    }
    for (JavaServiceClass sc : model.getServiceClasses().values()) {
        if (sc.getServiceName().equals(service.getName().getLocalPart())) {
            sclz = sc;
        }
    }
    if (sclz == null) {
        sclz = new JavaServiceClass(model);
        service.setProperty("JavaServiceClass", sclz);
        String name = NameUtil.mangleNameToClassName(service.getName().getLocalPart());
        String namespace = service.getName().getNamespaceURI();
        String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
        // customizing
        JAXWSBinding serviceBinding = null;
        if (service.getDescription() != null) {
            serviceBinding = service.getDescription().getExtensor(JAXWSBinding.class);
        }
        JAXWSBinding serviceBinding2 = service.getExtensor(JAXWSBinding.class);
        // Handle service customized class
        if (serviceBinding != null) {
            if (serviceBinding.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding.getPackage());
            }
            if (serviceBinding.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            jaxwsBinding.setEnableWrapperStyle(serviceBinding.isEnableWrapperStyle());
            if (serviceBinding.getJaxwsClass() != null && serviceBinding.getJaxwsClass().getClassName() != null) {
                name = serviceBinding.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
                sclz.setClassJavaDoc(serviceBinding.getJaxwsClass().getComments());
            }
            sclz.setPackageJavaDoc(serviceBinding.getPackageJavaDoc());
        }
        if (serviceBinding2 != null) {
            if (serviceBinding2.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding2.getPackage());
            }
            if (serviceBinding2.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding2.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            if (serviceBinding2.isEnableWrapperStyle()) {
                jaxwsBinding.setEnableWrapperStyle(true);
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getClassName() != null) {
                name = serviceBinding2.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getComments() != null) {
                jaxwsBinding.setClassJavaDoc(serviceBinding2.getJaxwsClass().getComments());
            }
            if (!serviceBinding2.getPackageJavaDoc().equals("")) {
                sclz.setPackageJavaDoc(serviceBinding2.getPackageJavaDoc());
            }
        }
        sclz.setServiceName(service.getName().getLocalPart());
        sclz.setNamespace(namespace);
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        sclz.setPackageName(packageName);
        name = mapName(packageName, name);
        sclz.setName(name);
        ClassCollector collector = context.get(ClassCollector.class);
        String checkName = name;
        int count = 0;
        while (collector.containServiceClass(packageName, checkName)) {
            checkName = name + (++count);
        }
        name = checkName;
        sclz.setName(name);
        collector.addServiceClassName(packageName, name, packageName + "." + name);
        Element handler = (Element) context.get(ToolConstants.HANDLER_CHAIN);
        sclz.setHandlerChains(handler);
    }
    Collection<EndpointInfo> ports = service.getEndpoints();
    for (EndpointInfo port : ports) {
        JavaPort javaport = processPort(model, service, port);
        sclz.addPort(javaport);
    }
    sclz.setClassJavaDoc(jaxwsBinding.getClassJavaDoc());
    if (StringUtils.isEmpty(sclz.getClassJavaDoc())) {
        sclz.setClassJavaDoc(service.getDocumentation());
    }
    model.addServiceClass(sclz.getName(), sclz);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Aggregations

JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)14 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 ToolException (org.apache.cxf.tools.common.ToolException)5 QName (javax.xml.namespace.QName)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 Message (org.apache.cxf.common.i18n.Message)3 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)3 JAXWSParameter (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter)3 Definition (javax.wsdl.Definition)2 Operation (javax.wsdl.Operation)2 PortType (javax.wsdl.PortType)2 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)2 JavaPort (org.apache.cxf.tools.common.model.JavaPort)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 Test (org.junit.Test)2