/** * <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; }
/** * <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; }
/** * 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; }