use of com.sun.tools.xjc.reader.xmlschema.parser.LSInputSAXWrapper in project cxf by apache.
the class JAXBDataBinding method validateSchema.
public void validateSchema(Element ele, String uri, final OASISCatalogManager catalog, final SchemaCollection schemaCollection) throws ToolException {
SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFact.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String s = JAXBDataBinding.mapSchemaLocation(systemId, baseURI, catalog);
LOG.fine("validating: " + namespaceURI + " " + systemId + " " + baseURI + " " + s);
if (s == null) {
XmlSchema sc = schemaCollection.getSchemaByTargetNamespace(namespaceURI);
if (sc != null) {
StringWriter writer = new StringWriter();
sc.write(writer);
InputSource src = new InputSource(new StringReader(writer.toString()));
src.setSystemId(sc.getSourceURI());
return new LSInputSAXWrapper(src);
}
throw new ToolException("Schema not found for namespace: " + namespaceURI);
}
return new LSInputSAXWrapper(new InputSource(s));
}
});
DOMSource domSrc = new DOMSource(ele, uri);
try {
schemaFact.newSchema(domSrc);
} catch (SAXException e) {
if (e.getLocalizedMessage().indexOf("src-resolve.4.2") > -1) {
// Ignore schema resolve error and do nothing
} else {
// e.printStackTrace();
throw new ToolException("Schema Error : " + e.getLocalizedMessage(), e);
}
}
}
Aggregations