in stax-api-1.2/src/main/java/javax/xml/stream/FactoryLocator.java [56:122]
static Object locate(String factoryId, String[] altClassName,
ClassLoader classLoader) throws FactoryConfigurationError {
try {
// If we are deployed into an OSGi environment, leverage it
ClassLoader cl = FactoryLocator.class.getClassLoader();
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
Class factoryClass = cl.loadClass(factoryId);
Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryClass, factoryId);
if (spiClass != null) {
return spiClass.newInstance();
}
} catch (Throwable e) {
}
try {
String prop = System.getProperty(factoryId);
if (prop != null) {
return loadFactory(prop, classLoader);
}
} catch (Exception e) {
}
try {
String configFile = System.getProperty("java.home")
+ File.separator + "lib" + File.separator
+ "stax.properties";
File f = new File(configFile);
if (f.exists()) {
Properties props = new Properties();
props.load(new FileInputStream(f));
String factoryClassName = props.getProperty(factoryId);
return loadFactory(factoryClassName, classLoader);
}
} catch (Exception e) {
}
String serviceId = "META-INF/services/" + factoryId;
try {
InputStream is = null;
if (classLoader == null) {
is = ClassLoader.getSystemResourceAsStream(serviceId);
} else {
is = classLoader.getResourceAsStream(serviceId);
}
if (is != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(
is, "UTF-8"));
String factoryClassName = br.readLine();
br.close();
if (factoryClassName != null && !"".equals(factoryClassName)) {
return loadFactory(factoryClassName, classLoader);
}
}
} catch (Exception ex) {
}
if (altClassName == null) {
throw new FactoryConfigurationError("Unable to locate factory for "
+ factoryId + ".", null);
}
return loadFactory(altClassName, classLoader);
}