XMLOutputSplitter { @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, String> inputMap) throws XMLSplitterExecutionException { Map<String, Object> result = new HashMap<String, Object>(); List<String> outputNameList = Arrays.asList(outputNames); String xml = inputMap.get(inputNames[0]); try { Document doc = new SAXBuilder().build(new StringReader(xml)); List<Element> children = doc.getRootElement().getChildren(); if (typeDescriptor instanceof ArrayTypeDescriptor) { if (outputNames.length > 1) throw new XMLSplitterExecutionException( "Unexpected, multiple output names for ArrayType"); executeForArrayType(result, children); } else { executeForComplexType(result, outputNameList, children, doc.getRootElement().getAttributes()); } for (int i = 0; i < outputNames.length; i++) { if (result.get(outputNames[i]) == null) { if (outputTypes[i].equals("'text/xml'")) { result .put(outputNames[i], "<" + outputNames[i] + " />"); } else if (outputTypes[i].startsWith("l('")) { result.put(outputNames[i], new ArrayList<Object>()); } else { result.put(outputNames[i], ""); } } } } catch (JDOMException e) { throw new XMLSplitterExecutionException("Unable to parse XML: " + xml, e); } catch (IOException e) { throw new XMLSplitterExecutionException("IOException parsing XML: " + xml, e); } return result; } XMLOutputSplitter(TypeDescriptor typeDescriptor,
			String[] outputNames, String[] outputTypes,String[] inputNames); @SuppressWarnings("unchecked") Map<String, Object> execute(Map<String, String> inputMap);  }
@Test public void testRPCComplexWithInternalList() throws Exception { WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("menagerie-complex-rpc.wsdl")); TypeDescriptor descriptor = parser.getOperationOutputParameters("getComplexWithInternalList").get(0); XMLOutputSplitter splitter = new XMLOutputSplitter(descriptor, new String [] {"length","innerArray","innerList"}, new String [] {"text/plain","l('text/plain')","l('text/plain')"}, new String[] {"input"}); String inputXML=getResourceAsString("getComplexWithInternalListResponse.xml"); Map<String,String> inputMap = new HashMap<String,String>(); inputMap.put("input", inputXML); Map<String,Object> outputMap = splitter.execute(inputMap); assertNotNull(outputMap.get("length")); assertNotNull(outputMap.get("innerList")); assertNotNull(outputMap.get("innerArray")); assertEquals("4",outputMap.get("length")); List<String> array = ( List<String> )outputMap.get("innerArray"); assertEquals(4,array.size()); assertEquals("String A",array.get(0)); assertEquals("String B",array.get(1)); assertEquals("String C",array.get(2)); assertEquals("String D",array.get(3)); array = ( List<String> )outputMap.get("innerList"); assertEquals(4,array.size()); assertEquals("String A",array.get(0)); assertEquals("String B",array.get(1)); assertEquals("String C",array.get(2)); assertEquals("String D",array.get(3)); }
@Test public void testWrappedArrayDefinedWithRestriction() throws Exception { WSDLParser parser = new WSDLParser(WSDLTestHelper.wsdlResourcePath("jws-online.wsdl")); TypeDescriptor descriptor = parser.getOperationOutputParameters("getSteadyStateTable").get(0); XMLOutputSplitter splitter = new XMLOutputSplitter(descriptor, new String [] {"model","fluxNames","fluxVals"}, new String [] {"text/plain","l('text/plain')","l('text/plain')"}, new String[] {"input"}); String inputXML=getResourceAsString("jws-splitter-input.xml"); Map<String,String> inputMap = new HashMap<String,String>(); inputMap.put("input", inputXML); Map<String,Object> outputMap = splitter.execute(inputMap); assertNotNull(outputMap.get("model")); assertNotNull(outputMap.get("fluxNames")); assertNotNull(outputMap.get("fluxVals")); assertEquals("teusink",outputMap.get("model")); List<String> array = ( List<String> )outputMap.get("fluxNames"); assertEquals(17,array.size()); assert(array.contains("v[G3PDH]")); array = ( List<String> )outputMap.get("fluxVals"); assertEquals(17,array.size()); assert(array.contains("88.15049285974906")); }