*/
public class WSDLCleaner {
public static void cleanWSDL(WsdlDefinitions definition){
WsdlDefinitions wsdl = definition;
Iterable<WsdlBinding> bindings = wsdl.bindings();
ArrayList<WsdlBinding> removedBindings = new ArrayList<WsdlBinding>();
for (WsdlBinding wsdlBinding : bindings) {
XmlElement innerBinding = wsdlBinding.xml().element("binding");
if( null != innerBinding &&
!"http://schemas.xmlsoap.org/wsdl/soap/".equals(innerBinding.getNamespace().getName())){
removedBindings .add(wsdlBinding);
}
}
//to mitigate the Concurrent modifications this is done separately
for (WsdlBinding wsdlBinding : removedBindings) {
wsdl.xml().removeElement(wsdlBinding.xml());
}
ArrayList<WsdlPort> removePorts = new ArrayList<WsdlPort>();
Iterable<WsdlService> services = wsdl.services();
for (WsdlService wsdlService : services) {
Iterable<WsdlPort> ports = wsdlService.ports();
for (WsdlPort wsdlPort : ports) {
for (WsdlBinding removedBinding : removedBindings) {
if(removedBinding.getName().equals(wsdlPort.getBinding().getLocalPart())){
removePorts.add(wsdlPort);
break;
}
}
}
for (WsdlPort wsdlPort : removePorts) {
wsdlService.xml().removeElement(wsdlPort.xml());
}
removePorts.clear();
}
//remove attributeFormDefault and elementFormDefault
Iterable<XmlElement> schemas = wsdl.getTypes().elements(null, "schema");
for (XmlElement schema : schemas) {
XmlAttribute attributeFormDefault = schema.attribute("attributeFormDefault");
schema.removeAttribute(attributeFormDefault);
XmlAttribute elementFormDefault = schema.attribute("elementFormDefault");