private Document createDOMWrapper()

in bindings/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java [149:240]


    private Document createDOMWrapper(SoapMessage message) {
        Document document;
        BindingOperationInfo wsdlOperation = getOperation(message);
        BindingMessageInfo wsdlMessage = !isRequestor(message) ? wsdlOperation
                .getInput()
                : wsdlOperation.getOutput();

        document = DomUtil.createDocument();
        Element root = DomUtil.createElement(document,
                CxfJbiConstants.WSDL11_WRAPPER_MESSAGE);
        String typeNamespace = wsdlMessage.getMessageInfo().getName()
                .getNamespaceURI();
        if (typeNamespace == null || typeNamespace.length() == 0) {
            throw new IllegalArgumentException(
                    "messageType namespace is null or empty");
        }
        root.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
                        + CxfJbiConstants.WSDL11_WRAPPER_MESSAGE_PREFIX,
                        typeNamespace);
        
        setExtraPrefix(message, root);
        
        String typeLocalName = wsdlMessage.getMessageInfo().getName()
                .getLocalPart();
        if (typeLocalName == null || typeLocalName.length() == 0) {
            throw new IllegalArgumentException(
                    "messageType local name is null or empty");
        }
        root.setAttribute(CxfJbiConstants.WSDL11_WRAPPER_TYPE,
                CxfJbiConstants.WSDL11_WRAPPER_MESSAGE_PREFIX + ":"
                        + typeLocalName);
        String messageName = wsdlMessage.getMessageInfo().getName()
                .getLocalPart();
        root.setAttribute(CxfJbiConstants.WSDL11_WRAPPER_NAME, messageName);
        root.setAttribute(CxfJbiConstants.WSDL11_WRAPPER_VERSION, "1.0");

        SoapBindingInfo binding = (SoapBindingInfo) message.getExchange()
                .get(Endpoint.class).getEndpointInfo().getBinding();
        String style = binding.getStyle(wsdlOperation.getOperationInfo());
        if (style == null) {
            style = binding.getStyle();
        }

        Element body = getBodyElement(message);
        if (body == null) {
            return null;
        }

        if (body.getLocalName().equals("Fault")) {
            handleJBIFault(message, body);
            return null;
        }
        List<SoapHeaderInfo> headers = wsdlMessage
                .getExtensors(SoapHeaderInfo.class);
        List<Header> headerElement = message.getHeaders();
        List<Object> parts = new ArrayList<Object>();
        for (MessagePartInfo part : wsdlMessage.getMessageParts()) {
            if ("document".equals(style)) {
                parts.add(body);
            } else /* rpc-style */ {
                // SOAP:Body element is the operation name, children are
                // operation parameters

                Element param = DomUtil.getFirstChildElement(body);
                boolean found = false;
                while (param != null) {
                    if (part.getName().getLocalPart().equals(
                            param.getLocalName())) {
                        found = true;
                        parts.add(wrapNodeList(param.getChildNodes()));
                        break;
                    }
                    param = DomUtil.getNextSiblingElement(param);
                }
                if (!found) {
                    throw new Fault(new Exception("Missing part '"
                            + part.getName() + "'"));
                }
            }
        }
        processHeader(message, headers, headerElement, parts);
        for (Object part : parts) {
            if (part instanceof Node) {
                addPart(root, (Node) part);
            } else if (part instanceof NodeList) {
                addPart(root, (NodeList) part);
            } else if (part instanceof SoapHeader) {
                addPart(root, (Node) ((SoapHeader) part).getObject());
            }
        }
        return document;
    }