src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 48412 d4412e380f6b
equal deleted inserted replaced
47311:ff631a3cadbc 47312:d4f959806fe9
    31 import java.util.Iterator;
    31 import java.util.Iterator;
    32 import java.util.Properties;
    32 import java.util.Properties;
    33 import java.util.ServiceConfigurationError;
    33 import java.util.ServiceConfigurationError;
    34 import java.util.ServiceLoader;
    34 import java.util.ServiceLoader;
    35 import java.util.function.Supplier;
    35 import java.util.function.Supplier;
       
    36 import jdk.xml.internal.SecuritySupport;
    36 
    37 
    37 /**
    38 /**
    38  * <p>Implements pluggable Datatypes.</p>
    39  * <p>Implements pluggable Datatypes.</p>
    39  *
    40  *
    40  * <p>This class is duplicated for each JAXP subpackage so keep it in
    41  * <p>This class is duplicated for each JAXP subpackage so keep it in
    59      * Flag indicating if properties from java.home/conf/jaxp.properties
    60      * Flag indicating if properties from java.home/conf/jaxp.properties
    60      * have been cached.
    61      * have been cached.
    61      */
    62      */
    62     private static volatile boolean firstTime = true;
    63     private static volatile boolean firstTime = true;
    63 
    64 
    64     /**
       
    65      * Security support class use to check access control before
       
    66      * getting certain system resources.
       
    67      */
       
    68     private final static SecuritySupport ss = new SecuritySupport();
       
    69 
       
    70     // Define system property "jaxp.debug" to get output
    65     // Define system property "jaxp.debug" to get output
    71     static {
    66     static {
    72         // Use try/catch block to support applets, which throws
    67         // Use try/catch block to support applets, which throws
    73         // SecurityException out of this code.
    68         // SecurityException out of this code.
    74         try {
    69         try {
    75             String val = ss.getSystemProperty("jaxp.debug");
    70             String val = SecuritySupport.getSystemProperty("jaxp.debug");
    76             // Allow simply setting the prop to turn on debug
    71             // Allow simply setting the prop to turn on debug
    77             debug = val != null && !"false".equals(val);
    72             debug = val != null && !"false".equals(val);
    78         }
    73         }
    79         catch (SecurityException se) {
    74         catch (SecurityException se) {
    80             debug = false;
    75             debug = false;
   104         try {
    99         try {
   105             if (cl == null) {
   100             if (cl == null) {
   106                 if (useBSClsLoader) {
   101                 if (useBSClsLoader) {
   107                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   102                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   108                 } else {
   103                 } else {
   109                     cl = ss.getContextClassLoader();
   104                     cl = SecuritySupport.getContextClassLoader();
   110                     if (cl == null) {
   105                     if (cl == null) {
   111                         throw new ClassNotFoundException();
   106                         throw new ClassNotFoundException();
   112                     }
   107                     }
   113                     else {
   108                     else {
   114                         return Class.forName(className, false, cl);
   109                         return Class.forName(className, false, cl);
   225         final String factoryId = type.getName();
   220         final String factoryId = type.getName();
   226         dPrint(()->"find factoryId =" + factoryId);
   221         dPrint(()->"find factoryId =" + factoryId);
   227 
   222 
   228         // Use the system property first
   223         // Use the system property first
   229         try {
   224         try {
   230             String systemProp = ss.getSystemProperty(factoryId);
   225             String systemProp = SecuritySupport.getSystemProperty(factoryId);
   231             if (systemProp != null) {
   226             if (systemProp != null) {
   232                 dPrint(()->"found system property, value=" + systemProp);
   227                 dPrint(()->"found system property, value=" + systemProp);
   233                 return newInstance(type, systemProp, null, true);
   228                 return newInstance(type, systemProp, null, true);
   234             }
   229             }
   235         }
   230         }
   240         // try to read from $java.home/conf/jaxp.properties
   235         // try to read from $java.home/conf/jaxp.properties
   241         try {
   236         try {
   242             if (firstTime) {
   237             if (firstTime) {
   243                 synchronized (cacheProps) {
   238                 synchronized (cacheProps) {
   244                     if (firstTime) {
   239                     if (firstTime) {
   245                         String configFile = ss.getSystemProperty("java.home") + File.separator +
   240                         String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator +
   246                             "conf" + File.separator + "jaxp.properties";
   241                             "conf" + File.separator + "jaxp.properties";
   247                         File f = new File(configFile);
   242                         File f = new File(configFile);
   248                         firstTime = false;
   243                         firstTime = false;
   249                         if (ss.doesFileExist(f)) {
   244                         if (SecuritySupport.doesFileExist(f)) {
   250                             dPrint(()->"Read properties file "+f);
   245                             dPrint(()->"Read properties file "+f);
   251                             cacheProps.load(ss.getFileInputStream(f));
   246                             cacheProps.load(SecuritySupport.getFileInputStream(f));
   252                         }
   247                         }
   253                     }
   248                     }
   254                 }
   249                 }
   255             }
   250             }
   256             final String factoryClassName = cacheProps.getProperty(factoryId);
   251             final String factoryClassName = cacheProps.getProperty(factoryId);