/** * Write the specified WSDL definition to the specified Writer. * * @param wsdlDef the WSDL definition to be written. * @param sink the Writer to write the xml to. */ public void writeWSDL(Definition wsdlDef, Writer sink) throws WSDLException { String encoding = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // Unless a width is set, there will be only line breaks but no indentation. // The IBM JDK and the Sun JDK don't agree on the property name, // so we set them both. // transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); if (encoding != null) { transformer.setOutputProperty(OutputKeys.ENCODING, encoding); } Document document = ((DefinitionImpl) wsdlDef).getDocument(); if (document == null) { ((DefinitionImpl) wsdlDef).updateElement(true); document = ((DefinitionImpl) wsdlDef).getDocument(); } transformer.transform(new DOMSource(document), new StreamResult(sink)); } catch (TransformerException exception) { throw new WSDLException(WSDLException.OTHER_ERROR, "Failed to save Definitions.", exception); } }