/* First, let's check and map schema type to the shorter internal
* id:
*/
String internalId = (String) sSchemaIds.get(schemaType);
if (internalId == null) {
throw new FactoryConfigurationError("Unrecognized schema type (id '"+schemaType+"')");
}
String propertyId = SYSTEM_PROPERTY_FOR_IMPL + internalId;
SecurityException secEx = null;
/* First, let's see if there's a system property (overrides other
* settings)
*/
try {
String clsName = System.getProperty(propertyId);
if (clsName != null && clsName.length() > 0) {
return createNewInstance(classLoader, clsName);
}
} catch (SecurityException se) {
// May happen on sandbox envs, like applets?
secEx = se;
}
/* try to read from $java.home/lib/xml.properties (simulating
* the way XMLInputFactory does this... not sure if this should
* be done, as this is not [yet?] really jaxp specified)
*/
try {
String home = System.getProperty("java.home");
File f = new File(home);
// Let's not hard-code separators...
f = new File(f, "lib");
f = new File(f, JAXP_PROP_FILENAME);
if (f.exists()) {
try {
Properties props = new Properties();
props.load(new FileInputStream(f));
String clsName = props.getProperty(propertyId);
if (clsName != null && clsName.length() > 0) {
return createNewInstance(classLoader, clsName);
}
} catch (IOException ioe) {
// can also happen quite easily...
}
}
} catch (SecurityException se) {
// Fine, as above
secEx = se;
}
/* Ok, no match; how about a service def from the impl jar?
*/
// try to find services in CLASSPATH
String path = SERVICE_DEFINITION_PATH + internalId;
try {
Enumeration en;
if (classLoader == null) {
en = ClassLoader.getSystemResources(path);
} else {
en = classLoader.getResources(path);
}
if (en != null) {
while (en.hasMoreElements()) {
URL url = (URL) en.nextElement();
InputStream is = url.openStream();
BufferedReader rd =
new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
String clsName = null;
String line;
try {
while ((line = rd.readLine()) != null) {
line = line.trim();
if (line.length() > 0 && line.charAt(0) != '#') {
clsName = line;
break;
}
}
} finally {
rd.close();
}
if (clsName != null && clsName.length() > 0) {
return createNewInstance(classLoader, clsName);
}
}
}
} catch (SecurityException se) {
secEx = se;
} catch (IOException ex) {
/* Let's assume these are mostly ok, too (missing jar ie.)
*/
}
String msg = "No XMLValidationSchemaFactory implementation class specified or accessible (via system property '"
+propertyId+"', or service definition under '"+path+"')";
if (secEx != null) {
throw new FactoryConfigurationError(msg + " (possibly caused by: "+secEx+")", secEx);
}
throw new FactoryConfigurationError(msg);
}