/** * 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
/** * <p>Lookup a {@link XPathFactory} for the given object model.</p> * * @param uri identifies the object model. * * @return {@link XPathFactory} for the given object model. */ private XPathFactory _newFactory(String uri) { XPathFactory xpathFactory; String propertyName = SERVICE_CLASS.getName() + ":" + uri; // system property look up try { debugPrintln("Looking up system property '"+propertyName+"'" ); String r = ss.getSystemProperty(propertyName); if(r!=null) { debugPrintln("The value is '"+r+"'"); xpathFactory = createInstance(r, true); if(xpathFactory != null) return xpathFactory; } else debugPrintln("The property is undefined."); } catch( Throwable t ) { if( debug ) { debugPrintln("failed to look up system property '"+propertyName+"'" ); t.printStackTrace(); } } String javah = ss.getSystemProperty( "java.home" ); String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties"; String factoryClassName = null ; // try to read from $java.home/lib/jaxp.properties try { if(firstTime){ synchronized(cacheProps){ if(firstTime){ File f=new File( configFile ); firstTime = false; if(ss.doesFileExist(f)){ debugPrintln("Read properties file " + f); cacheProps.load(ss.getFileInputStream(f)); } } } } factoryClassName = cacheProps.getProperty(propertyName); debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); if (factoryClassName != null) { xpathFactory = createInstance(factoryClassName, true); if(xpathFactory != null){ return xpathFactory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } // try META-INF/services files Iterator sitr = createServiceFileIterator(); while(sitr.hasNext()) { URL resource = (URL)sitr.next(); debugPrintln("looking into " + resource); try { xpathFactory = loadFromService(uri, resource.toExternalForm(), ss.getURLInputStream(resource)); if (xpathFactory != null) { return xpathFactory; } } catch(IOException e) { if( debug ) { debugPrintln("failed to read "+resource); e.printStackTrace(); } } } // platform default if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) { debugPrintln("attempting to use the platform default W3C DOM XPath lib"); return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true); } debugPrintln("all things were tried, but none was found. bailing out."); return null; }
/** * <p>Lookup a {@link XPathFactory} for the given object model.</p> * * @param uri identifies the object model. * * @return {@link XPathFactory} for the given object model. */ private XPathFactory _newFactory(String uri) { XPathFactory xpf; String propertyName = SERVICE_CLASS.getName() + ":" + uri; // system property look up try { if (debug) debugPrintln("Looking up system property '"+propertyName+"'" ); String r = SecuritySupport.getSystemProperty(propertyName); if (r != null && r.length() > 0) { if (debug) debugPrintln("The value is '"+r+"'"); xpf = createInstance(r); if(xpf!=null) return xpf; } else if (debug) { debugPrintln("The property is undefined."); } } // The VM ran out of memory or there was some other serious problem. Re-throw. catch (VirtualMachineError vme) { throw vme; } // ThreadDeath should always be re-thrown catch (ThreadDeath td) { throw td; } catch (Throwable t) { if( debug ) { debugPrintln("failed to look up system property '"+propertyName+"'" ); t.printStackTrace(); } } String javah = SecuritySupport.getSystemProperty( "java.home" ); String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties"; String factoryClassName = null ; // try to read from $java.home/lib/jaxp.properties try { if(firstTime){ synchronized(cacheProps){ if(firstTime){ File f=new File( configFile ); firstTime = false; if(SecuritySupport.doesFileExist(f)){ if (debug) debugPrintln("Read properties file " + f); cacheProps.load(SecuritySupport.getFileInputStream(f)); } } } } factoryClassName = cacheProps.getProperty(propertyName); if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); if (factoryClassName != null) { xpf = createInstance(factoryClassName); if(xpf != null){ return xpf; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } // try META-INF/services files Iterator sitr = createServiceFileIterator(); while(sitr.hasNext()) { URL resource = (URL)sitr.next(); if (debug) debugPrintln("looking into " + resource); try { xpf = loadFromServicesFile(uri, resource.toExternalForm(), SecuritySupport.getURLInputStream(resource)); if(xpf!=null) return xpf; } catch(IOException e) { if( debug ) { debugPrintln("failed to read "+resource); e.printStackTrace(); } } } // platform default if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) { if (debug) debugPrintln("attempting to use the platform default W3C DOM XPath lib"); return createInstance("org.apache.xpath.jaxp.XPathFactoryImpl"); } if (debug) debugPrintln("all things were tried, but none was found. bailing out."); return null; }
/* 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: */ }
/** * Lookup a {@link XPathFactory} for the given object model. * * @param uri identifies the object model. * @return {@link XPathFactory} for the given object model. */ private XPathFactory _newFactory(String uri) throws XPathFactoryConfigurationException { XPathFactory xpathFactory = null; String propertyName = SERVICE_CLASS.getName() + ":" + uri; // system property look up try { debugPrintln("Looking up system property '" + propertyName + "'"); String r = ss.getSystemProperty(propertyName); if (r != null) { debugPrintln("The value is '" + r + "'"); xpathFactory = createInstance(r, true); if (xpathFactory != null) { return xpathFactory; } } else debugPrintln("The property is undefined."); } catch (Throwable t) { if (debug) { debugPrintln("failed to look up system property '" + propertyName + "'"); t.printStackTrace(); } } String javah = ss.getSystemProperty("java.home"); String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties"; // try to read from $java.home/lib/jaxp.properties try { if (firstTime) { synchronized (cacheProps) { if (firstTime) { File f = new File(configFile); firstTime = false; if (ss.doesFileExist(f)) { debugPrintln("Read properties file " + f); cacheProps.load(ss.getFileInputStream(f)); } } } } final String factoryClassName = cacheProps.getProperty(propertyName); debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); if (factoryClassName != null) { xpathFactory = createInstance(factoryClassName, true); if (xpathFactory != null) { return xpathFactory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } // Try with ServiceLoader assert xpathFactory == null; xpathFactory = findServiceProvider(uri); // The following assertion should always be true. // Uncomment it, recompile, and run with -ea in case of doubts: // assert xpathFactory == null || xpathFactory.isObjectModelSupported(uri); if (xpathFactory != null) { return xpathFactory; } // platform default if (uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) { debugPrintln("attempting to use the platform default W3C DOM XPath lib"); return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true); } debugPrintln("all things were tried, but none was found. bailing out."); return null; }