// Uses Xerxes internal classes
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
registry.addSource(new DOMXSImplementationSourceImpl());
Object xsImplementation = registry.getDOMImplementation("XS-Loader");
if (xsImplementation == null) {
throw new ConfigurationException("Failed to retrieve XS-Loader implementation from registry obtained via DOMImplementationRegistry.newInstance, please check that registry.getDOMImplementation(\"XS-Loader\") returns an instance");
}
if (!JavaClassHelper.isImplementsInterface(xsImplementation.getClass(), XSImplementation.class)) {
String message = "The XS-Loader instance returned by the DOM registry class '" + xsImplementation.getClass().getName() + "' does not implement the interface '" + XSImplementation.class.getName() + "'; If you have a another Xerces distribution in your classpath please ensure the classpath order loads the JRE Xerces distribution or set the DOMImplementationRegistry.PROPERTY system property";
throw new ConfigurationException(message);
}
XSImplementation impl =(XSImplementation) xsImplementation;
XSLoader schemaLoader = impl.createXSLoader(null);
schemaLoader.getConfig().setParameter("error-handler", new XSDSchemaMapperErrorHandler(schemaResource));
XSModel xsModel;
if (input != null) {
xsModel = schemaLoader.load(input);
}
else {
xsModel = schemaLoader.loadURI(baseURI);
// If having trouble loading from the uri, try to attempt from file system.
if (xsModel == null) {
String schema;
try {
schema = FileUtil.readTextFile(new File(url.toURI()));
}
catch (IOException e) {
throw new ConfigurationException("Failed to read file '" + url.toURI() + "':" + e.getMessage(), e);
}
log.debug("Found and obtained schema: " + schema);
xsModel = schemaLoader.load(new LSInputImpl(schema));
log.debug("Model for schema: " + xsModel);
}
}
if (xsModel == null)
{
throw new ConfigurationException("Failed to read schema via URL '" + schemaResource + '\'');
}
return xsModel;
}