*** javax/xml/stream/FactoryFinder.java.orig 2010-05-07 12:43:00.000000000 +0530 --- javax/xml/stream/FactoryFinder.java 2010-05-07 12:41:45.000000000 +0530 *************** *** 33,38 **** --- 33,41 ---- import java.io.FileInputStream; import java.util.Properties; + import java.util.ServiceLoader; + import java.util.Iterator; + import java.util.ServiceConfigurationError; import java.io.BufferedReader; import java.io.InputStreamReader; *************** *** 251,314 **** private static Object findJarServiceProvider(String factoryId) throws ConfigurationError { ! String serviceId = "META-INF/services/" + factoryId; ! InputStream is = null; ! // First try the Context ClassLoader ClassLoader cl = ss.getContextClassLoader(); if (cl != null) { ! is = ss.getResourceAsStream(cl, serviceId); ! ! // If no provider found then try the current ClassLoader ! if (is == null) { ! cl = FactoryFinder.class.getClassLoader(); ! is = ss.getResourceAsStream(cl, serviceId); } - } else { - // No Context ClassLoader, try the current ClassLoader - cl = FactoryFinder.class.getClassLoader(); - is = ss.getResourceAsStream(cl, serviceId); } ! ! if (is == null) { ! // No provider found ! return null; ! } ! ! if (debug) { // Extra check to avoid computing cl strings ! dPrint("found jar resource=" + serviceId + " using ClassLoader: " + cl); ! } ! ! BufferedReader rd; ! try { ! rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); ! } ! catch (java.io.UnsupportedEncodingException e) { ! rd = new BufferedReader(new InputStreamReader(is)); ! } ! ! String factoryClassName = null; ! try { ! // XXX Does not handle all possible input as specified by the ! // Jar Service Provider specification ! factoryClassName = rd.readLine(); ! rd.close(); ! } catch (IOException x) { ! // No provider found ! return null; ! } ! ! if (factoryClassName != null && !"".equals(factoryClassName)) { ! dPrint("found in resource, value=" + factoryClassName); ! ! // Note: here we do not want to fall back to the current ! // ClassLoader because we want to avoid the case where the ! // resource file was found using one ClassLoader and the ! // provider class was instantiated using a different one. ! return newInstance(factoryClassName, cl, false); } ! ! // No provider found return null; } --- 254,295 ---- private static Object findJarServiceProvider(String factoryId) throws ConfigurationError { ! final Class serviceClass; ! try { ! serviceClass = Class.forName(factoryId); ! } catch (ClassNotFoundException e) { ! throw new ConfigurationError("Not able to load " + factoryId, e); ! } // First try the Context ClassLoader ClassLoader cl = ss.getContextClassLoader(); if (cl != null) { ! ServiceLoader loader = ServiceLoader.load(serviceClass, cl); ! final Iterator providers = loader.iterator(); ! while (providers.hasNext()) { ! try { ! return providers.next(); ! } catch (ServiceConfigurationError e) { ! // This can happen because of class loader mismatch or any other reason. ! // log and continue to next one ! if (debug) { ! dPrint("This provider is not suitable because of: " + e + ". Will try next one."); ! } ! } } } ! // If no provider found then try the current ClassLoader ! ServiceLoader loader = ServiceLoader.load(serviceClass, FactoryFinder.class.getClassLoader()); ! final Iterator providers = loader.iterator(); ! while (providers.hasNext()) { ! try { ! return providers.next(); ! } catch (Exception e) { ! // This can happen because of class loader mismatch or any other reason. ! // log and continue to next one ! e.printStackTrace(); ! } } ! return null; } *************** *** 330,333 **** } } - --- 311,313 ----