Example usage for org.dom4j Element addNamespace

List of usage examples for org.dom4j Element addNamespace

Introduction

In this page you can find the example usage for org.dom4j Element addNamespace.

Prototype

Element addNamespace(String prefix, String uri);

Source Link

Document

Adds a namespace to this element for use by its child content

Usage

From source file:zutil.net.ws.soap.SOAPHttpPage.java

License:Open Source License

/**
 * Takes an XML Element and invokes all the it's child elements as methods.
 * // w  w w  .  ja  v  a2  s  . co m
 * @param       obj            is the object that the methods will be called from
 * @param       requestRoot    is the Element where the children lies
 * @param       responseRoot   is the root element of the response
 */
@SuppressWarnings("unchecked")
private void prepareInvoke(WSInterface obj, Element requestRoot, Element responseRoot) throws Throwable {
    Iterator<Element> it = requestRoot.elementIterator();
    while (it.hasNext()) {
        Element e = it.next();
        if (wsDef.hasMethod(e.getQName().getName())) {
            WSMethodDef m = wsDef.getMethod(e.getQName().getName());
            Object[] params = new Object[m.getInputCount()];

            // Get the parameter values
            for (int i = 0; i < m.getInputCount(); i++) {
                WSParameterDef param = m.getInput(i);
                if (e.element(param.getName()) != null) {
                    params[i] = Converter.fromString(e.element(param.getName()).getTextTrim(),
                            param.getParamClass());
                }
            }

            // Invoke
            Object ret = m.invoke(obj, params);

            // generate response XML
            if (m.getOutputCount() > 0) {
                Element response = responseRoot.addElement("");
                response.addNamespace("m", m.getNamespace());
                response.setName("m:" + m.getName() + "Response");

                if (ret instanceof WSReturnObject) {
                    Field[] f = ret.getClass().getFields();
                    for (int i = 0; i < m.getOutputCount(); i++) {
                        WSParameterDef param = m.getOutput(i);
                        generateSOAPXMLForObj(response, ((WSReturnObject) ret).getValue(f[i]), param.getName());
                    }
                } else {
                    generateSOAPXMLForObj(response, ret, m.getOutput(0).getName());
                }
            }
        } else {
            throw new NoSuchMethodException("Unable to find method: " + e.getQName().getName() + "!");
        }
    }
}

From source file:zutil.parser.wsdl.WSDLWriter.java

License:Open Source License

private Document generateDefinition() {
    Document wsdl = DocumentHelper.createDocument();
    Element definitions = wsdl.addElement("wsdl:definitions");
    definitions.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    definitions.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    definitions.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
    definitions.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
    definitions.addNamespace("soap-enc", "http://schemas.xmlsoap.org/soap/encoding/");
    definitions.addNamespace("tns", ws.getNamespace() + "?type");
    definitions.addAttribute("targetNamespace", ws.getNamespace());

    generateType(definitions);/* w ww  . j  a  v  a  2  s  .co  m*/
    generateMessages(definitions);
    generatePortType(definitions);
    generateBinding(definitions);
    generateService(definitions);

    return wsdl;
}