XMLInputSplitter { public Map<String, String> execute(Map<String, Object> inputMap) throws JDOMException, IOException { Map<String, String> result = new HashMap<String, String>(); Element outputElement = (this.typeDescriptor.getName().length() > 0 ? new Element( this.typeDescriptor.getName()) : new Element(this.typeDescriptor.getType())); if (typeDescriptor instanceof ComplexTypeDescriptor) { executeForComplexType(inputMap, result, outputElement); } else { for (String key : inputMap.keySet()) { Object dataObject = inputMap.get(key); if (dataObject instanceof List) { Element dataElement = buildElementFromObject(key, ""); for (Object dataItem : ((List<?>) dataObject)) { Element itemElement = buildElementFromObject(key, dataItem); dataElement.addContent(itemElement); } XMLOutputter outputter = new XMLOutputter(); String xmlText = outputter.outputString(dataElement); result.put(outputNames[0], xmlText); } else { Element dataElement = buildElementFromObject(key, dataObject); outputElement.addContent(dataElement); XMLOutputter outputter = new XMLOutputter(); String xmlText = outputter.outputString(outputElement); result.put(outputNames[0], xmlText); } } } return result; } XMLInputSplitter(TypeDescriptor typeDescriptor, String inputNames[],
			String inputTypes[], String[] outputNames); Map<String, String> execute(Map<String, Object> inputMap);  }
@Test public void testExecute() throws Exception { WSDLParser parser = new WSDLParser(wsdlResourcePath("eutils/eutils_lite.wsdl")); TypeDescriptor descriptor = parser.getOperationInputParameters("run_eInfo").get(0); XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"db","tool","email"},new String[]{"text/plain","text/plain","text/plain"},new String[]{"output"}); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("db", "pubmed"); inputMap.put("email", "bob.monkhouse@itv.com"); Map<String,String> outputMap = splitter.execute(inputMap); assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); String xml = outputMap.get("output"); assertTrue(xml.startsWith("<parameters xmlns=\"http: assertTrue(xml.contains("<db>pubmed</db>")); assertTrue(! xml.contains("<tool")); assertTrue(xml.contains("<email>bob.monkhouse@itv.com</email>")); }
@Test public void testOptional() throws Exception { WSDLParser parser = new WSDLParser(wsdlResourcePath("VSOi.wsdl")); TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0); XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"}); Map<String,Object> inputMap = new HashMap<String, Object>(); Map<String,String> outputMap = splitter.execute(inputMap); assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); String xml = outputMap.get("output"); assertTrue(xml.contains("<block xmlns=\"\"></block>")); assertTrue(! xml.contains("<version>")); }
@Test public void testNillable() throws Exception { WSDLParser parser = new WSDLParser(wsdlResourcePath("VSOi.wsdl")); TypeDescriptor descriptor = parser.getOperationInputParameters("Query").get(0); XMLInputSplitter splitter = new XMLInputSplitter(descriptor,new String[]{"version","block"},new String[]{"text/plain","text/plain"},new String[]{"output"}); Map<String,Object> inputMap = new HashMap<String, Object>(); inputMap.put("version", "xsi:nil"); Map<String,String> outputMap = splitter.execute(inputMap); assertNotNull("there should be an output named 'output'",outputMap.containsKey("output")); String xml = outputMap.get("output"); System.out.println(xml); assertTrue(xml.contains("<block xmlns=\"\"></block>")); assertTrue(xml.contains("<version xmlns=\"\" " + "xmlns:xsi=\"http: "xsi:nil=\"true\" />")); }