// get the schema
if (xmlSchemas == null || xmlSchemas.isEmpty()){
// if there is no schema no need to validate
// return a warning saying there is no schema
TeiidException noSchema = new TeiidComponentException("ERR.015.006.0042", QueryPlugin.Util.getString("ERR.015.006.0042")); //$NON-NLS-1$ //$NON-NLS-2$
addWarning(noSchema);
return;
}
// perform the validation
HashMap nameSpaceMap = null;
try{
// also find the target name space URIs for the document(s).
nameSpaceMap = getTargetNameSpaces(xmlSchemas);
} catch(TeiidException me){
addWarning(me);
nameSpaceMap = new HashMap();
}
// Create a SAXParser
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
XMLReader reader = null;
// set the features on the parser
try{
SAXParser parser = spf.newSAXParser();
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$ //$NON-NLS-2$
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", nameSpaceMap.keySet().toArray()); //$NON-NLS-1$
reader = parser.getXMLReader();
} catch (SAXException err) {
throw new TeiidComponentException(err);
} catch (ParserConfigurationException err) {
throw new TeiidComponentException(err);
}
// place the schema into the customized entity resolver so that we can
// resolve the schema elements
EntityResolver xmlEntityResolver = new MultiEntityResolver(nameSpaceMap);
reader.setEntityResolver(xmlEntityResolver);
// Create the specialized error handler so that we can get any warnings,
// errors, or fatal errors back from validation
MMErrorHandler errorHandler = new MMErrorHandler();
reader.setErrorHandler(errorHandler);
// create the input stream for the xml document to be parsed
InputSource source = new InputSource(xmlStream);
try{
reader.parse(source);
} catch(SAXException se){
throw new TeiidComponentException(se);
} catch(IOException io){
throw new TeiidComponentException(io);
}
// determine if we have any warnings, errors, or fatal errors and report as necessary
if (errorHandler.hasExceptions()) {
List exceptionList = errorHandler.getExceptionList();