* @return XMLInputFactory for the current classloader
*/
private static XMLInputFactory getXMLInputFactory_perClassLoader(StAXParserConfiguration configuration) {
ClassLoader cl = getContextClassLoader();
XMLInputFactory factory;
if (cl == null) {
factory = getXMLInputFactory_singleton(configuration);
} else {
// Check the cache
if (configuration == null) {
configuration = StAXParserConfiguration.DEFAULT;
}
Map map = (Map)inputFactoryPerCLMap.get(configuration);
if (map == null) {
map = Collections.synchronizedMap(new WeakHashMap());
inputFactoryPerCLMap.put(configuration, map);
factory = null;
} else {
factory = (XMLInputFactory)map.get(cl);
}
// If not found in the cache map, crate a new factory
if (factory == null) {
if (log.isDebugEnabled()) {
log.debug("About to create XMLInputFactory implementation with " +
"classloader=" + cl);
log.debug("The classloader for javax.xml.stream.XMLInputFactory is: "
+ XMLInputFactory.class.getClassLoader());
}
try {
factory = newXMLInputFactory(null, configuration);
} catch (ClassCastException cce) {
if (log.isDebugEnabled()) {
log.debug("Failed creation of XMLInputFactory implementation with " +
"classloader=" + cl);
log.debug("Exception is=" + cce);
log.debug("Attempting with classloader: " +
XMLInputFactory.class.getClassLoader());
}
factory = newXMLInputFactory(XMLInputFactory.class.getClassLoader(),
configuration);
}
if (factory != null) {
// Cache the new factory
map.put(cl, factory);
if (log.isDebugEnabled()) {
log.debug("Created XMLInputFactory = " + factory.getClass() +
" with classloader=" + cl);
log.debug("Configuration = " + configuration);
log.debug("Size of XMLInputFactory map for this configuration = " + map.size());
log.debug("Configurations for which factories have been cached = " +
inputFactoryPerCLMap.keySet());