final String systemProp; if (type.getName().equals(factoryId)) { systemProp = getSystemProperty(factoryId); } else { systemProp = System.getProperty(factoryId); dPrint(()->"found system property, value=" + systemProp); return newInstance(type, systemProp, cl, true); if (firstTime) { firstTime = false; String javaHome = getSystemProperty("java.home"); String configFile; configFile = javaHome + File.separator + "conf" + File.separator + "jaxp.properties"; File jaxp = new File(configFile); if (doesFileExist(jaxp)) { cacheProps.load(getFileInputStream(jaxp)); if (doesFileExist(stax)) { cacheProps.load(getFileInputStream(stax)); return newInstance(type, factoryClassName, cl, true); final T provider = findServiceProvider(type, cl); if (provider != null) { return provider; dPrint(()->"loaded from fallback value: " + fallbackClassName); return newInstance(type, fallbackClassName, cl, true);
static private Class getProviderClass(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException { try { if (cl == null) { if (useBSClsLoader) { return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); } else { cl = getContextClassLoader(); if (cl == null) { throw new ClassNotFoundException(); } else { return Class.forName(className, false, cl); } } } else { return Class.forName(className, false, cl); } } catch (ClassNotFoundException e1) { if (doFallback) { return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); } else { throw e1; } } }
static <T> T newInstance(Class<T> type, String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws FactoryConfigurationError { assert type != null; if (System.getSecurityManager() != null) { if (className != null && className.startsWith(DEFAULT_PACKAGE)) { cl = null; useBSClsLoader = true; } } try { Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); if (!type.isAssignableFrom(providerClass)) { throw new ClassCastException(className + " cannot be cast to " + type.getName()); } Object instance = providerClass.getConstructor().newInstance(); final ClassLoader clD = cl; dPrint(()->"created new instance of " + providerClass + " using ClassLoader: " + clD); return type.cast(instance); } catch (ClassNotFoundException x) { throw new FactoryConfigurationError(x, "Provider " + className + " not found"); } catch (Exception x) { throw new FactoryConfigurationError(x, "Provider " + className + " could not be instantiated: " + x); } }
static <T> T newInstance(Class<T> type, String className, ClassLoader cl, boolean doFallback) throws FactoryConfigurationError { return newInstance(type, className, cl, doFallback, false); }
public static SAXParserFactory newInstance(String factoryClassName, ClassLoader classLoader) { return $FactoryFinder.newInstance(SAXParserFactory.class, factoryClassName, classLoader, false); }
public static SAXParserFactory newInstance() { return $FactoryFinder.find(SAXParserFactory.class, DEFAULT_IMPL); }
public static DocumentBuilderFactory newInstance() { return $FactoryFinder.find(DocumentBuilderFactory.class, DEFAULT_IMPL); }
public static SAXParserFactory newDefaultInstance() { return $FactoryFinder.newInstance(SAXParserFactory.class, DEFAULT_IMPL, null, false, true); }
public static DocumentBuilderFactory newDefaultInstance() { return $FactoryFinder.newInstance(DocumentBuilderFactory.class, DEFAULT_IMPL, null, false, true); }
public static DocumentBuilderFactory newInstance(String factoryClassName, ClassLoader classLoader) { return $FactoryFinder.newInstance(DocumentBuilderFactory.class, factoryClassName, classLoader, false); }