in axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java [78:129]
static List<Implementation> parseDescriptor(Loader loader, URL url) {
if (log.isDebugEnabled()) {
log.debug("Loading " + url);
}
List<Implementation> implementations = new ArrayList<Implementation>();
try {
// Since this code is used to discover Axiom implementations, we have to use DOM here.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
// Use URL#openStream() (instead of converting the URL to a String and passing it to the
// parser) to avoid situations where the parser can't reconstruct/interpret the URL.
InputStream in = url.openStream();
try {
Element root = dbf.newDocumentBuilder().parse(in).getDocumentElement();
QName rootQName = getQName(root);
if (rootQName.equals(QNAME_IMPLEMENTATIONS)) {
Node child = root.getFirstChild();
while (child != null) {
if (child instanceof Element) {
QName childQName = getQName(child);
if (childQName.equals(QNAME_IMPLEMENTATION)) {
Implementation implementation = parseImplementation(loader, (Element)child);
if (implementation != null) {
implementations.add(implementation);
}
} else {
log.warn("Skipping unexpected element " + childQName + "; only "
+ QNAME_IMPLEMENTATION + " is expected");
}
}
child = child.getNextSibling();
}
} else {
log.error(url + " is not a valid implementation descriptor: unexpected root element "
+ rootQName + "; expected " + QNAME_IMPLEMENTATIONS);
}
} finally {
in.close();
}
} catch (ParserConfigurationException ex) {
// If we get here, something went badly wrong
throw new Error(ex);
} catch (IOException ex) {
log.error("Unable to read " + url, ex);
} catch (SAXException ex) {
log.error("Parser error while reading " + url, ex);
}
if (log.isDebugEnabled()) {
log.debug("Discovered implementations: " + implementations);
}
return implementations;
}