< prev index next >

src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 30,39 **** --- 30,40 ---- import java.security.PrivilegedAction; import java.util.Iterator; import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; + import java.util.function.Supplier; /** * <p>Implements pluggable Datatypes.</p> * * <p>This class is duplicated for each JAXP subpackage so keep it in
*** 78,90 **** catch (SecurityException se) { debug = false; } } ! private static void dPrint(String msg) { if (debug) { ! System.err.println("JAXP: " + msg); } } /** * Attempt to load a class using the class loader supplied. If that fails --- 79,91 ---- catch (SecurityException se) { debug = false; } } ! private static void dPrint(Supplier<String> msgGen) { if (debug) { ! System.err.println("JAXP: " + msgGen.get()); } } /** * Attempt to load a class using the class loader supplied. If that fails
*** 188,201 **** Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); if (!type.isAssignableFrom(providerClass)) { throw new ClassCastException(className + " cannot be cast to " + type.getName()); } Object instance = providerClass.newInstance(); ! if (debug) { // Extra check to avoid computing cl strings ! dPrint("created new instance of " + providerClass + ! " using ClassLoader: " + cl); ! } return type.cast(instance); } catch (ClassNotFoundException x) { throw new DatatypeConfigurationException( "Provider " + className + " not found", x); --- 189,201 ---- Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); if (!type.isAssignableFrom(providerClass)) { throw new ClassCastException(className + " cannot be cast to " + type.getName()); } Object instance = providerClass.newInstance(); ! final ClassLoader clD = cl; ! dPrint(()->"created new instance of " + providerClass + ! " using ClassLoader: " + clD); return type.cast(instance); } catch (ClassNotFoundException x) { throw new DatatypeConfigurationException( "Provider " + className + " not found", x);
*** 221,237 **** */ static <T> T find(Class<T> type, String fallbackClassName) throws DatatypeConfigurationException { final String factoryId = type.getName(); ! dPrint("find factoryId =" + factoryId); // Use the system property first try { String systemProp = ss.getSystemProperty(factoryId); if (systemProp != null) { ! dPrint("found system property, value=" + systemProp); return newInstance(type, systemProp, null, true); } } catch (SecurityException se) { if (debug) se.printStackTrace(); --- 221,237 ---- */ static <T> T find(Class<T> type, String fallbackClassName) throws DatatypeConfigurationException { final String factoryId = type.getName(); ! dPrint(()->"find factoryId =" + factoryId); // Use the system property first try { String systemProp = ss.getSystemProperty(factoryId); if (systemProp != null) { ! dPrint(()->"found system property, value=" + systemProp); return newInstance(type, systemProp, null, true); } } catch (SecurityException se) { if (debug) se.printStackTrace();
*** 245,264 **** String configFile = ss.getSystemProperty("java.home") + File.separator + "conf" + File.separator + "jaxp.properties"; File f = new File(configFile); firstTime = false; if (ss.doesFileExist(f)) { ! dPrint("Read properties file "+f); cacheProps.load(ss.getFileInputStream(f)); } } } } final String factoryClassName = cacheProps.getProperty(factoryId); if (factoryClassName != null) { ! dPrint("found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); return newInstance(type, factoryClassName, null, true); } } catch (Exception ex) { if (debug) ex.printStackTrace(); --- 245,264 ---- String configFile = ss.getSystemProperty("java.home") + File.separator + "conf" + File.separator + "jaxp.properties"; File f = new File(configFile); firstTime = false; if (ss.doesFileExist(f)) { ! dPrint(()->"Read properties file "+f); cacheProps.load(ss.getFileInputStream(f)); } } } } final String factoryClassName = cacheProps.getProperty(factoryId); if (factoryClassName != null) { ! dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); return newInstance(type, factoryClassName, null, true); } } catch (Exception ex) { if (debug) ex.printStackTrace();
*** 272,282 **** if (fallbackClassName == null) { throw new DatatypeConfigurationException( "Provider for " + factoryId + " cannot be found"); } ! dPrint("loaded from fallback value: " + fallbackClassName); return newInstance(type, fallbackClassName, null, true); } /* * Try to find provider using the ServiceLoader API --- 272,282 ---- if (fallbackClassName == null) { throw new DatatypeConfigurationException( "Provider for " + factoryId + " cannot be found"); } ! dPrint(()->"loaded from fallback value: " + fallbackClassName); return newInstance(type, fallbackClassName, null, true); } /* * Try to find provider using the ServiceLoader API
< prev index next >