Package de.tudan.otrsclient

Source Code of de.tudan.otrsclient.SoapArrayFactory

package de.tudan.otrsclient;

import org.w3c.dom.DOMException;

import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import java.util.Collection;

/**
* Utility to create SoapEncoded Arrays from Collections
*
* @author Gregor Tudan
*/
class SoapArrayFactory {

  <T> SOAPElement createSoapArray(String name, Collection<T> values)
      throws DOMException, SOAPException {
    SOAPElement element = SOAPFactory.newInstance().createElement(name);

    // Check the type of the array and default to string if empty
    String type;
    if (values.size() != 0) {
      type = XSDTypeConverter.simpleTypeForObject(values.iterator().next());
    } else {
      type = "xsi:string";
    }

    element.setAttribute("soapenc:arrayType", type + "[" + values.size() + "]");
    element.setAttribute("xsi:type", "soapenc:Array");

    for (T s : values) {
      element.addChildElement("item").addTextNode(s.toString()).setAttribute("xsi:type", type);
    }

    return element;
  }
}
TOP

Related Classes of de.tudan.otrsclient.SoapArrayFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.