photopcf / magja

Automatically exported from code.google.com/p/magja
0 stars 0 forks source link

SoapCallFactory: create Array of Maps #26

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
SoapReturnParser is able to parse an Array of Maps, but SoapCallFactory is not 
able to create one.
We are using a custom Magento module which requires a parameter of type: Array 
of Maps.

Simply extend the method SoapCallFactory.typedElement(OMNamespace, String, 
Object):

        ...
        } else if (value instanceof String[]) {
        ...
        } else if (value instanceof Map[]) {
            Map<?, ?>[] mapArray = (Map<?, ?>[]) value;
            OMElement arrayArg = fac.createOMElement(name, elementNs);
            arrayArg.addAttribute("arrayType", soapXml.getPrefix() + ":Map[" + mapArray.length + "]", soapEnc);
            arrayArg.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi);
            for (Map<?, ?> item : mapArray) {
                arrayArg.addChild(typedElement(elementNs, "item", item));
            }
            return arrayArg;
        } else if (value instanceof Map[]) {
        ...

Original issue reported on code.google.com by reich...@googlemail.com on 14 Jan 2011 at 3:11

GoogleCodeExporter commented 8 years ago
the same for Boolean, Integer[] and Object[]:

        ...
        } else if (value instanceof Boolean) {
            return this.typedElement(elementNs, name, ((Boolean) value).toString(), xsd.getPrefix() + ":boolean");
        } else if (value instanceof Integer[]) {
            /*
             * Integer Array is represented by a list of items <item
             * SOAP-ENC:arrayType="xsd:int[length]"
             * xsi:type="SOAP-ENC:Array"> <item
             * xsi:type="xsd:int">123</item> <!-- more items if array
             * contains more entries --> </item>
             */
            Integer[] intArray = (Integer[]) value;
            OMElement arrayArg = fac.createOMElement(name, elementNs);
            arrayArg.addAttribute("arrayType", xsd.getPrefix() + ":int[" + intArray.length + "]", soapEnc);
            arrayArg.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi);
            for (Integer item : intArray) {
                arrayArg.addChild(typedElement(elementNs, "item", item));
            }
            return arrayArg;
        } else if (value instanceof Object[]) {
            Object[] objArray = (Object[]) value;
            OMElement arrayArg = fac.createOMElement(name, elementNs);
            arrayArg.addAttribute("arrayType", xsd.getPrefix() + ":ur-type[" + objArray.length + "]", soapEnc);
            arrayArg.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi);
            for (Object item : objArray) {
                arrayArg.addChild(typedElement(elementNs, "item", item));
            }
            return arrayArg;
        } else if...

Original comment by reich...@googlemail.com on 24 Jan 2011 at 9:44