Element root = null;
try {
URIResolver resolver = new URIResolver(bindingFile);
root = DOMUtils.readXml(resolver.getInputStream()).getDocumentElement();
} catch (Exception e1) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] {bindingFile});
throw new ToolException(msg, e1);
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(root);
StAXUtil.toStartTag(reader);
if (isValidJaxwsBindingFile(bindingFile, reader)) {
String wsdlLocation = root.getAttribute("wsdlLocation");
Element targetNode = null;
if (!StringUtils.isEmpty(wsdlLocation)) {
String wsdlURI = getAbsoluteURI(wsdlLocation, bindingFile);
targetNode = getTargetNode(wsdlURI);
String resolvedLoc = wsdlURI;
if (targetNode == null && env.get(ToolConstants.CFG_CATALOG) != null) {
resolvedLoc = resolveByCatalog(wsdlURI.toString());
targetNode = getTargetNode(resolvedLoc);
}
if (targetNode == null) {
Message msg = new Message("POINT_TO_WSDL_DOES_NOT_EXIST",
LOG, new Object[] {bindingFile, resolvedLoc});
throw new ToolException(msg);
}
root.setAttribute("wsdlLocation", wsdlURI);
} else {
targetNode = wsdlNode;
root.setAttribute("wsdlLocation", wsdlURL);
}
jaxwsBindingsMap.put(root, targetNode);
} else if (isValidJaxbBindingFile(reader)) {
String schemaLocation = root.getAttribute("schemaLocation");
boolean hasJaxbBindingChild = false;
NodeList nlist = root.getElementsByTagNameNS(ToolConstants.JAXB_BINDINGS.getNamespaceURI(),
ToolConstants.JAXB_BINDINGS.getLocalPart());
for (int i = 0; i < nlist.getLength(); i++) {
Node node = nlist.item(i);
if (node instanceof Element) {
hasJaxbBindingChild = true;
break;
}
}
if (StringUtils.isEmpty(schemaLocation) && !hasJaxbBindingChild) {
InputSource tmpIns = null;
try {
tmpIns = convertToTmpInputSource(root, wsdlURL);
} catch (Exception e1) {
Message msg = new Message("FAILED_TO_ADD_SCHEMALOCATION", LOG, bindingFile);
throw new ToolException(msg, e1);
}
jaxbBindings.add(tmpIns);
} else {
jaxbBindings.add(new InputSource(bindingFile));
}
} else {
Message msg = new Message("UNKNOWN_BINDING_FILE", LOG, bindingFile, reader.getName());
throw new ToolException(msg);
}
}