Search in sources :

Example 1 with WrapperElement

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.WrapperElement 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)

Aggregations

HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ToolContext (org.apache.cxf.tools.common.ToolContext)1 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)1 WrapperElement (org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.WrapperElement)1