/**
* @return XMLOutputFactory for the current classloader
*/
private static XMLOutputFactory getXMLOutputFactory_perClassLoader(StAXWriterConfiguration configuration) {
ClassLoader cl = getContextClassLoader();
XMLOutputFactory factory;
if (cl == null) {
factory = getXMLOutputFactory_singleton(configuration);
} else {
if (configuration == null) {
configuration = StAXWriterConfiguration.DEFAULT;
}
Map map = (Map)outputFactoryPerCLMap.get(configuration);
if (map == null) {
map = Collections.synchronizedMap(new WeakHashMap());
outputFactoryPerCLMap.put(configuration, map);
factory = null;
} else {
factory = (XMLOutputFactory)map.get(cl);
}
if (factory == null) {
if (log.isDebugEnabled()) {
log.debug("About to create XMLOutputFactory implementation with " +
"classloader=" + cl);
log.debug("The classloader for javax.xml.stream.XMLOutputFactory is: " +
XMLOutputFactory.class.getClassLoader());
}
try {
factory = newXMLOutputFactory(null, configuration);
} catch (ClassCastException cce) {
if (log.isDebugEnabled()) {
log.debug("Failed creation of XMLOutputFactory implementation with " +
"classloader=" + cl);
log.debug("Exception is=" + cce);
log.debug("Attempting with classloader: " +
XMLOutputFactory.class.getClassLoader());
}
factory = newXMLOutputFactory(XMLOutputFactory.class.getClassLoader(),
configuration);
}
if (factory != null) {
map.put(cl, factory);
if (log.isDebugEnabled()) {
log.debug("Created XMLOutputFactory = " + factory.getClass()
+ " for classloader=" + cl);
log.debug("Configuration = " + configuration);
log.debug("Size of XMLOutFactory map for this configuration = " + map.size());
log.debug("Configurations for which factories have been cached = " +
outputFactoryPerCLMap.keySet());