in jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java [184:252]
static Object find(String factoryId, String fallbackClassName)
throws ConfigurationError {
ClassLoader classLoader = findClassLoader();
try {
// If we are deployed into an OSGi environment, leverage it
Class factoryClass = FactoryFinder.class.getClassLoader().loadClass(factoryId);
Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryClass, factoryId);
if (spiClass != null) {
return spiClass.newInstance();
}
} catch (Throwable e) {
}
// Use the system property first
try {
String systemProp = SecuritySupport.getSystemProperty(factoryId);
if (systemProp != null) {
if (debug) debugPrintln("found " + systemProp + " in the system property " + factoryId);
return newInstance(systemProp, classLoader);
}
} catch (SecurityException se) {
; // NOP, explicitly ignore SecurityException
}
// try to read from $java.home/lib/jaxp.properties
try {
String javah = SecuritySupport.getSystemProperty("java.home");
String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties";
String factoryClassName = null;
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(factoryId);
if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {
return newInstance(factoryClassName, classLoader);
}
} catch (Exception ex) {
if (debug) {
ex.printStackTrace();
}
}
// Try Jar Service Provider Mechanism
Object provider = findJarServiceProvider(factoryId);
if (provider != null) {
return provider;
}
if (fallbackClassName == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
if (debug) debugPrintln("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader);
}