/**
* Trims the sourceWSDL based on the excludedFields that are declared for the graphClass associated with the input WebService implementation class.
* The targetWSDL will be generated as a result.
* @param sourceWSDL a source WSDL.
* @param targetWSDLToGenerate the WSDL to generate.
* @param webServiceImplementationClassName the WebService implementation class that may have an annotation declaring the need for WSDL trimming.
*/
public static void trim(File sourceWSDL, File targetWSDLToGenerate, String webServiceImplementationClassName) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException, ClassNotFoundException {
Map<Class, Collection<String>> excludedFields = getExcludedFields(webServiceImplementationClassName);
if (excludedFields != null && excludedFields.size() > 0) {
if (log.isDebugEnabled())
log.debug("Trimming '" + sourceWSDL + "' by excluding " + excludedFields);
//Parse the source WSDL
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(sourceWSDL);
//Trim the source WSDL
trim(document.getDocumentElement(), excludedFields);
//Generate the target WSDL
if (log.isDebugEnabled())
log.debug("Generating: " + targetWSDLToGenerate);
Source source = new DOMSource(document);
Result result = new StreamResult(targetWSDLToGenerate);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
//transformerFactory.setAttribute("indent-number", 2);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(source, result);
} else if (!sourceWSDL.equals(targetWSDLToGenerate)) {
if (log.isDebugEnabled())
log.debug("None of the fields are excluded. '" + targetWSDLToGenerate + "' will be created as a copy of '" + sourceWSDL + '\'');
copy(sourceWSDL, targetWSDLToGenerate);
}
}
WSDLTrimmer.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:jaffa-framework
作者:
评论列表
文章目录