/** * Finds the name of the required implementation class in the specified order. The specified order * is the following: * * <ol> * <li>query the system property using <code>System.getProperty</code> * <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file * <li>read <code>META-INF/services/<i>factoryId</i></code> file * <li>use fallback classname * </ol> * * @return name of class that provides factory service, never null * @param factoryId Name of the factory to find, same as a property name * @param propertiesFilename The filename in the $java.home/lib directory of the properties file. * If none specified, ${java.home}/lib/xalan.properties will be used. * @param fallbackClassName Implementation class name, if nothing else is found. Use null to mean * no fallback. * @exception ObjectFactory.ConfigurationError */ static String lookUpFactoryClassName( String factoryId, String propertiesFilename, String fallbackClassName) { SecuritySupport ss = SecuritySupport.getInstance(); // Use the system property first try { String systemProp = ss.getSystemProperty(factoryId); if (systemProp != null) { if (DEBUG) debugPrintln("found system property, value=" + systemProp); return systemProp; } } catch (SecurityException se) { // Ignore and continue w/ next location } // Try to read from propertiesFilename, or // $java.home/lib/xalan.properties String factoryClassName = null; // no properties file name specified; use // $JAVA_HOME/lib/xalan.properties: if (propertiesFilename == null) { File propertiesFile = null; boolean propertiesFileExists = false; try { String javah = ss.getSystemProperty("java.home"); propertiesFilename = javah + File.separator + "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME; propertiesFile = new File(propertiesFilename); propertiesFileExists = ss.getFileExists(propertiesFile); } catch (SecurityException e) { // try again... fLastModified = -1; fXalanProperties = null; } synchronized (ObjectFactory.class) { boolean loadProperties = false; FileInputStream fis = null; try { // file existed last time if (fLastModified >= 0) { if (propertiesFileExists && (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) { loadProperties = true; } else { // file has stopped existing... if (!propertiesFileExists) { fLastModified = -1; fXalanProperties = null; } // else, file wasn't modified! } } else { // file has started to exist: if (propertiesFileExists) { loadProperties = true; fLastModified = ss.getLastModified(propertiesFile); } // else, nothing's changed } if (loadProperties) { // must never have attempted to read xalan.properties // before (or it's outdeated) fXalanProperties = new Properties(); fis = ss.getFileInputStream(propertiesFile); fXalanProperties.load(fis); } } catch (Exception x) { fXalanProperties = null; fLastModified = -1; // assert(x instanceof FileNotFoundException // || x instanceof SecurityException) // In both cases, ignore and continue w/ next location } finally { // try to close the input stream if one was opened. if (fis != null) { try { fis.close(); } // Ignore the exception. catch (IOException exc) { } } } } if (fXalanProperties != null) { factoryClassName = fXalanProperties.getProperty(factoryId); } } else { FileInputStream fis = null; try { fis = ss.getFileInputStream(new File(propertiesFilename)); Properties props = new Properties(); props.load(fis); factoryClassName = props.getProperty(factoryId); } catch (Exception x) { // assert(x instanceof FileNotFoundException // || x instanceof SecurityException) // In both cases, ignore and continue w/ next location } finally { // try to close the input stream if one was opened. if (fis != null) { try { fis.close(); } // Ignore the exception. catch (IOException exc) { } } } } if (factoryClassName != null) { if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName); return factoryClassName; } // Try Jar Service Provider Mechanism return findJarServiceProviderName(factoryId); } // lookUpFactoryClass(String,String):String
/* 79: */ /* 80: */ static String lookUpFactoryClassName( String factoryId, String propertiesFilename, String fallbackClassName) /* 81: */ { /* 82:261 */ SecuritySupport ss = SecuritySupport.getInstance(); /* 83: */ try /* 84: */ { /* 85:265 */ String systemProp = ss.getSystemProperty(factoryId); /* 86:266 */ if (systemProp != null) /* 87: */ { /* 88:267 */ debugPrintln("found system property, value=" + systemProp); /* 89:268 */ return systemProp; /* 90: */ } /* 91: */ } /* 92: */ catch (SecurityException se) { } /* 93:276 */ String factoryClassName = null; /* 94:279 */ if (propertiesFilename == null) /* 95: */ { /* 96:280 */ File propertiesFile = null; /* 97:281 */ boolean propertiesFileExists = false; /* 98: */ try /* 99: */ { /* 100:283 */ String javah = ss.getSystemProperty("java.home"); /* 101:284 */ propertiesFilename = javah + File.separator + "lib" + File.separator + "xalan.properties"; /* 102: */ /* 103:286 */ propertiesFile = new File(propertiesFilename); /* 104:287 */ propertiesFileExists = ss.getFileExists(propertiesFile); /* 105: */ } /* 106: */ catch (SecurityException javah) /* 107: */ { /* 108:290 */ fLastModified = -1L; /* 109:291 */ fXalanProperties = null; /* 110: */ } /* 111:294 */ synchronized (ObjectFactory.class) /* 112: */ { /* 113:295 */ boolean loadProperties = false; /* 114:296 */ FileInputStream fis = null; /* 115: */ try /* 116: */ { /* 117:299 */ if (fLastModified >= 0L) /* 118: */ { /* 119:300 */ if ((propertiesFileExists) && (fLastModified < (ObjectFactory.fLastModified = ss.getLastModified(propertiesFile)))) /* 120: */ { /* 121:302 */ loadProperties = true; /* 122: */ } /* 123:305 */ else if (!propertiesFileExists) /* 124: */ { /* 125:306 */ fLastModified = -1L; /* 126:307 */ fXalanProperties = null; /* 127: */ } /* 128: */ } /* 129:312 */ else if (propertiesFileExists) /* 130: */ { /* 131:313 */ loadProperties = true; /* 132:314 */ fLastModified = ss.getLastModified(propertiesFile); /* 133: */ } /* 134:317 */ if (loadProperties) /* 135: */ { /* 136:320 */ fXalanProperties = new Properties(); /* 137:321 */ fis = ss.getFileInputStream(propertiesFile); /* 138:322 */ fXalanProperties.load(fis); /* 139: */ } /* 140: */ } /* 141: */ catch (Exception x) /* 142: */ { /* 143:325 */ fXalanProperties = null; /* 144:326 */ fLastModified = -1L; /* 145: */ } /* 146: */ finally /* 147: */ { /* 148:333 */ if (fis != null) { /* 149: */ try /* 150: */ { /* 151:335 */ fis.close(); /* 152: */ } /* 153: */ catch (IOException exc) { } /* 154: */ } /* 155: */ } /* 156: */ } /* 157:342 */ if (fXalanProperties != null) { /* 158:343 */ factoryClassName = fXalanProperties.getProperty(factoryId); /* 159: */ } /* 160: */ } /* 161: */ else /* 162: */ { /* 163:346 */ FileInputStream fis = null; /* 164: */ try /* 165: */ { /* 166:348 */ fis = ss.getFileInputStream(new File(propertiesFilename)); /* 167:349 */ Properties props = new Properties(); /* 168:350 */ props.load(fis); /* 169:351 */ factoryClassName = props.getProperty(factoryId); /* 170: */ } /* 171: */ catch (Exception x) { } finally /* 172: */ { /* 173:359 */ if (fis != null) { /* 174: */ try /* 175: */ { /* 176:361 */ fis.close(); /* 177: */ } /* 178: */ catch (IOException exc) { } /* 179: */ } /* 180: */ } /* 181: */ } /* 182:368 */ if (factoryClassName != null) /* 183: */ { /* 184:369 */ debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName); /* 185: */ /* 186:371 */ return factoryClassName; /* 187: */ } /* 188:375 */ return findJarServiceProviderName(factoryId); /* 189: */ }