src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 48412 d4412e380f6b
equal deleted inserted replaced
47311:ff631a3cadbc 47312:d4f959806fe9
    33 import java.util.Iterator;
    33 import java.util.Iterator;
    34 import java.util.Properties;
    34 import java.util.Properties;
    35 import java.util.ServiceConfigurationError;
    35 import java.util.ServiceConfigurationError;
    36 import java.util.ServiceLoader;
    36 import java.util.ServiceLoader;
    37 import java.util.function.Supplier;
    37 import java.util.function.Supplier;
       
    38 import jdk.xml.internal.SecuritySupport;
    38 
    39 
    39 /**
    40 /**
    40  * <p>Implements pluggable Datatypes.</p>
    41  * <p>Implements pluggable Datatypes.</p>
    41  *
    42  *
    42  * <p>This class is duplicated for each JAXP subpackage so keep it in
    43  * <p>This class is duplicated for each JAXP subpackage so keep it in
    62      * Flag indicating if properties from java.home/conf/jaxp.properties
    63      * Flag indicating if properties from java.home/conf/jaxp.properties
    63      * have been cached.
    64      * have been cached.
    64      */
    65      */
    65     static volatile boolean firstTime = true;
    66     static volatile boolean firstTime = true;
    66 
    67 
    67     /**
       
    68      * Security support class use to check access control before
       
    69      * getting certain system resources.
       
    70      */
       
    71     private final static SecuritySupport ss = new SecuritySupport();
       
    72 
       
    73     // Define system property "jaxp.debug" to get output
    68     // Define system property "jaxp.debug" to get output
    74     static {
    69     static {
    75         // Use try/catch block to support applets, which throws
    70         // Use try/catch block to support applets, which throws
    76         // SecurityException out of this code.
    71         // SecurityException out of this code.
    77         try {
    72         try {
    78             String val = ss.getSystemProperty("jaxp.debug");
    73             String val = SecuritySupport.getSystemProperty("jaxp.debug");
    79             // Allow simply setting the prop to turn on debug
    74             // Allow simply setting the prop to turn on debug
    80             debug = val != null && !"false".equals(val);
    75             debug = val != null && !"false".equals(val);
    81         }
    76         }
    82         catch (SecurityException se) {
    77         catch (SecurityException se) {
    83             debug = false;
    78             debug = false;
   107         try {
   102         try {
   108             if (cl == null) {
   103             if (cl == null) {
   109                 if (useBSClsLoader) {
   104                 if (useBSClsLoader) {
   110                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   105                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   111                 } else {
   106                 } else {
   112                     cl = ss.getContextClassLoader();
   107                     cl = SecuritySupport.getContextClassLoader();
   113                     if (cl == null) {
   108                     if (cl == null) {
   114                         throw new ClassNotFoundException();
   109                         throw new ClassNotFoundException();
   115                     }
   110                     }
   116                     else {
   111                     else {
   117                         return Class.forName(className, false, cl);
   112                         return Class.forName(className, false, cl);
   256         final String factoryId = type.getName();
   251         final String factoryId = type.getName();
   257 
   252 
   258         dPrint(()->"find factoryId =" + factoryId);
   253         dPrint(()->"find factoryId =" + factoryId);
   259         // Use the system property first
   254         // Use the system property first
   260         try {
   255         try {
   261             String systemProp = ss.getSystemProperty(factoryId);
   256             String systemProp = SecuritySupport.getSystemProperty(factoryId);
   262             if (systemProp != null) {
   257             if (systemProp != null) {
   263                 dPrint(()->"found system property, value=" + systemProp);
   258                 dPrint(()->"found system property, value=" + systemProp);
   264                 return newInstance(type, systemProp, null, true, true);
   259                 return newInstance(type, systemProp, null, true, true);
   265             }
   260             }
   266         }
   261         }
   271         // try to read from $java.home/conf/jaxp.properties
   266         // try to read from $java.home/conf/jaxp.properties
   272         try {
   267         try {
   273             if (firstTime) {
   268             if (firstTime) {
   274                 synchronized (cacheProps) {
   269                 synchronized (cacheProps) {
   275                     if (firstTime) {
   270                     if (firstTime) {
   276                         String configFile = ss.getSystemProperty("java.home") + File.separator +
   271                         String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator +
   277                             "conf" + File.separator + "jaxp.properties";
   272                             "conf" + File.separator + "jaxp.properties";
   278                         File f = new File(configFile);
   273                         File f = new File(configFile);
   279                         firstTime = false;
   274                         firstTime = false;
   280                         if (ss.doesFileExist(f)) {
   275                         if (SecuritySupport.doesFileExist(f)) {
   281                             dPrint(()->"Read properties file "+f);
   276                             dPrint(()->"Read properties file "+f);
   282                             cacheProps.load(ss.getFileInputStream(f));
   277                             cacheProps.load(SecuritySupport.getFileInputStream(f));
   283                         }
   278                         }
   284                     }
   279                     }
   285                 }
   280                 }
   286             }
   281             }
   287             final String factoryClassName = cacheProps.getProperty(factoryId);
   282             final String factoryClassName = cacheProps.getProperty(factoryId);